now x/y/width/height instead of x1/y1/x2/y2. Avoids unnecessary +1/-1 computations.tags/v0.99.beta14
@@ -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. | * and will be stretched to the text area. | ||||
* | * | ||||
* \param cv A handle to the libcucul canvas. | * \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 d Dither object to be drawn. | ||||
* \param pixels Bitmap's pixels. | * \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) | cucul_dither_t const *d, void *pixels) | ||||
{ | { | ||||
int *floyd_steinberg, *fs_r, *fs_g, *fs_b; | int *floyd_steinberg, *fs_r, *fs_g, *fs_b; | ||||
int fs_length; | int fs_length; | ||||
int x, y, w, h, pitch, deltax, deltay; | |||||
int x1, y1, x2, y2, pitch, deltax, deltay; | |||||
unsigned int dchmax; | unsigned int dchmax; | ||||
if(!d || !pixels) | if(!d || !pixels) | ||||
return; | return; | ||||
x1 = x; x2 = x + w - 1; | |||||
y1 = y; y2 = y + h - 1; | |||||
/* FIXME: do not overwrite arguments */ | |||||
w = d->w; | w = d->w; | ||||
h = d->h; | h = d->h; | ||||
pitch = d->pitch; | 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; | deltax = x2 - x1 + 1; | ||||
deltay = y2 - y1 + 1; | deltay = y2 - y1 + 1; | ||||
dchmax = d->glyph_count; | dchmax = d->glyph_count; | ||||
@@ -237,8 +237,8 @@ drawfire (void) | |||||
firemain (); | firemain (); | ||||
#ifdef LIBCACA | #ifdef LIBCACA | ||||
paused: | 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_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | ||||
cucul_putstr(cv, cucul_get_canvas_width(cv) - 30, | cucul_putstr(cv, cucul_get_canvas_width(cv) - 30, | ||||
cucul_get_canvas_height(cv) - 2, " -=[ Powered by libcaca ]=- "); | cucul_get_canvas_height(cv) - 2, " -=[ Powered by libcaca ]=- "); | ||||
@@ -154,8 +154,8 @@ int main(int argc, char **argv) | |||||
paused: | paused: | ||||
/* Draw our virtual buffer to screen, letting libcucul resize it */ | /* Draw our virtual buffer to screen, letting libcucul resize it */ | ||||
cucul_dither_bitmap(cv, 0, 0, | 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_dither, pixels + (METASIZE / 2) * (1 + XSIZ)); | ||||
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | ||||
cucul_putstr(cv, cucul_get_canvas_width(cv) - 30, | cucul_putstr(cv, cucul_get_canvas_width(cv) - 30, | ||||
@@ -107,8 +107,8 @@ int main (int argc, char **argv) | |||||
paused: | paused: | ||||
cucul_dither_bitmap(cv, 0, 0, | 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); | dither, screen); | ||||
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | ||||
cucul_putstr(cv, cucul_get_canvas_width(cv) - 30, | cucul_putstr(cv, cucul_get_canvas_width(cv) - 30, | ||||
@@ -122,8 +122,8 @@ int main (int argc, char **argv) | |||||
paused: | paused: | ||||
cucul_dither_bitmap(cv, 0, 0, | 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); | dither, screen); | ||||
cucul_blit(c2, 0, 0, cv, NULL); | cucul_blit(c2, 0, 0, cv, NULL); | ||||
@@ -362,14 +362,12 @@ int main(int argc, char **argv) | |||||
draw_checkers(ww * (1.0 - xfactor) / 2, | draw_checkers(ww * (1.0 - xfactor) / 2, | ||||
y + height * (1.0 - yfactor) / 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, | 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) | if(!fullscreen) | ||||
@@ -502,19 +500,19 @@ static void set_gamma(int new_gamma) | |||||
(g < 0) ? 1.0 / gammatab[-g] : gammatab[g]); | (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; | 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); | cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY); | ||||
else | else | ||||
cucul_set_color(cv, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY); | cucul_set_color(cv, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY); | ||||
@@ -54,7 +54,7 @@ int main(int argc, char **argv) | |||||
cucul_set_canvas_size(cv, cols, lines); | cucul_set_canvas_size(cv, cols, lines); | ||||
cucul_clear_canvas(cv, CUCUL_COLOR_TRANSPARENT); | 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); | unload_image(i); | ||||
@@ -504,7 +504,7 @@ static void demo_render(void) | |||||
cucul_set_dither_invert(dither, 1); | cucul_set_dither_invert(dither, 1); | ||||
//dither = cucul_create_dither(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000); | //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); | 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); | dither, buffer); | ||||
cucul_free_dither(dither); | 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); | dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); | ||||
cucul_set_dither_invert(dither, 1); | 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); | cucul_free_dither(dither); | ||||
} | } | ||||
@@ -80,8 +80,8 @@ int main(int argc, char *argv[]) | |||||
dither = cucul_create_dither(32, 256, 256, 4 * 256, | dither = cucul_create_dither(32, 256, 256, 4 * 256, | ||||
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); | 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_free_dither(dither); | ||||
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | ||||
@@ -93,8 +93,8 @@ int main(int argc, char *argv[]) | |||||
d = cucul_create_dither(32, w, h, 4 * w, | d = cucul_create_dither(32, w, h, 4 * w, | ||||
0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff); | 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_display(dp); | ||||
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); | caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); | ||||
@@ -81,13 +81,13 @@ int main(void) | |||||
cucul_set_canvas_size(mask, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv)); | cucul_set_canvas_size(mask, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv)); | ||||
/* Draw the regular dither on the main canvas */ | /* 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 */ | /* Draw the gamma-modified dither on the spare canvas */ | ||||
cucul_set_dither_gamma(right, gam); | 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 */ | /* Draw something on the mask */ | ||||
cucul_clear_canvas(mask, CUCUL_COLOR_BLACK); | cucul_clear_canvas(mask, CUCUL_COLOR_BLACK); | ||||
@@ -46,8 +46,8 @@ int main(void) | |||||
dither = cucul_create_dither(32, 256, 256, 4 * 256, | dither = cucul_create_dither(32, 256, 256, 4 * 256, | ||||
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); | 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); | cucul_free_dither(dither); | ||||
caca_display(dp); | caca_display(dp); | ||||