Skip to content

Commit

Permalink
image fills with images with channels not at 4 were broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Cook committed Jun 25, 2003
1 parent b4d8a00 commit cde2dbc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -718,6 +718,9 @@ Revision history for Perl extension Imager.
which we use, define it if freetype doesn't.
- Added extra options to rubthrough() so only a subpart of
source image is used.
- the image fills didn't handle filling with source images of
less than four channels correctly

=================================================================

For latest versions check the Imager-devel pages:
Expand Down
53 changes: 50 additions & 3 deletions fills.c
Expand Up @@ -727,6 +727,7 @@ static void fill_image(i_fill_t *fill, int x, int y, int width, int channels,
struct i_fill_image_t *f = (struct i_fill_image_t *)fill;
int i = 0;
i_color c;
i_color *out = data;

if (f->has_matrix) {
/* the hard way */
Expand Down Expand Up @@ -761,7 +762,7 @@ static void fill_image(i_fill_t *fill, int x, int y, int width, int channels,
}
c2[dy] = interp_i_color(c[dy][0], c[dy][1], rx, f->src->channels);
}
*data++ = interp_i_color(c2[0], c2[1], ry, f->src->channels);
*out++ = interp_i_color(c2[0], c2[1], ry, f->src->channels);
++i;
}
}
Expand All @@ -784,11 +785,34 @@ static void fill_image(i_fill_t *fill, int x, int y, int width, int channels,
}
rx -= ix * f->src->xsize;
ry -= iy * f->src->ysize;
i_gpix(f->src, rx, ry, data);
++data;
i_gpix(f->src, rx, ry, out);
++out;
++i;
}
}
if (f->src->channels == 3) {
/* just set the alpha */
for (i = 0; i < width; ++i) {
data->channel[3] = 255;
data++;
}
}
else if (f->src->channels == 2) {
/* copy the alpha to channel 3, duplicate the grey value */
for (i = 0; i < width; ++i) {
data->channel[3] = data->channel[1];
data->channel[1] = data->channel[2] = data->channel[0];
data++;
}
}
else if (f->src->channels == 1) {
/* set the alpha, duplicate grey */
for (i = 0; i < width; ++i) {
data->channel[3] = 255;
data->channel[1] = data->channel[2] = data->channel[0];
data++;
}
}
}

/*
Expand Down Expand Up @@ -863,6 +887,29 @@ static void fill_imagef(i_fill_t *fill, int x, int y, int width, int channels,
++i;
}
}
if (f->src->channels == 3) {
/* just set the alpha */
for (i = 0; i < width; ++i) {
data->channel[3] = 1.0;
data++;
}
}
else if (f->src->channels == 2) {
/* copy the alpha to channel 3, duplicate the grey value */
for (i = 0; i < width; ++i) {
data->channel[3] = data->channel[1];
data->channel[1] = data->channel[2] = data->channel[0];
data++;
}
}
else if (f->src->channels == 1) {
/* set the alpha, duplicate grey */
for (i = 0; i < width; ++i) {
data->channel[3] = 1.0;
data->channel[1] = data->channel[2] = data->channel[0];
data++;
}
}
}

static void combine_replace(i_color *, i_color *, int, int);
Expand Down

0 comments on commit cde2dbc

Please sign in to comment.