6 i_compose_mask(i_img *out, i_img *src, i_img *mask,
7 i_img_dim out_left, i_img_dim out_top,
8 i_img_dim src_left, i_img_dim src_top,
9 i_img_dim mask_left, i_img_dim mask_top,
10 i_img_dim width, i_img_dim height,
15 i_fill_combine_f combinef_8;
16 i_fill_combinef_f combinef_double;
19 mm_log((1, "i_compose_mask(out %p, src %p, mask %p, out(" i_DFp "), "
20 "src(" i_DFp "), mask(" i_DFp "), size(" i_DFp "),"
21 " combine %d opacity %f\n", out, src,
22 mask, i_DFcp(out_left, out_top), i_DFcp(src_left, src_top),
23 i_DFcp(mask_left, mask_top), i_DFcp(width, height),
27 if (out_left >= out->xsize
28 || out_top >= out->ysize
29 || src_left >= src->xsize
30 || src_top >= src->ysize
33 || out_left + width <= 0
34 || out_top + height <= 0
35 || src_left + width <= 0
36 || src_top + height <= 0
37 || mask_left >= mask->xsize
38 || mask_top >= mask->ysize
39 || mask_left + width <= 0
40 || mask_top + height <= 0)
44 width = out_left + width;
46 mask_left -= out_left;
49 if (out_left + width > out->xsize)
50 width = out->xsize - out_left;
53 height = out_top + height;
58 if (out_top + height > out->ysize)
59 height = out->ysize - out_top;
62 width = src_left + width;
64 mask_left -= src_left;
67 if (src_left + width > src->xsize)
68 width = src->xsize - src_left;
71 height = src_top + height;
76 if (src_top + height > src->ysize)
77 height = src->ysize - src_top;
80 width = mask_left + width;
81 out_left -= mask_left;
82 src_left -= mask_left;
85 if (mask_left + width > mask->xsize)
86 width = mask->xsize - mask_left;
89 height = mask_top + height;
94 if (mask_top + height > mask->ysize)
95 height = mask->ysize - mask_top;
99 else if (opacity <= 0) {
100 i_push_error(0, "opacity must be positive");
104 mm_log((1, "after adjustments: (out(" i_DFp "), src(" i_DFp "),"
105 " mask(" i_DFp "), size(" i_DFp ")\n",
106 i_DFcp(out_left, out_top), i_DFcp(src_left, src_top),
107 i_DFcp(mask_left, mask_top), i_DFcp(width, height)));
109 i_get_combine(combine, &combinef_8, &combinef_double);
111 i_render_init(&r, out, width);
112 #code out->bits <= 8 && src->bits<= 8 && mask->bits <= 8
113 IM_COLOR *src_line = mymalloc(sizeof(IM_COLOR) * width);
114 IM_SAMPLE_T *mask_line = mymalloc(sizeof(IM_SAMPLE_T) * width);
115 int adapt_channels = out->channels;
117 if (adapt_channels == 1 || adapt_channels == 3)
120 for (dy = 0; dy < height; ++dy) {
121 IM_GLIN(src, src_left, src_left + width, src_top + dy, src_line);
122 IM_ADAPT_COLORS(adapt_channels, src->channels, src_line, width);
123 IM_GSAMP(mask, mask_left, mask_left + width, mask_top + dy,
124 mask_line, &channel_zero, 1);
127 IM_SAMPLE_T *maskp = mask_line;
128 for (i = 0; i < width; ++i) {
129 *maskp = IM_ROUND(*maskp * opacity);
133 IM_RENDER_LINE(&r, out_left, out_top+dy, width, mask_line, src_line,
134 IM_SUFFIX(combinef));
146 i_compose(i_img *out, i_img *src,
147 i_img_dim out_left, i_img_dim out_top,
148 i_img_dim src_left, i_img_dim src_top,
149 i_img_dim width, i_img_dim height,
154 i_fill_combine_f combinef_8;
155 i_fill_combinef_f combinef_double;
157 mm_log((1, "i_compose(out %p, src %p, out(" i_DFp "), src(" i_DFp "), "
158 "size(" i_DFp "), combine %d opacity %f\n", out, src,
159 i_DFcp(out_left, out_top), i_DFcp(src_left, src_top),
160 i_DFcp(width, height), combine, opacity));
163 if (out_left >= out->xsize
164 || out_top >= out->ysize
165 || src_left >= src->xsize
166 || src_top >= src->ysize
169 || out_left + width <= 0
170 || out_top + height <= 0
171 || src_left + width <= 0
172 || src_top + height <= 0)
176 width = out_left + width;
177 src_left -= out_left;
180 if (out_left + width > out->xsize)
181 width = out->xsize - out_left;
184 height = out_top + height;
188 if (out_top + height > out->ysize)
189 height = out->ysize - out_top;
192 width = src_left + width;
193 out_left -= src_left;
196 if (src_left + width > src->xsize)
197 width = src->xsize - src_left;
200 height = src_top + height;
204 if (src_top + height > src->ysize)
205 height = src->ysize - src_top;
209 else if (opacity <= 0) {
210 i_push_error(0, "opacity must be positive");
214 i_get_combine(combine, &combinef_8, &combinef_double);
216 i_render_init(&r, out, width);
217 #code out->bits <= 8 && src->bits <= 8
218 IM_COLOR *src_line = mymalloc(sizeof(IM_COLOR) * width);
219 IM_SAMPLE_T *mask_line = NULL;
220 int adapt_channels = out->channels;
222 if (opacity != 1.0) {
224 IM_SAMPLE_T mask_value = IM_ROUND(opacity * IM_SAMPLE_MAX);
225 mask_line = mymalloc(sizeof(IM_SAMPLE_T) * width);
227 for (i = 0; i < width; ++i)
228 mask_line[i] = mask_value;
231 if (adapt_channels == 1 || adapt_channels == 3)
234 for (dy = 0; dy < height; ++dy) {
235 IM_GLIN(src, src_left, src_left + width, src_top + dy, src_line);
236 IM_ADAPT_COLORS(adapt_channels, src->channels, src_line, width);
237 IM_RENDER_LINE(&r, out_left, out_top+dy, width, mask_line, src_line,
238 IM_SUFFIX(combinef));