From 0deb4abc251fe0c717bb7892cb569e4a114fadca Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 18 Apr 2006 16:50:56 +0000 Subject: [PATCH] * Changed the cucul_dither_bitmap behaviour so that the 4 coordinates are now x/y/width/height instead of x1/y1/x2/y2. Avoids unnecessary +1/-1 computations. --- cucul/dither.c | 26 ++++++++++---------------- src/aafire.c | 4 ++-- src/cacaball.c | 4 ++-- src/cacamoir.c | 4 ++-- src/cacaplas.c | 4 ++-- src/cacaview.c | 26 ++++++++++++-------------- src/img2irc.c | 2 +- test/demo.c | 4 ++-- test/export.c | 4 ++-- test/font.c | 4 ++-- test/gamma.c | 8 ++++---- test/hsv.c | 4 ++-- 12 files changed, 43 insertions(+), 51 deletions(-) diff --git a/cucul/dither.c b/cucul/dither.c index a62d5b6..098e482 100644 --- a/cucul/dither.c +++ b/cucul/dither.c @@ -694,38 +694,32 @@ char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d) * and will be stretched to the text area. * * \param cv A handle to the libcucul canvas. - * \param x1 X coordinate of the upper-left corner of the drawing area. - * \param y1 Y coordinate of the upper-left corner of the drawing area. - * \param x2 X coordinate of the lower-right corner of the drawing area. - * \param y2 Y coordinate of the lower-right corner of the drawing area. + * \param x X coordinate of the upper-left corner of the drawing area. + * \param y Y coordinate of the upper-left corner of the drawing area. + * \param w Width of the drawing area. + * \param h Height of the drawing area. * \param d Dither object to be drawn. * \param pixels Bitmap's pixels. */ -void cucul_dither_bitmap(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, +void cucul_dither_bitmap(cucul_canvas_t *cv, int x, int y, int w, int h, cucul_dither_t const *d, void *pixels) { int *floyd_steinberg, *fs_r, *fs_g, *fs_b; int fs_length; - int x, y, w, h, pitch, deltax, deltay; + int x1, y1, x2, y2, pitch, deltax, deltay; unsigned int dchmax; if(!d || !pixels) return; + x1 = x; x2 = x + w - 1; + y1 = y; y2 = y + h - 1; + + /* FIXME: do not overwrite arguments */ w = d->w; h = d->h; pitch = d->pitch; - if(x1 > x2) - { - int tmp = x2; x2 = x1; x1 = tmp; - } - - if(y1 > y2) - { - int tmp = y2; y2 = y1; y1 = tmp; - } - deltax = x2 - x1 + 1; deltay = y2 - y1 + 1; dchmax = d->glyph_count; diff --git a/src/aafire.c b/src/aafire.c index b0303e3..09d2624 100644 --- a/src/aafire.c +++ b/src/aafire.c @@ -237,8 +237,8 @@ drawfire (void) firemain (); #ifdef LIBCACA paused: - cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1, - cucul_get_canvas_height(cv) - 1, cucul_dither, bitmap); + cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), + cucul_get_canvas_height(cv), cucul_dither, bitmap); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_putstr(cv, cucul_get_canvas_width(cv) - 30, cucul_get_canvas_height(cv) - 2, " -=[ Powered by libcaca ]=- "); diff --git a/src/cacaball.c b/src/cacaball.c index cfcd392..1b26c94 100644 --- a/src/cacaball.c +++ b/src/cacaball.c @@ -154,8 +154,8 @@ int main(int argc, char **argv) paused: /* Draw our virtual buffer to screen, letting libcucul resize it */ cucul_dither_bitmap(cv, 0, 0, - cucul_get_canvas_width(cv) - 1, - cucul_get_canvas_height(cv) - 1, + cucul_get_canvas_width(cv), + cucul_get_canvas_height(cv), cucul_dither, pixels + (METASIZE / 2) * (1 + XSIZ)); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_putstr(cv, cucul_get_canvas_width(cv) - 30, diff --git a/src/cacamoir.c b/src/cacamoir.c index 20d4925..214b8ac 100644 --- a/src/cacamoir.c +++ b/src/cacamoir.c @@ -107,8 +107,8 @@ int main (int argc, char **argv) paused: cucul_dither_bitmap(cv, 0, 0, - cucul_get_canvas_width(cv) - 1, - cucul_get_canvas_height(cv) - 1, + cucul_get_canvas_width(cv), + cucul_get_canvas_height(cv), dither, screen); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); cucul_putstr(cv, cucul_get_canvas_width(cv) - 30, diff --git a/src/cacaplas.c b/src/cacaplas.c index b014d0f..1fd4d82 100644 --- a/src/cacaplas.c +++ b/src/cacaplas.c @@ -122,8 +122,8 @@ int main (int argc, char **argv) paused: cucul_dither_bitmap(cv, 0, 0, - cucul_get_canvas_width(cv) - 1, - cucul_get_canvas_height(cv) - 1, + cucul_get_canvas_width(cv), + cucul_get_canvas_height(cv), dither, screen); cucul_blit(c2, 0, 0, cv, NULL); diff --git a/src/cacaview.c b/src/cacaview.c index 1210bf4..1d3ce47 100644 --- a/src/cacaview.c +++ b/src/cacaview.c @@ -362,14 +362,12 @@ int main(int argc, char **argv) draw_checkers(ww * (1.0 - xfactor) / 2, y + height * (1.0 - yfactor) / 2, - ww * (1.0 + xfactor) / 2, - y + height * (1.0 + yfactor) / 2); + ww * xfactor, height * yfactor); cucul_dither_bitmap(cv, ww * (1.0 - xfactor) * xdelta, - y + height * (1.0 - yfactor) * ydelta, - ww * (xdelta + (1.0 - xdelta) * xfactor), - y + height * (ydelta + (1.0 - ydelta) * yfactor), - im->dither, im->pixels); + y + height * (1.0 - yfactor) * ydelta, + ww * xfactor + 1, height * yfactor + 1, + im->dither, im->pixels); } if(!fullscreen) @@ -502,19 +500,19 @@ static void set_gamma(int new_gamma) (g < 0) ? 1.0 / gammatab[-g] : gammatab[g]); } -static void draw_checkers(int x1, int y1, int x2, int y2) +static void draw_checkers(int x, int y, int w, int h) { int xn, yn; - if(x2 + 1 > (int)cucul_get_canvas_width(cv)) - x2 = cucul_get_canvas_width(cv) - 1; - if(y2 + 1 > (int)cucul_get_canvas_height(cv)) - y2 = cucul_get_canvas_height(cv) - 1; + if(x + w > (int)cucul_get_canvas_width(cv)) + w = cucul_get_canvas_width(cv) - x; + if(y + h > (int)cucul_get_canvas_height(cv)) + h = cucul_get_canvas_height(cv) - y; - for(yn = y1 > 0 ? y1 : 0; yn <= y2; yn++) - for(xn = x1 > 0 ? x1 : 0; xn <= x2; xn++) + for(yn = y > 0 ? y : 0; yn < y + h; yn++) + for(xn = x > 0 ? x : 0; xn < x + w; xn++) { - if((((xn - x1) / 5) ^ ((yn - y1) / 3)) & 1) + if((((xn - x) / 5) ^ ((yn - y) / 3)) & 1) cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY); else cucul_set_color(cv, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY); diff --git a/src/img2irc.c b/src/img2irc.c index 3be8acd..88ca8de 100644 --- a/src/img2irc.c +++ b/src/img2irc.c @@ -54,7 +54,7 @@ int main(int argc, char **argv) cucul_set_canvas_size(cv, cols, lines); cucul_clear_canvas(cv, CUCUL_COLOR_TRANSPARENT); - cucul_dither_bitmap(cv, 0, 0, cols - 1, lines - 1, i->dither, i->pixels); + cucul_dither_bitmap(cv, 0, 0, cols, lines, i->dither, i->pixels); unload_image(i); diff --git a/test/demo.c b/test/demo.c index 9ef79c9..7ab84bd 100644 --- a/test/demo.c +++ b/test/demo.c @@ -504,7 +504,7 @@ static void demo_render(void) cucul_set_dither_invert(dither, 1); //dither = cucul_create_dither(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000); dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); - cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1, cucul_get_canvas_height(cv) - 1, + cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv), dither, buffer); cucul_free_dither(dither); } @@ -549,7 +549,7 @@ static void demo_render(void) dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); cucul_set_dither_invert(dither, 1); - cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1, cucul_get_canvas_height(cv) - 1, dither, (char *)buffer); + cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv), dither, (char *)buffer); cucul_free_dither(dither); } diff --git a/test/export.c b/test/export.c index f3133e6..c229dc2 100644 --- a/test/export.c +++ b/test/export.c @@ -80,8 +80,8 @@ int main(int argc, char *argv[]) dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); - cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1, - cucul_get_canvas_height(cv) - 1, dither, pixels); + cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), + cucul_get_canvas_height(cv), dither, pixels); cucul_free_dither(dither); cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); diff --git a/test/font.c b/test/font.c index 694803e..ef4669e 100644 --- a/test/font.c +++ b/test/font.c @@ -93,8 +93,8 @@ int main(int argc, char *argv[]) d = cucul_create_dither(32, w, h, 4 * w, 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff); - cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1, - cucul_get_canvas_height(cv) - 1, d, buf); + cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), + cucul_get_canvas_height(cv), d, buf); caca_display(dp); caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); diff --git a/test/gamma.c b/test/gamma.c index fd079f9..8c1420a 100644 --- a/test/gamma.c +++ b/test/gamma.c @@ -81,13 +81,13 @@ int main(void) cucul_set_canvas_size(mask, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv)); /* Draw the regular dither on the main canvas */ - cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1, - cucul_get_canvas_height(cv) - 1, left, buffer); + cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), + cucul_get_canvas_height(cv), left, buffer); /* Draw the gamma-modified dither on the spare canvas */ cucul_set_dither_gamma(right, gam); - cucul_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw) - 1, - cucul_get_canvas_height(cw) - 1, right, buffer); + cucul_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw), + cucul_get_canvas_height(cw), right, buffer); /* Draw something on the mask */ cucul_clear_canvas(mask, CUCUL_COLOR_BLACK); diff --git a/test/hsv.c b/test/hsv.c index 61d8840..68bb80e 100644 --- a/test/hsv.c +++ b/test/hsv.c @@ -46,8 +46,8 @@ int main(void) dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); - cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv) - 1, - cucul_get_canvas_height(cv) - 1, dither, buffer); + cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), + cucul_get_canvas_height(cv), dither, buffer); cucul_free_dither(dither); caca_display(dp);