X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/b8c2033e5aee9480ee5f2d219bde41ee1d365505..5caa40a62404f7c43eee8826bfb3d9577c57c08f:/filters.c diff --git a/filters.c b/filters.c index 2110a341..2523de51 100644 --- a/filters.c +++ b/filters.c @@ -140,7 +140,7 @@ Inverts the pixel values by the amount specified. =cut */ -#ifdef _MSC_VER +#ifdef WIN32 /* random() is non-ASCII, even if it is better than rand() */ #define random() rand() #endif @@ -649,7 +649,10 @@ i_watermark(i_img *im, i_img *wmark, int tx, int ty, int pixdiff) { int vx, vy, ch; i_color val, wval; - for(vx=0;vx<128;vx++) for(vy=0;vy<110;vy++) { + int mx = wmark->xsize; + int my = wmark->ysize; + + for(vx=0;vxchannels != im2->channels) { + i_push_error(0, "different number of channels"); + return NULL; + } + + outchans = diffchans = im1->channels; + if (outchans == 1 || outchans == 3) + ++outchans; + + xsize = i_min(im1->xsize, im2->xsize); + ysize = i_min(im1->ysize, im2->ysize); + + out = i_sametype_chans(im1, xsize, ysize, outchans); + + if (im1->bits == i_8_bits && im2->bits == i_8_bits) { + i_color *line1 = mymalloc(2 * xsize * sizeof(*line1)); + i_color *line2 = line1 + xsize; + i_color empty; + int x, y, ch; + + for (ch = 0; ch < MAXCHANNELS; ++ch) + empty.channel[ch] = 0; + + for (y = 0; y < ysize; ++y) { + i_glin(im1, 0, xsize, y, line1); + i_glin(im2, 0, xsize, y, line2); + if (outchans != diffchans) { + /* give the output an alpha channel since it doesn't have one */ + for (x = 0; x < xsize; ++x) + line2[x].channel[diffchans] = 255; + } + for (x = 0; x < xsize; ++x) { + int diff = 0; + for (ch = 0; ch < diffchans; ++ch) { + if (line1[x].channel[ch] != line2[x].channel[ch] + && abs(line1[x].channel[ch] - line2[x].channel[ch]) > mindiff) { + diff = 1; + break; + } + } + if (!diff) + line2[x] = empty; + } + i_plin(out, 0, xsize, y, line2); + } + myfree(line1); + } + else { + i_fcolor *line1 = mymalloc(2 * xsize * sizeof(*line1)); + i_fcolor *line2 = line1 + xsize; + i_fcolor empty; + int x, y, ch; + double dist = mindiff / 255; + + for (ch = 0; ch < MAXCHANNELS; ++ch) + empty.channel[ch] = 0; + + for (y = 0; y < ysize; ++y) { + i_glinf(im1, 0, xsize, y, line1); + i_glinf(im2, 0, xsize, y, line2); + if (outchans != diffchans) { + /* give the output an alpha channel since it doesn't have one */ + for (x = 0; x < xsize; ++x) + line2[x].channel[diffchans] = 1.0; + } + for (x = 0; x < xsize; ++x) { + int diff = 0; + for (ch = 0; ch < diffchans; ++ch) { + if (line1[x].channel[ch] != line2[x].channel[ch] + && abs(line1[x].channel[ch] - line2[x].channel[ch]) > dist) { + diff = 1; + break; + } + } + if (!diff) + line2[x] = empty; + } + i_plinf(out, 0, xsize, y, line2); + } + myfree(line1); + } + + return out; +} + struct fount_state; static double linear_fount_f(double x, double y, struct fount_state *state); static double bilinear_fount_f(double x, double y, struct fount_state *state); @@ -1456,6 +1563,7 @@ i_fountain(i_img *im, double xa, double ya, double xb, double yb, i_plinf(im, 0, im->xsize, y, line); } fount_finish_state(&state); + if (work) myfree(work); myfree(line); } @@ -1466,7 +1574,7 @@ typedef struct { static void fill_fountf(i_fill_t *fill, int x, int y, int width, int channels, - i_fcolor *data, i_fcolor *work); + i_fcolor *data); static void fount_fill_destroy(i_fill_t *fill); @@ -2077,42 +2185,21 @@ The fill function for fountain fills. */ static void fill_fountf(i_fill_t *fill, int x, int y, int width, int channels, - i_fcolor *data, i_fcolor *work) { + i_fcolor *data) { i_fill_fountain_t *f = (i_fill_fountain_t *)fill; - if (fill->combinef) { - i_fcolor *wstart = work; - int count = width; - - while (width--) { - i_fcolor c; - int got_one; - - if (f->state.ssfunc) - got_one = f->state.ssfunc(&c, x, y, &f->state); - else - got_one = fount_getat(&c, x, y, &f->state); - - *work++ = c; - - ++x; - } - (fill->combinef)(data, wstart, channels, count); - } - else { - while (width--) { - i_fcolor c; - int got_one; - - if (f->state.ssfunc) - got_one = f->state.ssfunc(&c, x, y, &f->state); - else - got_one = fount_getat(&c, x, y, &f->state); - - *data++ = c; - - ++x; - } + while (width--) { + i_fcolor c; + int got_one; + + if (f->state.ssfunc) + got_one = f->state.ssfunc(&c, x, y, &f->state); + else + got_one = fount_getat(&c, x, y, &f->state); + + *data++ = c; + + ++x; } }