6 i_compose_mask(i_img *out, i_img *src, i_img *mask,
7 int out_left, int out_top,
8 int src_left, int src_top,
9 int mask_left, int mask_top,
10 int width, int height,
15 i_fill_combine_f combinef_8;
16 i_fill_combinef_f combinef_double;
20 if (out_left >= out->xsize
21 || out_top >= out->ysize
22 || src_left >= src->xsize
23 || src_top >= src->ysize
26 || out_left + width <= 0
27 || out_top + height <= 0
28 || src_left + width <= 0
29 || src_top + height <= 0
30 || mask_left >= mask->xsize
31 || mask_top >= mask->ysize
32 || mask_left + width <= 0
33 || mask_top + height <= 0)
37 width = out_left + width;
40 if (out_left + width > out->xsize)
41 width = out->xsize - out_left;
44 height = out_top + height;
47 if (out_top + height > out->ysize)
48 height = out->ysize - out_top;
51 width = src_left + width;
54 if (src_left + width > src->xsize)
55 width = src->xsize - src_left;
58 height = src_top + height;
61 if (src_top + height > src->ysize)
62 height = src->ysize - src_left;
65 width = mask_left + width;
68 if (mask_left + width > mask->xsize)
69 width = mask->xsize - mask_left;
72 height = mask->ysize + height;
75 if (mask_top + height > mask->ysize)
76 height = mask->xsize - mask_top;
80 else if (opacity <= 0)
83 i_get_combine(combine, &combinef_8, &combinef_double);
85 i_render_init(&r, out, width);
86 #code out->bits <= 8 && src->bits<= 8 && mask->bits <= 8
87 IM_COLOR *src_line = mymalloc(sizeof(IM_COLOR) * width);
88 IM_SAMPLE_T *mask_line = mymalloc(sizeof(IM_SAMPLE_T) * width);
89 int adapt_channels = out->channels;
91 if (adapt_channels == 1 || adapt_channels == 3)
94 for (dy = 0; dy < height; ++dy) {
95 IM_GLIN(src, src_left, src_left + width, src_top + dy, src_line);
96 IM_ADAPT_COLORS(adapt_channels, src->channels, src_line, width);
97 IM_GSAMP(mask, mask_left, mask_left + width, mask_top + dy,
98 mask_line, &channel_zero, 1);
101 IM_SAMPLE_T *maskp = mask_line;
102 for (i = 0; i < width; ++i) {
103 *maskp = IM_ROUND(*maskp * opacity);
107 IM_RENDER_LINE(&r, out_left, out_top+dy, width, mask_line, src_line,
108 IM_SUFFIX(combinef));
120 i_compose(i_img *out, i_img *src,
121 int out_left, int out_top,
122 int src_left, int src_top,
123 int width, int height,
128 i_fill_combine_f combinef_8;
129 i_fill_combinef_f combinef_double;
132 if (out_left >= out->xsize
133 || out_top >= out->ysize
134 || src_left >= src->xsize
135 || src_top >= src->ysize
138 || out_left + width <= 0
139 || out_top + height <= 0
140 || src_left + width <= 0
141 || src_top + height <= 0)
145 width = out_left + width;
148 if (out_left + width > out->xsize)
149 width = out->xsize - out_left;
152 height = out_top + height;
155 if (out_top + height > out->ysize)
156 height = out->ysize - out_top;
159 width = src_left + width;
162 if (src_left + width > src->xsize)
163 width = src->xsize - src_left;
166 height = src_top + height;
169 if (src_top + height > src->ysize)
170 height = src->ysize - src_left;
174 else if (opacity <= 0)
177 i_get_combine(combine, &combinef_8, &combinef_double);
179 i_render_init(&r, out, width);
180 #code out->bits <= 8 && src->bits <= 8
181 IM_COLOR *src_line = mymalloc(sizeof(IM_COLOR) * width);
182 IM_SAMPLE_T *mask_line = NULL;
183 int adapt_channels = out->channels;
185 if (opacity != 1.0) {
187 IM_SAMPLE_T mask_value = IM_ROUND(opacity * IM_SAMPLE_MAX);
188 mask_line = mymalloc(sizeof(IM_SAMPLE_T) * width);
190 for (i = 0; i < width; ++i)
191 mask_line[i] = mask_value;
194 if (adapt_channels == 1 || adapt_channels == 3)
197 for (dy = 0; dy < height; ++dy) {
198 IM_GLIN(src, src_left, src_left + width, src_top + dy, src_line);
199 IM_ADAPT_COLORS(adapt_channels, src->channels, src_line, width);
200 IM_RENDER_LINE(&r, out_left, out_top+dy, width, mask_line, src_line,
201 IM_SUFFIX(combinef));