line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "imager.h" |
2
|
|
|
|
|
|
|
#include "imageri.h" |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
/* |
5
|
|
|
|
|
|
|
=item i_copyto(C, C, C, C, C, C, C, C) |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=category Image |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Copies image data from the area (C,C)-[C,C] in the |
10
|
|
|
|
|
|
|
source image to a rectangle the same size with it's top-left corner at |
11
|
|
|
|
|
|
|
(C,C) in the destination image. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
If C > C or C > C then the corresponding co-ordinates |
14
|
|
|
|
|
|
|
are swapped. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
*/ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
void |
20
|
83
|
|
|
|
|
|
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
|
83
|
50
|
|
|
|
|
if (x2
|
24
|
83
|
50
|
|
|
|
|
if (y2
|
25
|
83
|
50
|
|
|
|
|
if (tx < 0) { |
26
|
|
|
|
|
|
|
/* adjust everything equally */ |
27
|
0
|
|
|
|
|
|
x1 += -tx; |
28
|
0
|
|
|
|
|
|
x2 += -tx; |
29
|
0
|
|
|
|
|
|
tx = 0; |
30
|
|
|
|
|
|
|
} |
31
|
83
|
50
|
|
|
|
|
if (ty < 0) { |
32
|
0
|
|
|
|
|
|
y1 += -ty; |
33
|
0
|
|
|
|
|
|
y2 += -ty; |
34
|
0
|
|
|
|
|
|
ty = 0; |
35
|
|
|
|
|
|
|
} |
36
|
83
|
50
|
|
|
|
|
if (x1 >= src->xsize || y1 >= src->ysize) |
|
|
50
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return; /* nothing to do */ |
38
|
83
|
50
|
|
|
|
|
if (x2 > src->xsize) |
39
|
0
|
|
|
|
|
|
x2 = src->xsize; |
40
|
83
|
50
|
|
|
|
|
if (y2 > src->ysize) |
41
|
0
|
|
|
|
|
|
y2 = src->ysize; |
42
|
83
|
50
|
|
|
|
|
if (x1 == x2 || y1 == y2) |
|
|
50
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return; /* nothing to do */ |
44
|
|
|
|
|
|
|
|
45
|
83
|
|
|
|
|
|
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
|
83
|
100
|
|
|
|
|
#code im->bits == i_8_bits |
50
|
83
|
|
|
|
|
|
IM_COLOR *row = mymalloc(sizeof(IM_COLOR) * (x2-x1)); |
51
|
83
|
|
|
|
|
|
tty = ty; |
52
|
6019
|
100
|
|
|
|
|
for(y=y1; y
|
|
|
100
|
|
|
|
|
|
53
|
5936
|
|
|
|
|
|
IM_GLIN(src, x1, x2, y, row); |
54
|
5936
|
|
|
|
|
|
if (src->channels != im->channels) |
55
|
900
|
|
|
|
|
|
IM_ADAPT_COLORS(im->channels, src->channels, row, x2-x1); |
56
|
5936
|
|
|
|
|
|
IM_PLIN(im, tx, tx+x2-x1, tty, row); |
57
|
5936
|
|
|
|
|
|
tty++; |
58
|
|
|
|
|
|
|
} |
59
|
83
|
|
|
|
|
|
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
|
100
|
|
|
|
|
if (out_channels == in_channels) |
|
|
100
|
|
|
|
|
|
73
|
2138
|
|
|
|
|
|
return; |
74
|
1730
|
50
|
|
|
|
|
if (count == 0) |
|
|
50
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return; |
76
|
|
|
|
|
|
|
|
77
|
1730
|
|
|
|
|
|
switch (out_channels) { |
78
|
|
|
|
|
|
|
case 1: |
79
|
|
|
|
|
|
|
{ |
80
|
370
|
|
|
|
|
|
switch (in_channels) { |
81
|
|
|
|
|
|
|
case 2: |
82
|
|
|
|
|
|
|
/* apply alpha against a black background */ |
83
|
2550
|
0
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
case 3: |
91
|
|
|
|
|
|
|
/* convert to grey */ |
92
|
27970
|
0
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
93
|
27700
|
|
|
|
|
|
colors->channel[0] = IM_ROUND(color_to_grey(colors)); |
94
|
27700
|
|
|
|
|
|
++colors; |
95
|
27700
|
|
|
|
|
|
--count; |
96
|
|
|
|
|
|
|
} |
97
|
270
|
|
|
|
|
|
return; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
case 4: |
100
|
2550
|
0
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
case 2: |
114
|
|
|
|
|
|
|
{ |
115
|
550
|
|
|
|
|
|
switch (in_channels) { |
116
|
|
|
|
|
|
|
case 1: |
117
|
5940
|
100
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
118
|
5800
|
|
|
|
|
|
colors->channel[1] = IM_SAMPLE_MAX; |
119
|
5800
|
|
|
|
|
|
++colors; |
120
|
5800
|
|
|
|
|
|
--count; |
121
|
|
|
|
|
|
|
} |
122
|
140
|
|
|
|
|
|
return; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
case 3: |
125
|
5940
|
100
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
case 4: |
134
|
7890
|
100
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
case 3: |
149
|
|
|
|
|
|
|
{ |
150
|
200
|
|
|
|
|
|
switch (in_channels) { |
151
|
|
|
|
|
|
|
case 1: |
152
|
5100
|
0
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
153
|
5000
|
|
|
|
|
|
colors->channel[1] = colors->channel[2] = colors->channel[0]; |
154
|
5000
|
|
|
|
|
|
++colors; |
155
|
5000
|
|
|
|
|
|
--count; |
156
|
|
|
|
|
|
|
} |
157
|
100
|
|
|
|
|
|
return; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
case 2: |
160
|
2550
|
0
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
case 4: |
170
|
2550
|
0
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
case 4: |
190
|
|
|
|
|
|
|
{ |
191
|
610
|
|
|
|
|
|
switch (in_channels) { |
192
|
|
|
|
|
|
|
case 1: |
193
|
5940
|
100
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
case 2: |
202
|
14130
|
0
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
case 3: |
211
|
16040
|
100
|
|
|
|
|
while (count) { |
|
|
100
|
|
|
|
|
|
212
|
15800
|
|
|
|
|
|
colors->channel[3] = IM_SAMPLE_MAX; |
213
|
15800
|
|
|
|
|
|
++colors; |
214
|
15800
|
|
|
|
|
|
--count; |
215
|
|
|
|
|
|
|
} |
216
|
240
|
|
|
|
|
|
return; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
if (out_channels == in_channels) |
|
|
0
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
return; |
240
|
0
|
0
|
|
|
|
|
if (count == 0) |
|
|
0
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
return; |
242
|
|
|
|
|
|
|
|
243
|
0
|
|
|
|
|
|
switch (out_channels) { |
244
|
|
|
|
|
|
|
case 2: |
245
|
|
|
|
|
|
|
case 4: |
246
|
0
|
|
|
|
|
|
IM_ADAPT_COLORS(out_channels, in_channels, colors, count); |
247
|
0
|
|
|
|
|
|
return; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
case 1: |
250
|
0
|
|
|
|
|
|
switch (in_channels) { |
251
|
|
|
|
|
|
|
case 3: |
252
|
0
|
|
|
|
|
|
IM_ADAPT_COLORS(out_channels, in_channels, colors, count); |
253
|
0
|
|
|
|
|
|
return; |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
while (count) { |
|
|
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
|
|
|
|
|
|
|
case 4: |
270
|
|
|
|
|
|
|
{ |
271
|
0
|
|
|
|
|
|
IM_WORK_T grey_bg = IM_ROUND(color_to_grey(bg)); |
272
|
0
|
0
|
|
|
|
|
while (count) { |
|
|
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
|
|
|
|
|
|
|
case 3: |
286
|
0
|
|
|
|
|
|
switch (in_channels) { |
287
|
|
|
|
|
|
|
case 1: |
288
|
0
|
|
|
|
|
|
IM_ADAPT_COLORS(out_channels, in_channels, colors, count); |
289
|
0
|
|
|
|
|
|
return; |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
case 2: |
292
|
|
|
|
|
|
|
{ |
293
|
0
|
0
|
|
|
|
|
while (count) { |
|
|
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
|
0
|
|
|
|
|
for (ch = 0; ch < 3; ++ch) { |
|
|
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
|
|
|
|
|
|
|
case 4: |
310
|
|
|
|
|
|
|
{ |
311
|
0
|
0
|
|
|
|
|
while (count) { |
|
|
0
|
|
|
|
|
|
312
|
|
|
|
|
|
|
int ch; |
313
|
0
|
|
|
|
|
|
IM_WORK_T src_alpha = colors->channel[3]; |
314
|
0
|
0
|
|
|
|
|
for (ch = 0; ch < 3; ++ch) { |
|
|
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 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 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
|
992
|
|
|
|
|
|
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
|
4782
|
100
|
|
|
|
|
if (out_channels == im->channels) |
|
|
100
|
|
|
|
|
|
364
|
4606
|
|
|
|
|
|
return IM_GSAMP(im, l, r, y, samples, NULL, im->channels); |
365
|
|
|
|
|
|
|
|
366
|
176
|
|
|
|
|
|
switch (out_channels) { |
367
|
|
|
|
|
|
|
case 1: |
368
|
0
|
0
|
|
|
|
|
switch (im->channels) { |
|
|
0
|
|
|
|
|
|
369
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
for (x = l; x < r; ++x) { |
|
|
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
|
|
|
|
|
|
|
default: |
391
|
0
|
|
|
|
|
|
i_fatal(0, "i_gsamp_bg() can only remove alpha channels"); |
392
|
0
|
|
|
|
|
|
break; |
393
|
|
|
|
|
|
|
} |
394
|
0
|
|
|
|
|
|
break; |
395
|
|
|
|
|
|
|
case 3: |
396
|
176
|
|
|
|
|
|
switch (im->channels) { |
397
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
for (x = l; x < r; ++x) { |
|
|
0
|
|
|
|
|
|
415
|
0
|
|
|
|
|
|
IM_WORK_T alpha = inp[3]; |
416
|
0
|
0
|
|
|
|
|
for (ch = 0; ch < 3; ++ch) { |
|
|
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
|
|
|
|
|
|
|
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
|
100
|
|
|
|
|
for (x = l; x < r; ++x) { |
|
|
100
|
|
|
|
|
|
438
|
4736
|
|
|
|
|
|
IM_WORK_T alpha = inp[3]; |
439
|
18944
|
100
|
|
|
|
|
for (ch = 0; ch < 3; ++ch) { |
|
|
100
|
|
|
|
|
|
440
|
36288
|
|
|
|
|
|
*outp++ = ( *inp++ * alpha + |
441
|
22080
|
|
|
|
|
|
bg->channel[ch] * (IM_SAMPLE_MAX - alpha)) / IM_SAMPLE_MAX; |
442
|
|
|
|
|
|
|
} |
443
|
4736
|
|
|
|
|
|
++inp; |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
|
446
|
176
|
|
|
|
|
|
return count; |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
break; |
449
|
|
|
|
|
|
|
default: |
450
|
0
|
|
|
|
|
|
i_fatal(0, "i_gsamp_bg() can only remove alpha channels"); |
451
|
0
|
|
|
|
|
|
break; |
452
|
|
|
|
|
|
|
} |
453
|
0
|
|
|
|
|
|
break; |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|