4 =item i_copyto(dest, src, x1, y1, x2, y2, tx, ty)
8 Copies image data from the area (x1,y1)-[x2,y2] in the source image to
9 a rectangle the same size with it's top-left corner at (tx,ty) in the
12 If x1 > x2 or y1 > y2 then the corresponding co-ordinates are swapped.
18 i_copyto(i_img *im, i_img *src, int x1, int y1, int x2, int y2, int tx, int ty) {
19 int x, y, t, ttx, tty;
21 if (x2<x1) { t=x1; x1=x2; x2=t; }
22 if (y2<y1) { t=y1; y1=y2; y2=t; }
24 /* adjust everything equally */
34 if (x1 >= src->xsize || y1 >= src->ysize)
35 return; /* nothing to do */
40 if (x1 == x2 || y1 == y2)
41 return; /* nothing to do */
43 mm_log((1,"i_copyto(im* %p, src %p, x1 %d, y1 %d, x2 %d, y2 %d, tx %d, ty %d)\n",
44 im, src, x1, y1, x2, y2, tx, ty));
46 #code im->bits == i_8_bits
47 IM_COLOR *row = mymalloc(sizeof(IM_COLOR) * (x2-x1));
49 for(y=y1; y<y2; y++) {
51 IM_GLIN(src, x1, x2, y, row);
52 if (src->channels != im->channels)
53 IM_ADAPT_COLORS(im->channels, src->channels, row, x2-x1);
54 IM_PLIN(im, tx, tx+x2-x1, tty, row);
61 #define color_to_grey(col) ((col)->rgb.r * 0.222 + (col)->rgb.g * 0.707 + (col)->rgb.b * 0.071)
70 (int out_channels, int in_channels, IM_COLOR *colors,
73 if (out_channels == in_channels)
78 switch (out_channels) {
81 switch (in_channels) {
83 /* apply alpha against a black background */
85 colors->channel[0] = colors->channel[0] * colors->channel[1] / IM_SAMPLE_MAX;
94 colors->channel[0] = IM_ROUND(color_to_grey(colors));
102 colors->channel[0] = IM_ROUND(color_to_grey(colors) * colors->channel[3] / IM_SAMPLE_MAX);
109 i_fatal(3, "i_adapt_colors: in_channels of %d invalid\n", in_channels);
110 return; /* avoid warnings */
116 switch (in_channels) {
119 colors->channel[1] = IM_SAMPLE_MAX;
127 colors->channel[0] = IM_ROUND(color_to_grey(colors));
128 colors->channel[1] = IM_SAMPLE_MAX;
136 colors->channel[0] = IM_ROUND(color_to_grey(colors));
137 colors->channel[1] = colors->channel[3];
144 i_fatal(3, "i_adapt_colors: in_channels of %d invalid\n", in_channels);
145 return; /* avoid warnings */
151 switch (in_channels) {
154 colors->channel[1] = colors->channel[2] = colors->channel[0];
162 int alpha = colors->channel[1];
163 colors->channel[0] = colors->channel[1] = colors->channel[2] =
164 IM_ROUND(colors->channel[0] * alpha / IM_SAMPLE_MAX);
172 int alpha = colors->channel[3];
174 IM_ROUND(colors->channel[0] * alpha / IM_SAMPLE_MAX);
176 IM_ROUND(colors->channel[1] * alpha / IM_SAMPLE_MAX);
178 IM_ROUND(colors->channel[2] * alpha / IM_SAMPLE_MAX);
185 i_fatal(3, "i_adapt_colors: in_channels of %d invalid\n", in_channels);
186 return; /* avoid warnings */
192 switch (in_channels) {
195 colors->channel[1] = colors->channel[2] = colors->channel[0];
196 colors->channel[3] = IM_SAMPLE_MAX;
204 colors->channel[3] = colors->channel[1];
205 colors->channel[1] = colors->channel[2] = colors->channel[0];
213 colors->channel[3] = IM_SAMPLE_MAX;
220 i_fatal(3, "i_adapt_colors: in_channels of %d invalid\n", in_channels);
221 return; /* avoid warnings */
226 i_fatal(3, "i_adapt_colors: out_channels of %d invalid\n", out_channels);
227 return; /* avoid warnings */