| 1 |
|
| #include "imager.h" |
| 2 |
|
| #include "imageri.h" |
| 3 |
|
| |
| 4 |
|
| /* |
| 5 |
|
| =item i_copyto(C<dest>, C<src>, C<x1>, C<y1>, C<x2>, C<y2>, C<tx>, C<ty>) |
| 6 |
|
| |
| 7 |
|
| =category Image |
| 8 |
|
| |
| 9 |
|
| Copies image data from the area (C<x1>,C<y1>)-[C<x2>,C<y2>] in the |
| 10 |
|
| source image to a rectangle the same size with it's top-left corner at |
| 11 |
|
| (C<tx>,C<ty>) in the destination image. |
| 12 |
|
| |
| 13 |
|
| If C<x1> > C<x2> or C<y1> > C<y2> then the corresponding co-ordinates |
| 14 |
|
| are swapped. |
| 15 |
|
| |
| 16 |
|
| =cut |
| 17 |
|
| */ |
| 18 |
|
| |
| 19 |
|
| void |
| 20 |
84 |
| i_copyto(i_img *im, i_img *src, i_img_dim x1, i_img_dim y1, i_img_dim x2, i_img_dim y2, i_img_dim tx, i_img_dim ty) { |
| 21 |
|
| i_img_dim y, t, tty; |
| 22 |
|
| |
| 23 |
84 |
▶ | if (x2<x1) { t=x1; x1=x2; x2=t; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (x2<x1) { t=x1; x1=x2; x2=t; } |
0 |
84 |
84 |
|
| 24 |
84 |
▶ | if (y2<y1) { t=y1; y1=y2; y2=t; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (y2<y1) { t=y1; y1=y2; y2=t; } |
0 |
84 |
84 |
|
| 25 |
84 |
▶ | if (tx < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tx < 0) { |
0 |
84 |
84 |
|
| 26 |
|
| /* adjust everything equally */ |
| 27 |
0 |
| x1 += -tx; |
| 28 |
0 |
| x2 += -tx; |
| 29 |
0 |
| tx = 0; |
| 30 |
|
| } |
| 31 |
84 |
▶ | if (ty < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ty < 0) { |
0 |
84 |
84 |
|
| 32 |
0 |
| y1 += -ty; |
| 33 |
0 |
| y2 += -ty; |
| 34 |
0 |
| ty = 0; |
| 35 |
|
| } |
| 36 |
84 |
▶ | if (x1 >= src->xsize || y1 >= src->ysize) |
Branch: 2 branches
| Branch | True | False | Total |
| if (x1 >= src->xsize || y1 >= src->ysize) |
84 |
0 |
84 |
| if (x1 >= src->xsize || y1 >= src->ysize) |
0 |
84 |
84 |
|
| 37 |
0 |
| return; /* nothing to do */ |
| 38 |
84 |
▶ | if (x2 > src->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (x2 > src->xsize) |
0 |
84 |
84 |
|
| 39 |
0 |
| x2 = src->xsize; |
| 40 |
84 |
▶ | if (y2 > src->ysize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (y2 > src->ysize) |
0 |
84 |
84 |
|
| 41 |
0 |
| y2 = src->ysize; |
| 42 |
84 |
▶ | if (x1 == x2 || y1 == y2) |
Branch: 2 branches
| Branch | True | False | Total |
| if (x1 == x2 || y1 == y2) |
84 |
0 |
84 |
| if (x1 == x2 || y1 == y2) |
0 |
84 |
84 |
|
| 43 |
0 |
| return; /* nothing to do */ |
| 44 |
|
| |
| 45 |
84 |
| mm_log((1,"i_copyto(im* %p, src %p, p1(" i_DFp "), p2(" i_DFp "), t(" |
| 46 |
|
| i_DFp "))\n", |
| 47 |
|
| im, src, i_DFcp(x1, y1), i_DFcp(x2, y2), i_DFcp(tx, ty))); |
| 48 |
|
| |
| 49 |
84 |
▶ | #code im->bits == i_8_bits |
Branch: 1 branch
| Branch | True | False | Total |
| #code im->bits == i_8_bits |
78 |
6 |
84 |
|
| 50 |
84 |
| IM_COLOR *row = mymalloc(sizeof(IM_COLOR) * (x2-x1)); |
| 51 |
84 |
| tty = ty; |
| 52 |
6927 |
▶ | for(y=y1; y<y2; y++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for(y=y1; y<y2; y++) { |
6128 |
78 |
6206 |
| for(y=y1; y<y2; y++) { |
715 |
6 |
721 |
|
| 53 |
6843 |
| IM_GLIN(src, x1, x2, y, row); |
| 54 |
6843 |
| if (src->channels != im->channels) |
| 55 |
900 |
| IM_ADAPT_COLORS(im->channels, src->channels, row, x2-x1); |
| 56 |
6843 |
| IM_PLIN(im, tx, tx+x2-x1, tty, row); |
| 57 |
6843 |
| tty++; |
| 58 |
|
| } |
| 59 |
84 |
| myfree(row); |
| 60 |
|
| #/code |
| 61 |
|
| } |
| 62 |
|
| |
| 63 |
|
| #code |
| 64 |
|
| void |
| 65 |
|
| #ifdef IM_EIGHT_BIT |
| 66 |
2986 |
| i_adapt_colors |
| 67 |
|
| #else |
| 68 |
882 |
| i_adapt_fcolors |
| 69 |
|
| #endif |
| 70 |
|
| (int out_channels, int in_channels, IM_COLOR *colors, |
| 71 |
|
| size_t count) { |
| 72 |
3868 |
▶ | if (out_channels == in_channels) |
Branch: 2 branches
| Branch | True | False | Total |
| if (out_channels == in_channels) |
782 |
100 |
882 |
| if (out_channels == in_channels) |
1356 |
1630 |
2986 |
|
| 73 |
2138 |
| return; |
| 74 |
1730 |
▶ | if (count == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (count == 0) |
0 |
100 |
100 |
| if (count == 0) |
0 |
1630 |
1630 |
|
| 75 |
0 |
| return; |
| 76 |
|
| |
| 77 |
1730 |
| switch (out_channels) { |
| 78 |
370 |
| case 1: |
| 79 |
|
| { |
| 80 |
370 |
| switch (in_channels) { |
| 81 |
50 |
| case 2: |
| 82 |
|
| /* apply alpha against a black background */ |
| 83 |
2550 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
2500 |
50 |
2550 |
|
| 84 |
2500 |
| colors->channel[0] = colors->channel[0] * colors->channel[1] / IM_SAMPLE_MAX; |
| 85 |
2500 |
| ++colors; |
| 86 |
2500 |
| --count; |
| 87 |
|
| } |
| 88 |
50 |
| return; |
| 89 |
|
| |
| 90 |
270 |
| case 3: |
| 91 |
|
| /* convert to grey */ |
| 92 |
27970 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
27700 |
270 |
27970 |
|
| 93 |
27700 |
| colors->channel[0] = IM_ROUND(color_to_grey(colors)); |
| 94 |
27700 |
| ++colors; |
| 95 |
27700 |
| --count; |
| 96 |
|
| } |
| 97 |
270 |
| return; |
| 98 |
|
| |
| 99 |
50 |
| case 4: |
| 100 |
2550 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
2500 |
50 |
2550 |
|
| 101 |
2500 |
| colors->channel[0] = IM_ROUND(color_to_grey(colors) * colors->channel[3] / IM_SAMPLE_MAX); |
| 102 |
2500 |
| ++colors; |
| 103 |
2500 |
| --count; |
| 104 |
|
| } |
| 105 |
50 |
| return; |
| 106 |
|
| |
| 107 |
0 |
| default: |
| 108 |
0 |
| i_fatal(3, "i_adapt_colors: in_channels of %d invalid\n", in_channels); |
| 109 |
0 |
| return; /* avoid warnings */ |
| 110 |
|
| } |
| 111 |
|
| } |
| 112 |
|
| |
| 113 |
550 |
| case 2: |
| 114 |
|
| { |
| 115 |
550 |
| switch (in_channels) { |
| 116 |
140 |
| case 1: |
| 117 |
5940 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
400 |
20 |
420 |
| while (count) { |
5400 |
120 |
5520 |
|
| 118 |
5800 |
| colors->channel[1] = IM_SAMPLE_MAX; |
| 119 |
5800 |
| ++colors; |
| 120 |
5800 |
| --count; |
| 121 |
|
| } |
| 122 |
140 |
| return; |
| 123 |
|
| |
| 124 |
140 |
| case 3: |
| 125 |
5940 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
400 |
20 |
420 |
| while (count) { |
5400 |
120 |
5520 |
|
| 126 |
5800 |
| colors->channel[0] = IM_ROUND(color_to_grey(colors)); |
| 127 |
5800 |
| colors->channel[1] = IM_SAMPLE_MAX; |
| 128 |
5800 |
| ++colors; |
| 129 |
5800 |
| --count; |
| 130 |
|
| } |
| 131 |
140 |
| return; |
| 132 |
|
| |
| 133 |
270 |
| case 4: |
| 134 |
7890 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
20 |
20 |
40 |
| while (count) { |
7600 |
250 |
7850 |
|
| 135 |
7620 |
| colors->channel[0] = IM_ROUND(color_to_grey(colors)); |
| 136 |
7620 |
| colors->channel[1] = colors->channel[3]; |
| 137 |
7620 |
| ++colors; |
| 138 |
7620 |
| --count; |
| 139 |
|
| } |
| 140 |
270 |
| return; |
| 141 |
|
| |
| 142 |
0 |
| default: |
| 143 |
0 |
| i_fatal(3, "i_adapt_colors: in_channels of %d invalid\n", in_channels); |
| 144 |
0 |
| return; /* avoid warnings */ |
| 145 |
|
| } |
| 146 |
|
| } |
| 147 |
|
| |
| 148 |
200 |
| case 3: |
| 149 |
|
| { |
| 150 |
200 |
| switch (in_channels) { |
| 151 |
100 |
| case 1: |
| 152 |
5100 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
5000 |
100 |
5100 |
|
| 153 |
5000 |
| colors->channel[1] = colors->channel[2] = colors->channel[0]; |
| 154 |
5000 |
| ++colors; |
| 155 |
5000 |
| --count; |
| 156 |
|
| } |
| 157 |
100 |
| return; |
| 158 |
|
| |
| 159 |
50 |
| case 2: |
| 160 |
2550 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
2500 |
50 |
2550 |
|
| 161 |
2500 |
| int alpha = colors->channel[1]; |
| 162 |
2500 |
| colors->channel[0] = colors->channel[1] = colors->channel[2] = |
| 163 |
2500 |
| IM_ROUND(colors->channel[0] * alpha / IM_SAMPLE_MAX); |
| 164 |
2500 |
| ++colors; |
| 165 |
2500 |
| --count; |
| 166 |
|
| } |
| 167 |
50 |
| return; |
| 168 |
|
| |
| 169 |
50 |
| case 4: |
| 170 |
2550 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
2500 |
50 |
2550 |
|
| 171 |
2500 |
| int alpha = colors->channel[3]; |
| 172 |
2500 |
| colors->channel[0] = |
| 173 |
2500 |
| IM_ROUND(colors->channel[0] * alpha / IM_SAMPLE_MAX); |
| 174 |
2500 |
| colors->channel[1] = |
| 175 |
2500 |
| IM_ROUND(colors->channel[1] * alpha / IM_SAMPLE_MAX); |
| 176 |
2500 |
| colors->channel[2] = |
| 177 |
2500 |
| IM_ROUND(colors->channel[2] * alpha / IM_SAMPLE_MAX); |
| 178 |
2500 |
| ++colors; |
| 179 |
2500 |
| --count; |
| 180 |
|
| } |
| 181 |
50 |
| return; |
| 182 |
|
| |
| 183 |
0 |
| default: |
| 184 |
0 |
| i_fatal(3, "i_adapt_colors: in_channels of %d invalid\n", in_channels); |
| 185 |
0 |
| return; /* avoid warnings */ |
| 186 |
|
| } |
| 187 |
|
| } |
| 188 |
|
| |
| 189 |
610 |
| case 4: |
| 190 |
|
| { |
| 191 |
610 |
| switch (in_channels) { |
| 192 |
140 |
| case 1: |
| 193 |
5940 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
400 |
20 |
420 |
| while (count) { |
5400 |
120 |
5520 |
|
| 194 |
5800 |
| colors->channel[1] = colors->channel[2] = colors->channel[0]; |
| 195 |
5800 |
| colors->channel[3] = IM_SAMPLE_MAX; |
| 196 |
5800 |
| ++colors; |
| 197 |
5800 |
| --count; |
| 198 |
|
| } |
| 199 |
140 |
| return; |
| 200 |
|
| |
| 201 |
230 |
| case 2: |
| 202 |
14130 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
13900 |
230 |
14130 |
|
| 203 |
13900 |
| colors->channel[3] = colors->channel[1]; |
| 204 |
13900 |
| colors->channel[1] = colors->channel[2] = colors->channel[0]; |
| 205 |
13900 |
| ++colors; |
| 206 |
13900 |
| --count; |
| 207 |
|
| } |
| 208 |
230 |
| return; |
| 209 |
|
| |
| 210 |
240 |
| case 3: |
| 211 |
16040 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
400 |
20 |
420 |
| while (count) { |
15400 |
220 |
15620 |
|
| 212 |
15800 |
| colors->channel[3] = IM_SAMPLE_MAX; |
| 213 |
15800 |
| ++colors; |
| 214 |
15800 |
| --count; |
| 215 |
|
| } |
| 216 |
240 |
| return; |
| 217 |
|
| |
| 218 |
0 |
| default: |
| 219 |
0 |
| i_fatal(3, "i_adapt_colors: in_channels of %d invalid\n", in_channels); |
| 220 |
0 |
| return; /* avoid warnings */ |
| 221 |
|
| } |
| 222 |
|
| } |
| 223 |
|
| |
| 224 |
0 |
| default: |
| 225 |
0 |
| i_fatal(3, "i_adapt_colors: out_channels of %d invalid\n", out_channels); |
| 226 |
0 |
| return; /* avoid warnings */ |
| 227 |
|
| } |
| 228 |
|
| } |
| 229 |
|
| |
| 230 |
|
| void |
| 231 |
|
| #ifdef IM_EIGHT_BIT |
| 232 |
0 |
| i_adapt_colors_bg |
| 233 |
|
| #else |
| 234 |
0 |
| i_adapt_fcolors_bg |
| 235 |
|
| #endif |
| 236 |
|
| (int out_channels, int in_channels, IM_COLOR *colors, |
| 237 |
|
| size_t count, IM_COLOR const *bg) { |
| 238 |
0 |
▶ | if (out_channels == in_channels) |
Branch: 2 branches
| Branch | True | False | Total |
| if (out_channels == in_channels) |
0 |
0 |
0 |
| if (out_channels == in_channels) |
0 |
0 |
0 |
|
| 239 |
0 |
| return; |
| 240 |
0 |
▶ | if (count == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (count == 0) |
0 |
0 |
0 |
| if (count == 0) |
0 |
0 |
0 |
|
| 241 |
0 |
| return; |
| 242 |
|
| |
| 243 |
0 |
| switch (out_channels) { |
| 244 |
0 |
| case 2: |
| 245 |
|
| case 4: |
| 246 |
0 |
| IM_ADAPT_COLORS(out_channels, in_channels, colors, count); |
| 247 |
0 |
| return; |
| 248 |
|
| |
| 249 |
0 |
| case 1: |
| 250 |
0 |
| switch (in_channels) { |
| 251 |
0 |
| case 3: |
| 252 |
0 |
| IM_ADAPT_COLORS(out_channels, in_channels, colors, count); |
| 253 |
0 |
| return; |
| 254 |
|
| |
| 255 |
0 |
| case 2: |
| 256 |
|
| { |
| 257 |
|
| /* apply alpha against our given background */ |
| 258 |
0 |
| IM_WORK_T grey_bg = IM_ROUND(color_to_grey(bg)); |
| 259 |
0 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
0 |
0 |
0 |
|
| 260 |
0 |
| colors->channel[0] = |
| 261 |
0 |
| (colors->channel[0] * colors->channel[1] + |
| 262 |
0 |
| grey_bg * (IM_SAMPLE_MAX - colors->channel[1])) / IM_SAMPLE_MAX; |
| 263 |
0 |
| ++colors; |
| 264 |
0 |
| --count; |
| 265 |
|
| } |
| 266 |
|
| } |
| 267 |
0 |
| break; |
| 268 |
|
| |
| 269 |
0 |
| case 4: |
| 270 |
|
| { |
| 271 |
0 |
| IM_WORK_T grey_bg = IM_ROUND(color_to_grey(bg)); |
| 272 |
0 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
0 |
0 |
0 |
|
| 273 |
0 |
| IM_WORK_T src_grey = IM_ROUND(color_to_grey(colors)); |
| 274 |
0 |
| colors->channel[0] = |
| 275 |
0 |
| (src_grey * colors->channel[3] |
| 276 |
0 |
| + grey_bg * (IM_SAMPLE_MAX - colors->channel[3])) / IM_SAMPLE_MAX; |
| 277 |
0 |
| ++colors; |
| 278 |
0 |
| --count; |
| 279 |
|
| } |
| 280 |
|
| } |
| 281 |
0 |
| break; |
| 282 |
|
| } |
| 283 |
0 |
| break; |
| 284 |
|
| |
| 285 |
0 |
| case 3: |
| 286 |
0 |
| switch (in_channels) { |
| 287 |
0 |
| case 1: |
| 288 |
0 |
| IM_ADAPT_COLORS(out_channels, in_channels, colors, count); |
| 289 |
0 |
| return; |
| 290 |
|
| |
| 291 |
0 |
| case 2: |
| 292 |
|
| { |
| 293 |
0 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
0 |
0 |
0 |
|
| 294 |
|
| int ch; |
| 295 |
0 |
| IM_WORK_T src_grey = colors->channel[0]; |
| 296 |
0 |
| IM_WORK_T src_alpha = colors->channel[1]; |
| 297 |
0 |
▶ | for (ch = 0; ch < 3; ++ch) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (ch = 0; ch < 3; ++ch) { |
0 |
0 |
0 |
| for (ch = 0; ch < 3; ++ch) { |
0 |
0 |
0 |
|
| 298 |
0 |
| colors->channel[ch] = |
| 299 |
0 |
| (src_grey * src_alpha |
| 300 |
0 |
| + bg->channel[ch] * (IM_SAMPLE_MAX - src_alpha)) |
| 301 |
0 |
| / IM_SAMPLE_MAX; |
| 302 |
|
| } |
| 303 |
0 |
| ++colors; |
| 304 |
0 |
| --count; |
| 305 |
|
| } |
| 306 |
|
| } |
| 307 |
0 |
| break; |
| 308 |
|
| |
| 309 |
0 |
| case 4: |
| 310 |
|
| { |
| 311 |
0 |
▶ | while (count) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (count) { |
0 |
0 |
0 |
| while (count) { |
0 |
0 |
0 |
|
| 312 |
|
| int ch; |
| 313 |
0 |
| IM_WORK_T src_alpha = colors->channel[3]; |
| 314 |
0 |
▶ | for (ch = 0; ch < 3; ++ch) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (ch = 0; ch < 3; ++ch) { |
0 |
0 |
0 |
| for (ch = 0; ch < 3; ++ch) { |
0 |
0 |
0 |
|
| 315 |
0 |
| colors->channel[ch] = |
| 316 |
0 |
| (colors->channel[ch] * src_alpha |
| 317 |
0 |
| + bg->channel[ch] * (IM_SAMPLE_MAX - src_alpha)) |
| 318 |
0 |
| / IM_SAMPLE_MAX; |
| 319 |
|
| } |
| 320 |
0 |
| ++colors; |
| 321 |
0 |
| --count; |
| 322 |
|
| } |
| 323 |
|
| } |
| 324 |
0 |
| break; |
| 325 |
|
| } |
| 326 |
0 |
| break; |
| 327 |
|
| } |
| 328 |
|
| } |
| 329 |
|
| |
| 330 |
|
| /* |
| 331 |
|
| =item i_gsamp_bg(im, l, r, y, samples, out_channels, background) |
| 332 |
|
| |
| 333 |
|
| =category Drawing |
| 334 |
|
| |
| 335 |
|
| Like C<i_gsampf()> but applies the source image color over a supplied |
| 336 |
|
| background color. |
| 337 |
|
| |
| 338 |
|
| This is intended for output to image formats that don't support alpha |
| 339 |
|
| channels. |
| 340 |
|
| |
| 341 |
|
| =cut |
| 342 |
|
| |
| 343 |
|
| =item i_gsampf_bg(im, l, r, y, samples, out_channels, background) |
| 344 |
|
| |
| 345 |
|
| =category Drawing |
| 346 |
|
| |
| 347 |
|
| Like C<i_gsampf()> but applies the source image color over a supplied |
| 348 |
|
| background color. |
| 349 |
|
| |
| 350 |
|
| This is intended for output to image formats that don't support alpha |
| 351 |
|
| channels. |
| 352 |
|
| |
| 353 |
|
| =cut |
| 354 |
|
| */ |
| 355 |
|
| int |
| 356 |
|
| #ifdef IM_EIGHT_BIT |
| 357 |
3790 |
| i_gsamp_bg |
| 358 |
|
| #else |
| 359 |
1292 |
| i_gsampf_bg |
| 360 |
|
| #endif |
| 361 |
|
| (i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, IM_SAMPLE_T *samples, |
| 362 |
|
| int out_channels, IM_COLOR const *bg) { |
| 363 |
5082 |
▶ | if (out_channels == im->channels) |
Branch: 2 branches
| Branch | True | False | Total |
| if (out_channels == im->channels) |
1220 |
72 |
1292 |
| if (out_channels == im->channels) |
3686 |
104 |
3790 |
|
| 364 |
4906 |
| return IM_GSAMP(im, l, r, y, samples, NULL, im->channels); |
| 365 |
|
| |
| 366 |
176 |
| switch (out_channels) { |
| 367 |
0 |
| case 1: |
| 368 |
0 |
▶ | switch (im->channels) { |
Branch: 2 branches
| Branch | True | False | Total |
| switch (im->channels) { |
0 |
0 |
0 |
| switch (im->channels) { |
0 |
0 |
0 |
|
| 369 |
0 |
| case 2: |
| 370 |
|
| { |
| 371 |
|
| i_img_dim x; |
| 372 |
0 |
| IM_SAMPLE_T *inp = samples, *outp = samples; |
| 373 |
0 |
| IM_WORK_T grey_bg = IM_ROUND(color_to_grey(bg)); |
| 374 |
|
| i_img_dim count; |
| 375 |
|
| |
| 376 |
0 |
| count = IM_GSAMP(im, l, r, y, samples, NULL, im->channels); |
| 377 |
0 |
| if (!count) |
| 378 |
0 |
| return 0; |
| 379 |
|
| |
| 380 |
0 |
▶ | for (x = l; x < r; ++x) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (x = l; x < r; ++x) { |
0 |
0 |
0 |
| for (x = l; x < r; ++x) { |
0 |
0 |
0 |
|
| 381 |
0 |
| *outp++ = ( inp[0] * inp[1] + |
| 382 |
0 |
| grey_bg * (IM_SAMPLE_MAX - inp[1])) / IM_SAMPLE_MAX; |
| 383 |
0 |
| inp += 2; |
| 384 |
|
| } |
| 385 |
|
| |
| 386 |
0 |
| return count; |
| 387 |
|
| } |
| 388 |
|
| break; |
| 389 |
|
| |
| 390 |
0 |
| default: |
| 391 |
0 |
| i_fatal(0, "i_gsamp_bg() can only remove alpha channels"); |
| 392 |
0 |
| break; |
| 393 |
|
| } |
| 394 |
0 |
| break; |
| 395 |
176 |
| case 3: |
| 396 |
176 |
| switch (im->channels) { |
| 397 |
0 |
| case 1: |
| 398 |
|
| { |
| 399 |
0 |
| int channels[3] = { 0, 0, 0 }; |
| 400 |
0 |
| return IM_GSAMP(im, l, r, y, samples, channels, out_channels); |
| 401 |
|
| } |
| 402 |
0 |
| case 2: |
| 403 |
|
| { |
| 404 |
|
| i_img_dim x; |
| 405 |
|
| int ch; |
| 406 |
0 |
| IM_SAMPLE_T *inp = samples, *outp = samples; |
| 407 |
|
| i_img_dim count; |
| 408 |
0 |
| int channels[4] = { 0, 0, 0, 1 }; |
| 409 |
|
| |
| 410 |
0 |
| count = IM_GSAMP(im, l, r, y, samples, channels, im->channels); |
| 411 |
0 |
| if (!count) |
| 412 |
0 |
| return 0; |
| 413 |
|
| |
| 414 |
0 |
▶ | for (x = l; x < r; ++x) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (x = l; x < r; ++x) { |
0 |
0 |
0 |
| for (x = l; x < r; ++x) { |
0 |
0 |
0 |
|
| 415 |
0 |
| IM_WORK_T alpha = inp[3]; |
| 416 |
0 |
▶ | for (ch = 0; ch < 3; ++ch) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (ch = 0; ch < 3; ++ch) { |
0 |
0 |
0 |
| for (ch = 0; ch < 3; ++ch) { |
0 |
0 |
0 |
|
| 417 |
0 |
| *outp++ = ( *inp++ * alpha + |
| 418 |
0 |
| bg->channel[ch] * (IM_SAMPLE_MAX - alpha)) / IM_SAMPLE_MAX; |
| 419 |
|
| } |
| 420 |
0 |
| ++inp; |
| 421 |
|
| } |
| 422 |
|
| |
| 423 |
0 |
| return count; |
| 424 |
|
| } |
| 425 |
|
| |
| 426 |
176 |
| case 4: |
| 427 |
|
| { |
| 428 |
|
| i_img_dim x; |
| 429 |
|
| int ch; |
| 430 |
176 |
| IM_SAMPLE_T *inp = samples, *outp = samples; |
| 431 |
|
| i_img_dim count; |
| 432 |
|
| |
| 433 |
176 |
| count = IM_GSAMP(im, l, r, y, samples, NULL, im->channels); |
| 434 |
176 |
| if (!count) |
| 435 |
0 |
| return 0; |
| 436 |
|
| |
| 437 |
4912 |
▶ | for (x = l; x < r; ++x) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (x = l; x < r; ++x) { |
2112 |
72 |
2184 |
| for (x = l; x < r; ++x) { |
2624 |
104 |
2728 |
|
| 438 |
4736 |
| IM_WORK_T alpha = inp[3]; |
| 439 |
18944 |
▶ | for (ch = 0; ch < 3; ++ch) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (ch = 0; ch < 3; ++ch) { |
6336 |
2112 |
8448 |
| for (ch = 0; ch < 3; ++ch) { |
7872 |
2624 |
10496 |
|
| 440 |
14208 |
| *outp++ = ( *inp++ * alpha + |
| 441 |
14208 |
| bg->channel[ch] * (IM_SAMPLE_MAX - alpha)) / IM_SAMPLE_MAX; |
| 442 |
|
| } |
| 443 |
4736 |
| ++inp; |
| 444 |
|
| } |
| 445 |
|
| |
| 446 |
176 |
| return count; |
| 447 |
|
| } |
| 448 |
|
| break; |
| 449 |
0 |
| default: |
| 450 |
0 |
| i_fatal(0, "i_gsamp_bg() can only remove alpha channels"); |
| 451 |
0 |
| break; |
| 452 |
|
| } |
| 453 |
0 |
| break; |
| 454 |
|
| |
| 455 |
0 |
| default: |
| 456 |
0 |
| i_fatal(0, "i_gsamp_bg() can only remove alpha channels"); |
| 457 |
|
| } |
| 458 |
|
| |
| 459 |
0 |
| return 0; |
| 460 |
|
| } |
| 461 |
|
| |
| 462 |
|
| #/code |
| 463 |
|
| |