Преглед изворни кода

* Renamed *bitmap to *dither. Ben ouais connard, je fais ce que je veux.

tags/v0.99.beta14
Sam Hocevar sam пре 18 година
родитељ
комит
58ff9ea1f5
13 измењених фајлова са 295 додато и 298 уклоњено
  1. +189
    -190
      cucul/bitmap.c
  2. +2
    -2
      cucul/cucul.c
  3. +20
    -22
      cucul/cucul.h
  4. +2
    -2
      cucul/cucul_internals.h
  5. +6
    -6
      src/aafire.c
  6. +7
    -7
      src/cacaball.c
  7. +8
    -8
      src/cacamoir.c
  8. +8
    -8
      src/cacaplas.c
  9. +15
    -15
      src/cacaview.c
  10. +12
    -12
      test/demo.c
  11. +6
    -6
      test/export.c
  12. +14
    -14
      test/gamma.c
  13. +6
    -6
      test/hsv.c

+ 189
- 190
cucul/bitmap.c Прегледај датотеку

@@ -14,7 +14,7 @@
* \author Sam Hocevar <sam@zoy.org>
* \brief Bitmap blitting
*
* This file contains bitmap blitting functions.
* This file contains bitmap dithering functions.
*/

#include "config.h"
@@ -113,14 +113,14 @@ enum color_mode
COLOR_MODE_FULL16,
};

struct cucul_bitmap
struct cucul_dither
{
int bpp, has_palette, has_alpha;
int w, h, pitch;
int rmask, gmask, bmask, amask;
int rright, gright, bright, aright;
int rleft, gleft, bleft, aleft;
void (*get_hsv)(struct cucul_bitmap *, char *, int, int);
void (*get_hsv)(struct cucul_dither *, char *, int, int);
int red[256], green[256], blue[256], alpha[256];
float gamma;
int gammatab[4097];
@@ -165,7 +165,7 @@ struct cucul_bitmap
static void mask2shift(unsigned int, int *, int *);
static float gammapow(float x, float y);

static void get_rgba_default(struct cucul_bitmap const *, uint8_t *, int, int,
static void get_rgba_default(struct cucul_dither const *, uint8_t *, int, int,
unsigned int *);

/* Dithering methods */
@@ -230,12 +230,12 @@ static inline void rgb2hsv_default(int r, int g, int b,
}

/**
* \brief Create an internal bitmap object.
* \brief Create an internal dither object.
*
* Create a bitmap structure from its coordinates (depth, width, height and
* Create a dither structure from its coordinates (depth, width, height and
* pitch) and pixel mask values. If the depth is 8 bits per pixel, the mask
* values are ignored and the colour palette should be set using the
* cucul_set_bitmap_palette() function. For depths greater than 8 bits per
* cucul_set_dither_palette() function. For depths greater than 8 bits per
* pixel, a zero alpha mask causes the alpha values to be ignored.
*
* \param bpp Bitmap depth in bits per pixel.
@@ -246,101 +246,101 @@ static inline void rgb2hsv_default(int r, int g, int b,
* \param gmask Bitmask for green values.
* \param bmask Bitmask for blue values.
* \param amask Bitmask for alpha values.
* \return Bitmap object, or NULL upon error.
* \return Dither object, or NULL upon error.
*/
struct cucul_bitmap *cucul_create_bitmap(unsigned int bpp, unsigned int w,
struct cucul_dither *cucul_create_dither(unsigned int bpp, unsigned int w,
unsigned int h, unsigned int pitch,
unsigned int rmask, unsigned int gmask,
unsigned int bmask, unsigned int amask)
{
struct cucul_bitmap *bitmap;
struct cucul_dither *d;
int i;

/* Minor sanity test */
if(!w || !h || !pitch || bpp > 32 || bpp < 8)
return NULL;

bitmap = malloc(sizeof(struct cucul_bitmap));
if(!bitmap)
d = malloc(sizeof(struct cucul_dither));
if(!d)
return NULL;

bitmap->bpp = bpp;
bitmap->has_palette = 0;
bitmap->has_alpha = amask ? 1 : 0;
d->bpp = bpp;
d->has_palette = 0;
d->has_alpha = amask ? 1 : 0;

bitmap->w = w;
bitmap->h = h;
bitmap->pitch = pitch;
d->w = w;
d->h = h;
d->pitch = pitch;

bitmap->rmask = rmask;
bitmap->gmask = gmask;
bitmap->bmask = bmask;
bitmap->amask = amask;
d->rmask = rmask;
d->gmask = gmask;
d->bmask = bmask;
d->amask = amask;

/* Load bitmasks */
if(rmask || gmask || bmask || amask)
{
mask2shift(rmask, &bitmap->rright, &bitmap->rleft);
mask2shift(gmask, &bitmap->gright, &bitmap->gleft);
mask2shift(bmask, &bitmap->bright, &bitmap->bleft);
mask2shift(amask, &bitmap->aright, &bitmap->aleft);
mask2shift(rmask, &d->rright, &d->rleft);
mask2shift(gmask, &d->gright, &d->gleft);
mask2shift(bmask, &d->bright, &d->bleft);
mask2shift(amask, &d->aright, &d->aleft);
}

/* In 8 bpp mode, default to a grayscale palette */
if(bpp == 8)
{
bitmap->has_palette = 1;
bitmap->has_alpha = 0;
d->has_palette = 1;
d->has_alpha = 0;
for(i = 0; i < 256; i++)
{
bitmap->red[i] = i * 0xfff / 256;
bitmap->green[i] = i * 0xfff / 256;
bitmap->blue[i] = i * 0xfff / 256;
d->red[i] = i * 0xfff / 256;
d->green[i] = i * 0xfff / 256;
d->blue[i] = i * 0xfff / 256;
}
}

/* Default features */
bitmap->invert = 0;
bitmap->antialias = 1;
d->invert = 0;
d->antialias = 1;

/* Default gamma value */
for(i = 0; i < 4096; i++)
bitmap->gammatab[i] = i;
d->gammatab[i] = i;

/* Default colour mode */
bitmap->color_mode = COLOR_MODE_FULL16;
d->color_mode = COLOR_MODE_FULL16;

/* Default character set */
bitmap->glyphs = ascii_glyphs;
bitmap->glyph_count = sizeof(ascii_glyphs) / sizeof(*ascii_glyphs);
d->glyphs = ascii_glyphs;
d->glyph_count = sizeof(ascii_glyphs) / sizeof(*ascii_glyphs);

/* Default dithering mode */
bitmap->init_dither = init_fstein_dither;
bitmap->get_dither = get_fstein_dither;
bitmap->increment_dither = increment_fstein_dither;
d->init_dither = init_fstein_dither;
d->get_dither = get_fstein_dither;
d->increment_dither = increment_fstein_dither;

return bitmap;
return d;
}

/**
* \brief Set the palette of an 8bpp bitmap object.
* \brief Set the palette of an 8bpp dither object.
*
* Set the palette of an 8 bits per pixel bitmap. Values should be between
* 0 and 4095 (0xfff).
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \param red Array of 256 red values.
* \param green Array of 256 green values.
* \param blue Array of 256 blue values.
* \param alpha Array of 256 alpha values.
*/
void cucul_set_bitmap_palette(struct cucul_bitmap *bitmap,
void cucul_set_dither_palette(struct cucul_dither *d,
unsigned int red[], unsigned int green[],
unsigned int blue[], unsigned int alpha[])
{
int i, has_alpha = 0;

if(bitmap->bpp != 8)
if(d->bpp != 8)
return;

for(i = 0; i < 256; i++)
@@ -350,42 +350,42 @@ void cucul_set_bitmap_palette(struct cucul_bitmap *bitmap,
blue[i] >= 0 && blue[i] < 0x1000 &&
alpha[i] >= 0 && alpha[i] < 0x1000)
{
bitmap->red[i] = red[i];
bitmap->green[i] = green[i];
bitmap->blue[i] = blue[i];
d->red[i] = red[i];
d->green[i] = green[i];
d->blue[i] = blue[i];
if(alpha[i])
{
bitmap->alpha[i] = alpha[i];
d->alpha[i] = alpha[i];
has_alpha = 1;
}
}
}

bitmap->has_alpha = has_alpha;
d->has_alpha = has_alpha;
}

/**
* \brief Set the brightness of a bitmap object.
* \brief Set the brightness of a dither object.
*
* Set the brightness of bitmap.
* Set the brightness of dither.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \param brightness brightness value.
*/
void cucul_set_bitmap_brightness(struct cucul_bitmap *bitmap, float brightness)
void cucul_set_dither_brightness(struct cucul_dither *d, float brightness)
{
/* FIXME */
}

/**
* \brief Set the gamma of a bitmap object.
* \brief Set the gamma of a dither object.
*
* Set the gamma of bitmap.
* Set the gamma of dither.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \param gamma Gamma value.
*/
void cucul_set_bitmap_gamma(struct cucul_bitmap *bitmap, float gamma)
void cucul_set_dither_gamma(struct cucul_dither *d, float gamma)
{
/* FIXME: we don't need 4096 calls to gammapow(), we can just compute
* 128 of them and do linear interpolation for the rest. This will
@@ -395,42 +395,42 @@ void cucul_set_bitmap_gamma(struct cucul_bitmap *bitmap, float gamma)
if(gamma <= 0.0)
return;

bitmap->gamma = gamma;
d->gamma = gamma;

for(i = 0; i < 4096; i++)
bitmap->gammatab[i] = 4096.0 * gammapow((float)i / 4096.0, 1.0 / gamma);
d->gammatab[i] = 4096.0 * gammapow((float)i / 4096.0, 1.0 / gamma);
}

/**
* \brief Invert colors of bitmap
* \brief Invert colors of dither
*
* Invert colors of bitmap
* Invert colors of dither
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \param value 0 for normal behaviour, 1 for invert
*/
void cucul_set_bitmap_invert(struct cucul_bitmap *bitmap, int value)
void cucul_set_dither_invert(struct cucul_dither *d, int value)
{
bitmap->invert = value ? 1 : 0;
d->invert = value ? 1 : 0;
}

/**
* \brief Set the contrast of a bitmap object.
* \brief Set the contrast of a dither object.
*
* Set the contrast of bitmap.
* Set the contrast of dither.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \param contrast contrast value.
*/
void cucul_set_bitmap_contrast(struct cucul_bitmap *bitmap, float contrast)
void cucul_set_dither_contrast(struct cucul_dither *d, float contrast)
{
/* FIXME */
}

/**
* \brief Set bitmap antialiasing
* \brief Set dither antialiasing
*
* Tell the renderer whether to antialias the bitmap. Antialiasing smoothen
* Tell the renderer whether to antialias the dither. Antialiasing smoothen
* the rendered image and avoids the commonly seen staircase effect.
*
* \li \e "none": no antialiasing.
@@ -438,32 +438,32 @@ void cucul_set_bitmap_contrast(struct cucul_bitmap *bitmap, float contrast)
* \li \e "prefilter": simple prefilter antialiasing. This is the default
* value.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \param str A string describing the antialiasing method that will be used
* for the bitmap rendering.
* for the dithering.
*/
void cucul_set_bitmap_antialias(struct cucul_bitmap *bitmap, char const *str)
void cucul_set_dither_antialias(struct cucul_dither *d, char const *str)
{
if(!strcasecmp(str, "none"))
bitmap->antialias = 0;
d->antialias = 0;
else /* "prefilter" is the default */
bitmap->antialias = 1;
d->antialias = 1;
}

/**
* \brief Get available antialiasing methods
*
* Return a list of available antialiasing methods for a given bitmap. The
* Return a list of available antialiasing methods for a given dither. The
* list is a NULL-terminated array of strings, interleaving a string
* containing the internal value for the antialiasing method to be used with
* \e cucul_set_bitmap_antialias(), and a string containing the natural
* \e cucul_set_dither_antialias(), and a string containing the natural
* language description for that antialiasing method.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \return An array of strings.
*/
char const * const *
cucul_get_bitmap_antialias_list(struct cucul_bitmap const *bitmap)
cucul_get_dither_antialias_list(struct cucul_dither const *d)
{
static char const * const list[] =
{
@@ -476,7 +476,7 @@ char const * const *
}

/**
* \brief Choose colours used for bitmap rendering
* \brief Choose colours used for dithering
*
* Tell the renderer which colours should be used to render the
* bitmap. Valid values for \e str are:
@@ -498,42 +498,42 @@ char const * const *
* \li \e "full16": use the 16 ANSI colours for both the characters and the
* background. This is the default value.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \param str A string describing the colour set that will be used
* for the bitmap rendering.
* for the dithering.
*/
void cucul_set_bitmap_color(struct cucul_bitmap *bitmap, char const *str)
void cucul_set_dither_color(struct cucul_dither *d, char const *str)
{
if(!strcasecmp(str, "mono"))
bitmap->color_mode = COLOR_MODE_MONO;
d->color_mode = COLOR_MODE_MONO;
else if(!strcasecmp(str, "gray"))
bitmap->color_mode = COLOR_MODE_GRAY;
d->color_mode = COLOR_MODE_GRAY;
else if(!strcasecmp(str, "8"))
bitmap->color_mode = COLOR_MODE_8;
d->color_mode = COLOR_MODE_8;
else if(!strcasecmp(str, "16"))
bitmap->color_mode = COLOR_MODE_16;
d->color_mode = COLOR_MODE_16;
else if(!strcasecmp(str, "fullgray"))
bitmap->color_mode = COLOR_MODE_FULLGRAY;
d->color_mode = COLOR_MODE_FULLGRAY;
else if(!strcasecmp(str, "full8"))
bitmap->color_mode = COLOR_MODE_FULL8;
d->color_mode = COLOR_MODE_FULL8;
else /* "full16" is the default */
bitmap->color_mode = COLOR_MODE_FULL16;
d->color_mode = COLOR_MODE_FULL16;
}

/**
* \brief Get available colour modes
*
* Return a list of available colour modes for a given bitmap. The list
* Return a list of available colour modes for a given dither. The list
* is a NULL-terminated array of strings, interleaving a string containing
* the internal value for the colour mode, to be used with
* \e cucul_set_bitmap_color(), and a string containing the natural
* \e cucul_set_dither_color(), and a string containing the natural
* language description for that colour mode.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \return An array of strings.
*/
char const * const *
cucul_get_bitmap_color_list(struct cucul_bitmap const *bitmap)
cucul_get_dither_color_list(struct cucul_dither const *d)
{
static char const * const list[] =
{
@@ -551,10 +551,10 @@ char const * const *
}

/**
* \brief Choose characters used for bitmap rendering
* \brief Choose characters used for dithering
*
* Tell the renderer which characters should be used to render the
* bitmap. Valid values for \e str are:
* dither. Valid values for \e str are:
*
* \li \e "ascii": use only ASCII characters. This is the default value.
*
@@ -565,43 +565,43 @@ char const * const *
* \li \e "blocks": use Unicode quarter-cell block combinations. These
* characters are only found in the Unicode set.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \param str A string describing the characters that need to be used
* for the bitmap rendering.
* for the dithering.
*/
void cucul_set_bitmap_charset(struct cucul_bitmap *bitmap, char const *str)
void cucul_set_dither_charset(struct cucul_dither *d, char const *str)
{
if(!strcasecmp(str, "shades"))
{
bitmap->glyphs = shades_glyphs;
bitmap->glyph_count = sizeof(shades_glyphs) / sizeof(*shades_glyphs);
d->glyphs = shades_glyphs;
d->glyph_count = sizeof(shades_glyphs) / sizeof(*shades_glyphs);
}
else if(!strcasecmp(str, "blocks"))
{
bitmap->glyphs = blocks_glyphs;
bitmap->glyph_count = sizeof(blocks_glyphs) / sizeof(*blocks_glyphs);
d->glyphs = blocks_glyphs;
d->glyph_count = sizeof(blocks_glyphs) / sizeof(*blocks_glyphs);
}
else /* "ascii" is the default */
{
bitmap->glyphs = ascii_glyphs;
bitmap->glyph_count = sizeof(ascii_glyphs) / sizeof(*ascii_glyphs);
d->glyphs = ascii_glyphs;
d->glyph_count = sizeof(ascii_glyphs) / sizeof(*ascii_glyphs);
}
}

/**
* \brief Get available bitmap character sets
* \brief Get available dither character sets
*
* Return a list of available character sets for a given bitmap. The list
* Return a list of available character sets for a given dither. The list
* is a NULL-terminated array of strings, interleaving a string containing
* the internal value for the character set, to be used with
* \e cucul_set_bitmap_charset(), and a string containing the natural
* \e cucul_set_dither_charset(), and a string containing the natural
* language description for that character set.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \return An array of strings.
*/
char const * const *
cucul_get_bitmap_charset_list(struct cucul_bitmap const *bitmap)
cucul_get_dither_charset_list(struct cucul_dither const *d)
{
static char const * const list[] =
{
@@ -615,12 +615,11 @@ char const * const *
}

/**
* \brief Set bitmap dithering method
* \brief Set dithering method
*
* Tell the renderer which dithering method should be used to render the
* bitmap. Dithering is necessary because the picture being rendered has
* usually far more colours than the available palette. Valid values for
* \e str are:
* Tell the renderer which dithering method should be used. Dithering is
* necessary because the picture being rendered has usually far more colours
* than the available palette. Valid values for \e str are:
*
* \li \e "none": no dithering is used, the nearest matching colour is used.
*
@@ -634,64 +633,64 @@ char const * const *
*
* \li \e "fstein": use Floyd-Steinberg dithering. This is the default value.
*
* \param bitmap Bitmap object.
* \param str A string describing the dithering method that needs to be used
* for the bitmap rendering.
* \param dither Dither object.
* \param str A string describing the method that needs to be used
* for the dithering.
*/
void cucul_set_bitmap_dithering(struct cucul_bitmap *bitmap, char const *str)
void cucul_set_dither_mode(struct cucul_dither *d, char const *str)
{
if(!strcasecmp(str, "none"))
{
bitmap->init_dither = init_no_dither;
bitmap->get_dither = get_no_dither;
bitmap->increment_dither = increment_no_dither;
d->init_dither = init_no_dither;
d->get_dither = get_no_dither;
d->increment_dither = increment_no_dither;
}
else if(!strcasecmp(str, "ordered2"))
{
bitmap->init_dither = init_ordered2_dither;
bitmap->get_dither = get_ordered2_dither;
bitmap->increment_dither = increment_ordered2_dither;
d->init_dither = init_ordered2_dither;
d->get_dither = get_ordered2_dither;
d->increment_dither = increment_ordered2_dither;
}
else if(!strcasecmp(str, "ordered4"))
{
bitmap->init_dither = init_ordered4_dither;
bitmap->get_dither = get_ordered4_dither;
bitmap->increment_dither = increment_ordered4_dither;
d->init_dither = init_ordered4_dither;
d->get_dither = get_ordered4_dither;
d->increment_dither = increment_ordered4_dither;
}
else if(!strcasecmp(str, "ordered4"))
{
bitmap->init_dither = init_ordered8_dither;
bitmap->get_dither = get_ordered8_dither;
bitmap->increment_dither = increment_ordered8_dither;
d->init_dither = init_ordered8_dither;
d->get_dither = get_ordered8_dither;
d->increment_dither = increment_ordered8_dither;
}
else if(!strcasecmp(str, "random"))
{
bitmap->init_dither = init_random_dither;
bitmap->get_dither = get_random_dither;
bitmap->increment_dither = increment_random_dither;
d->init_dither = init_random_dither;
d->get_dither = get_random_dither;
d->increment_dither = increment_random_dither;
}
else /* "fstein" is the default */
{
bitmap->init_dither = init_fstein_dither;
bitmap->get_dither = get_fstein_dither;
bitmap->increment_dither = increment_fstein_dither;
d->init_dither = init_fstein_dither;
d->get_dither = get_fstein_dither;
d->increment_dither = increment_fstein_dither;
}
}

/**
* \brief Get bitmap dithering methods
* \brief Get dithering methods
*
* Return a list of available dithering methods for a given bitmap. The list
* Return a list of available dithering methods for a given dither. The list
* is a NULL-terminated array of strings, interleaving a string containing
* the internal value for the dithering method, to be used with
* \e cucul_set_bitmap_dithering(), and a string containing the natural
* \e cucul_set_dither_dithering(), and a string containing the natural
* language description for that dithering method.
*
* \param bitmap Bitmap object.
* \param dither Dither object.
* \return An array of strings.
*/
char const * const *
cucul_get_bitmap_dithering_list(struct cucul_bitmap const *bitmap)
cucul_get_dither_mode_list(struct cucul_dither const *d)
{
static char const * const list[] =
{
@@ -708,32 +707,32 @@ char const * const *
}

/**
* \brief Draw a bitmap on the screen.
* \brief Draw a dither on the screen.
*
* Draw a bitmap at the given coordinates. The bitmap can be of any size and
* Draw a dither at the given coordinates. The dither can be of any size and
* will be stretched to the text area.
*
* \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 bitmap Bitmap object to be drawn.
* \param dither Dither object to be drawn.
* \param pixels Bitmap's pixels.
*/
void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
struct cucul_bitmap const *bitmap, void *pixels)
void cucul_dither_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
struct cucul_dither const *d, void *pixels)
{
int *floyd_steinberg, *fs_r, *fs_g, *fs_b;
int fs_length;
int x, y, w, h, pitch, deltax, deltay;
unsigned int dchmax;

if(!bitmap || !pixels)
if(!d || !pixels)
return;

w = bitmap->w;
h = bitmap->h;
pitch = bitmap->pitch;
w = d->w;
h = d->h;
pitch = d->pitch;

if(x1 > x2)
{
@@ -747,7 +746,7 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,

deltax = x2 - x1 + 1;
deltay = y2 - y1 + 1;
dchmax = bitmap->glyph_count;
dchmax = d->glyph_count;

fs_length = ((int)qq->width <= x2 ? (int)qq->width : x2) + 1;
floyd_steinberg = malloc(3 * (fs_length + 2) * sizeof(int));
@@ -760,7 +759,7 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
{
int remain_r = 0, remain_g = 0, remain_b = 0;

for(x = x1 > 0 ? x1 : 0, bitmap->init_dither(y);
for(x = x1 > 0 ? x1 : 0, d->init_dither(y);
x <= x2 && x <= (int)qq->width;
x++)
{
@@ -777,7 +776,7 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
rgba[0] = rgba[1] = rgba[2] = rgba[3] = 0;

/* First get RGB */
if(bitmap->antialias)
if(d->antialias)
{
fromx = (x - x1) * w / deltax;
fromy = (y - y1) * h / deltay;
@@ -794,7 +793,7 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
for(myy = fromy; myy < toy; myy++)
{
dots++;
get_rgba_default(bitmap, pixels, myx, myy, rgba);
get_rgba_default(d, pixels, myx, myy, rgba);
}

/* Normalize */
@@ -816,10 +815,10 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
myx = (fromx + tox) / 2;
myy = (fromy + toy) / 2;

get_rgba_default(bitmap, pixels, myx, myy, rgba);
get_rgba_default(d, pixels, myx, myy, rgba);
}

if(bitmap->has_alpha && rgba[3] < 0x800)
if(d->has_alpha && rgba[3] < 0x800)
{
remain_r = remain_g = remain_b = 0;
fs_r[x] = 0;
@@ -829,7 +828,7 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
}

/* XXX: OMG HAX */
if(bitmap->init_dither == init_fstein_dither)
if(d->init_dither == init_fstein_dither)
{
rgba[0] += remain_r;
rgba[1] += remain_g;
@@ -837,9 +836,9 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
}
else
{
rgba[0] += (bitmap->get_dither() - 0x80) * 4;
rgba[1] += (bitmap->get_dither() - 0x80) * 4;
rgba[2] += (bitmap->get_dither() - 0x80) * 4;
rgba[0] += (d->get_dither() - 0x80) * 4;
rgba[1] += (d->get_dither() - 0x80) * 4;
rgba[2] += (d->get_dither() - 0x80) * 4;
}

distmin = INT_MAX;
@@ -860,7 +859,7 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
bg_b = rgb_palette[outbg * 3 + 2];

/* FIXME: we currently only honour "full16" */
if(bitmap->color_mode == COLOR_MODE_FULL16)
if(d->color_mode == COLOR_MODE_FULL16)
{
distmin = INT_MAX;
for(i = 0; i < 16; i++)
@@ -897,10 +896,10 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
distmin = dist;
}
}
outch = bitmap->glyphs[ch];
outch = d->glyphs[ch];

/* XXX: OMG HAX */
if(bitmap->init_dither == init_fstein_dither)
if(d->init_dither == init_fstein_dither)
{
error[0] = rgba[0] - (fg_r * ch + bg_r * ((2*dchmax-1) - ch)) / (2*dchmax-1);
error[1] = rgba[1] - (fg_g * ch + bg_g * ((2*dchmax-1) - ch)) / (2*dchmax-1);
@@ -920,10 +919,10 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
ch = 0;
else if(ch > (int)(dchmax - 1))
ch = dchmax - 1;
outch = bitmap->glyphs[ch];
outch = d->glyphs[ch];

/* XXX: OMG HAX */
if(bitmap->init_dither == init_fstein_dither)
if(d->init_dither == init_fstein_dither)
{
error[0] = rgba[0] - bg_r * ch / (dchmax-1);
error[1] = rgba[1] - bg_g * ch / (dchmax-1);
@@ -932,7 +931,7 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
}

/* XXX: OMG HAX */
if(bitmap->init_dither == init_fstein_dither)
if(d->init_dither == init_fstein_dither)
{
remain_r = fs_r[x+1] + 7 * error[0] / 16;
remain_g = fs_g[x+1] + 7 * error[1] / 16;
@@ -948,7 +947,7 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
fs_b[x+1] = 1 * error[2] / 16;
}

if(bitmap->invert)
if(d->invert)
{
outfg = 15 - outfg;
outbg = 15 - outbg;
@@ -958,7 +957,7 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
cucul_set_color(qq, outfg, outbg);
cucul_putstr(qq, x, y, outch);

bitmap->increment_dither();
d->increment_dither();
}
/* end loop */
}
@@ -967,18 +966,18 @@ void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
}

/**
* \brief Free the memory associated with a bitmap.
* \brief Free the memory associated with a dither.
*
* Free the memory allocated by cucul_create_bitmap().
* Free the memory allocated by cucul_create_dither().
*
* \param bitmap Bitmap object.
* \param dither Dither object.
*/
void cucul_free_bitmap(struct cucul_bitmap *bitmap)
void cucul_free_dither(struct cucul_dither *d)
{
if(!bitmap)
if(!d)
return;

free(bitmap);
free(d);
}

/*
@@ -1074,14 +1073,14 @@ static float gammapow(float x, float y)
#endif
}

static void get_rgba_default(struct cucul_bitmap const *bitmap, uint8_t *pixels,
static void get_rgba_default(struct cucul_dither const *d, uint8_t *pixels,
int x, int y, unsigned int *rgba)
{
uint32_t bits;

pixels += (bitmap->bpp / 8) * x + bitmap->pitch * y;
pixels += (d->bpp / 8) * x + d->pitch * y;

switch(bitmap->bpp / 8)
switch(d->bpp / 8)
{
case 4:
bits = *(uint32_t *)pixels;
@@ -1113,19 +1112,19 @@ static void get_rgba_default(struct cucul_bitmap const *bitmap, uint8_t *pixels,
break;
}

if(bitmap->has_palette)
if(d->has_palette)
{
rgba[0] += bitmap->gammatab[bitmap->red[bits]];
rgba[1] += bitmap->gammatab[bitmap->green[bits]];
rgba[2] += bitmap->gammatab[bitmap->blue[bits]];
rgba[3] += bitmap->alpha[bits];
rgba[0] += d->gammatab[d->red[bits]];
rgba[1] += d->gammatab[d->green[bits]];
rgba[2] += d->gammatab[d->blue[bits]];
rgba[3] += d->alpha[bits];
}
else
{
rgba[0] += bitmap->gammatab[((bits & bitmap->rmask) >> bitmap->rright) << bitmap->rleft];
rgba[1] += bitmap->gammatab[((bits & bitmap->gmask) >> bitmap->gright) << bitmap->gleft];
rgba[2] += bitmap->gammatab[((bits & bitmap->bmask) >> bitmap->bright) << bitmap->bleft];
rgba[3] += ((bits & bitmap->amask) >> bitmap->aright) << bitmap->aleft;
rgba[0] += d->gammatab[((bits & d->rmask) >> d->rright) << d->rleft];
rgba[1] += d->gammatab[((bits & d->gmask) >> d->gright) << d->gleft];
rgba[2] += d->gammatab[((bits & d->bmask) >> d->bright) << d->bleft];
rgba[3] += ((bits & d->amask) >> d->aright) << d->aleft;
}
}

@@ -1280,7 +1279,7 @@ static void increment_random_dither(void)
}

#if !defined(_DOXYGEN_SKIP_ME)
int _cucul_init_bitmap(void)
int _cucul_init_dither(void)
{
unsigned int v, s, h;

@@ -1338,7 +1337,7 @@ int _cucul_init_bitmap(void)
return 0;
}

int _cucul_end_bitmap(void)
int _cucul_end_dither(void)
{
return 0;
}


+ 2
- 2
cucul/cucul.c Прегледај датотеку

@@ -65,7 +65,7 @@ cucul_t * cucul_create(unsigned int width, unsigned int height)
else
_cucul_set_size(qq, 80, 32);

if(_cucul_init_bitmap())
if(_cucul_init_dither())
{
free(qq);
return NULL;
@@ -213,7 +213,7 @@ char const *cucul_get_color_name(unsigned int color)
*/
void cucul_free(cucul_t *qq)
{
_cucul_end_bitmap();
_cucul_end_dither();

free(qq->empty_line);
free(qq->scratch_line);


+ 20
- 22
cucul/cucul.h Прегледај датотеку

@@ -146,37 +146,35 @@ void cucul_draw_sprite(cucul_t *, int, int, struct cucul_sprite const *, int);
void cucul_free_sprite(struct cucul_sprite *);
/* @} */

/** \defgroup bitmap Bitmap handling
/** \defgroup dither Bitmap dithering
*
* These functions provide high level routines for bitmap allocation and
* These functions provide high level routines for dither allocation and
* rendering.
*
* @{ */
struct cucul_bitmap;
struct cucul_bitmap *cucul_create_bitmap(unsigned int, unsigned int,
struct cucul_dither;
struct cucul_dither *cucul_create_dither(unsigned int, unsigned int,
unsigned int, unsigned int,
unsigned int, unsigned int,
unsigned int, unsigned int);
void cucul_set_bitmap_palette(struct cucul_bitmap *,
void cucul_set_dither_palette(struct cucul_dither *,
unsigned int r[], unsigned int g[],
unsigned int b[], unsigned int a[]);
void cucul_set_bitmap_brightness(struct cucul_bitmap *, float);
void cucul_set_bitmap_gamma(struct cucul_bitmap *, float);
void cucul_set_bitmap_contrast(struct cucul_bitmap *, float);
void cucul_set_bitmap_invert(struct cucul_bitmap *, int);
void cucul_set_bitmap_antialias(struct cucul_bitmap *, char const *);
char const * const * cucul_get_bitmap_antialias_list(struct cucul_bitmap const *);
void cucul_set_bitmap_color(struct cucul_bitmap *, char const *);
char const * const * cucul_get_bitmap_color_list(struct cucul_bitmap const *);
void cucul_set_bitmap_charset(struct cucul_bitmap *, char const *);
char const * const * cucul_get_bitmap_charset_list(struct cucul_bitmap
const *);
void cucul_set_bitmap_dithering(struct cucul_bitmap *, char const *);
char const * const * cucul_get_bitmap_dithering_list(struct cucul_bitmap
const *);
void cucul_draw_bitmap(cucul_t *, int, int, int, int,
struct cucul_bitmap const *, void *);
void cucul_free_bitmap(struct cucul_bitmap *);
void cucul_set_dither_brightness(struct cucul_dither *, float);
void cucul_set_dither_gamma(struct cucul_dither *, float);
void cucul_set_dither_contrast(struct cucul_dither *, float);
void cucul_set_dither_invert(struct cucul_dither *, int);
void cucul_set_dither_antialias(struct cucul_dither *, char const *);
char const * const * cucul_get_dither_antialias_list(struct cucul_dither const *);
void cucul_set_dither_color(struct cucul_dither *, char const *);
char const * const * cucul_get_dither_color_list(struct cucul_dither const *);
void cucul_set_dither_charset(struct cucul_dither *, char const *);
char const * const * cucul_get_dither_charset_list(struct cucul_dither const *);
void cucul_set_dither_mode(struct cucul_dither *, char const *);
char const * const * cucul_get_dither_mode_list(struct cucul_dither const *);
void cucul_dither_bitmap(cucul_t *, int, int, int, int,
struct cucul_dither const *, void *);
void cucul_free_dither(struct cucul_dither *);
/* @} */

/** \defgroup exporter Exporters to various formats


+ 2
- 2
cucul/cucul_internals.h Прегледај датотеку

@@ -47,8 +47,8 @@ struct cucul_context
};

/* Bitmap functions */
extern int _cucul_init_bitmap(void);
extern int _cucul_end_bitmap(void);
extern int _cucul_init_dither(void);
extern int _cucul_end_dither(void);

/* Canvas functions */
extern void _cucul_set_size(cucul_t *, unsigned int, unsigned int);


+ 6
- 6
src/aafire.c Прегледај датотеку

@@ -42,7 +42,7 @@
static cucul_t *qq;
static caca_t *kk;
static int XSIZ, YSIZ;
static struct cucul_bitmap *cucul_bitmap;
static struct cucul_dither *cucul_dither;
static char *bitmap;
static int pause = 0;
#else
@@ -140,8 +140,8 @@ initialize (void)
#endif

#ifdef LIBCACA
cucul_bitmap = cucul_create_bitmap(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0);
cucul_set_bitmap_palette(cucul_bitmap, r, g, b, a);
cucul_dither = cucul_create_dither(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0);
cucul_set_dither_palette(cucul_dither, r, g, b, a);
bitmap = malloc(4 * cucul_get_width(qq) * cucul_get_height(qq) * sizeof(char));
memset(bitmap, 0, 4 * cucul_get_width(qq) * cucul_get_height(qq));
#else
@@ -235,9 +235,9 @@ drawfire (void)
firemain ();
#ifdef LIBCACA
paused:
cucul_draw_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
cucul_bitmap, bitmap);
cucul_dither_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
cucul_dither, bitmap);
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(qq, cucul_get_width(qq) - 30, cucul_get_height(qq) - 2,
" -=[ Powered by libcaca ]=- ");


+ 7
- 7
src/cacaball.c Прегледај датотеку

@@ -46,7 +46,7 @@ int main(int argc, char **argv)
unsigned int r[256], g[256], b[256], a[256];
float d[METABALLS], di[METABALLS], dj[METABALLS], dk[METABALLS];
unsigned int x[METABALLS], y[METABALLS];
struct cucul_bitmap *cucul_bitmap;
struct cucul_dither *cucul_dither;
float i = 10.0, j = 17.0, k = 11.0;
int p, frame = 0, pause = 0;
double frameOffset[360 + 80];
@@ -67,9 +67,9 @@ int main(int argc, char **argv)
r[p] = g[p] = b[p] = a[p] = 0x0;
r[255] = g[255] = b[255] = 0xfff;

/* Create a libcucul bitmap smaller than our pixel buffer, so that we
/* Create a libcucul dither smaller than our pixel buffer, so that we
* display only the interesting part of it */
cucul_bitmap = cucul_create_bitmap(8, XSIZ - METASIZE, YSIZ - METASIZE,
cucul_dither = cucul_create_dither(8, XSIZ - METASIZE, YSIZ - METASIZE,
XSIZ, 0, 0, 0, 0);

/* Generate ball sprite */
@@ -127,7 +127,7 @@ int main(int argc, char **argv)
}

/* Set the palette */
cucul_set_bitmap_palette(cucul_bitmap, r, g, b, a);
cucul_set_dither_palette(cucul_dither, r, g, b, a);

/* Silly paths for our balls */
for(p = 0; p < METABALLS; p++)
@@ -153,9 +153,9 @@ int main(int argc, char **argv)

paused:
/* Draw our virtual buffer to screen, letting libcucul resize it */
cucul_draw_bitmap(qq, 0, 0,
cucul_dither_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
cucul_bitmap, pixels + (METASIZE / 2) * (1 + XSIZ));
cucul_dither, pixels + (METASIZE / 2) * (1 + XSIZ));
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(qq, cucul_get_width(qq) - 30, cucul_get_height(qq) - 2,
" -=[ Powered by libcaca ]=- ");
@@ -165,7 +165,7 @@ paused:

/* End, bye folks */
end:
cucul_free_bitmap(cucul_bitmap);
cucul_free_dither(cucul_dither);
caca_detach(kk);
cucul_free(qq);



+ 8
- 8
src/cacamoir.c Прегледај датотеку

@@ -39,7 +39,7 @@ int main (int argc, char **argv)
{
cucul_t *qq; caca_t *kk;
unsigned int red[256], green[256], blue[256], alpha[256];
struct cucul_bitmap *bitmap;
struct cucul_dither *dither;
int i, x, y, frame = 0, pause = 0;

qq = cucul_create(0, 0);
@@ -62,8 +62,8 @@ int main (int argc, char **argv)
for(i = DISCSIZ * 2; i > 0; i -= DISCTHICKNESS)
draw_disc(i, (i / DISCTHICKNESS) % 2);

/* Create a libcucul bitmap */
bitmap = cucul_create_bitmap(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
/* Create a libcucul dither */
dither = cucul_create_dither(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);

/* Main loop */
for(;;)
@@ -92,7 +92,7 @@ int main (int argc, char **argv)
green[1] = 0.5 * (1 + cos(0.06 * frame + 5.0)) * 0xfff;
blue[1] = 0.5 * (1 + cos(0.05 * frame + 5.0)) * 0xfff;

cucul_set_bitmap_palette(bitmap, red, green, blue, alpha);
cucul_set_dither_palette(dither, red, green, blue, alpha);

/* Draw circles */
x = cos(0.07 * frame + 5.0) * 128.0 + (XSIZ / 2);
@@ -106,9 +106,9 @@ int main (int argc, char **argv)
frame++;

paused:
cucul_draw_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
bitmap, screen);
cucul_dither_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
dither, screen);
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(qq, cucul_get_width(qq) - 30, cucul_get_height(qq) - 2,
" -=[ Powered by libcaca ]=- ");
@@ -116,7 +116,7 @@ paused:
}

end:
cucul_free_bitmap(bitmap);
cucul_free_dither(dither);
caca_detach(kk);
cucul_free(qq);



+ 8
- 8
src/cacaplas.c Прегледај датотеку

@@ -43,7 +43,7 @@ int main (int argc, char **argv)
cucul_t *qq, *qq2, *mask; caca_t *kk;
unsigned int red[256], green[256], blue[256], alpha[256];
double r[3], R[6];
struct cucul_bitmap *bitmap;
struct cucul_dither *dither;
int i, x, y, frame = 0, pause = 0;

qq = cucul_create(0, 0);
@@ -78,8 +78,8 @@ int main (int argc, char **argv)
table[x + y * TABLEX] = (1.0 + sin(12.0 * sqrt(tmp))) * 256 / 6;
}

/* Create a libcucul bitmap */
bitmap = cucul_create_bitmap(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
/* Create a libcucul dither */
dither = cucul_create_dither(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);

/* Main loop */
for(;;)
@@ -107,7 +107,7 @@ int main (int argc, char **argv)
}

/* Set the palette */
cucul_set_bitmap_palette(bitmap, red, green, blue, alpha);
cucul_set_dither_palette(dither, red, green, blue, alpha);

do_plasma(screen,
(1.0 + sin(((double)frame) * R[0])) / 2,
@@ -119,9 +119,9 @@ int main (int argc, char **argv)
frame++;

paused:
cucul_draw_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
bitmap, screen);
cucul_dither_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
dither, screen);

cucul_blit(qq2, 0, 0, qq, NULL);
cucul_invert(qq2);
@@ -136,7 +136,7 @@ paused:
}

end:
cucul_free_bitmap(bitmap);
cucul_free_dither(dither);
caca_detach(kk);
cucul_free(qq);



+ 15
- 15
src/cacaview.c Прегледај датотеку

@@ -67,7 +67,7 @@ static int freadchar(FILE *);
Imlib_Image image = NULL;
#endif
char *pixels = NULL;
struct cucul_bitmap *bitmap = NULL;
struct cucul_dither *dither = NULL;
unsigned int w, h, depth, bpp, rmask, gmask, bmask, amask;
#if !defined(HAVE_IMLIB2_H)
unsigned int red[256], green[256], blue[256], alpha[256];
@@ -382,11 +382,11 @@ int main(int argc, char **argv)
ww * (1.0 + xfactor) / 2,
y + height * (1.0 + yfactor) / 2);

cucul_draw_bitmap(qq, ww * (1.0 - xfactor) * xdelta,
cucul_dither_bitmap(qq, ww * (1.0 - xfactor) * xdelta,
y + height * (1.0 - yfactor) * ydelta,
ww * (xdelta + (1.0 - xdelta) * xfactor),
y + height * (ydelta + (1.0 - ydelta) * yfactor),
bitmap, pixels);
dither, pixels);
}

if(!fullscreen)
@@ -506,7 +506,7 @@ static void set_gamma(int new_gamma)
if(g > GAMMA_MAX) g = GAMMA_MAX;
if(g < -GAMMA_MAX) g = -GAMMA_MAX;

cucul_set_bitmap_gamma(bitmap, (g < 0) ? 1.0 / gammatab[-g] : gammatab[g]);
cucul_set_dither_gamma(dither, (g < 0) ? 1.0 / gammatab[-g] : gammatab[g]);
}

static void unload_image(void)
@@ -521,9 +521,9 @@ static void unload_image(void)
free(pixels);
pixels = NULL;
#endif
if(bitmap)
cucul_free_bitmap(bitmap);
bitmap = NULL;
if(dither)
cucul_free_dither(dither);
dither = NULL;
}

static void load_image(char const *name)
@@ -546,10 +546,10 @@ static void load_image(char const *name)
bpp = 32;
depth = 4;

/* Create the libcucul bitmap */
bitmap = cucul_create_bitmap(bpp, w, h, depth * w,
/* Create the libcucul dither */
dither = cucul_create_dither(bpp, w, h, depth * w,
rmask, gmask, bmask, amask);
if(!bitmap)
if(!dither)
{
imlib_free_image();
image = NULL;
@@ -652,7 +652,7 @@ static void load_image(char const *name)

memset(pixels, 0, w * h * depth);

/* Read the bitmap data */
/* Read the dither data */
for(i = h; i--; )
{
unsigned int j, k, bits = 0;
@@ -714,10 +714,10 @@ static void load_image(char const *name)

fclose(fp);

/* Create the libcucul bitmap */
bitmap = cucul_create_bitmap(bpp, w, h, depth * w,
/* Create the libcucul dither */
dither = cucul_create_dither(bpp, w, h, depth * w,
rmask, gmask, bmask, amask);
if(!bitmap)
if(!dither)
{
free(pixels);
pixels = NULL;
@@ -725,7 +725,7 @@ static void load_image(char const *name)
}

if(bpp == 8)
cucul_set_bitmap_palette(bitmap, red, green, blue, alpha);
cucul_set_dither_palette(dither, red, green, blue, alpha);
#endif
}



+ 12
- 12
test/demo.c Прегледај датотеку

@@ -483,7 +483,7 @@ static void demo_sprites(void)
#if 0
static void demo_render(void)
{
struct cucul_bitmap *bitmap;
struct cucul_dither *dither;
//short buffer[256*256];
//short *dest = buffer;
int buffer[256*256];
@@ -500,12 +500,12 @@ static void demo_render(void)
//*dest++ = ((x >> 3) << 11) | ((y >> 2) << 5) | ((z >> 3));
*dest++ = (x << 16) | (y << 8) | (z);
}
cucul_set_bitmap_invert(bitmap, 1);
//bitmap = cucul_create_bitmap(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000);
bitmap = cucul_create_bitmap(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
cucul_draw_bitmap(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
bitmap, buffer);
cucul_free_bitmap(bitmap);
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(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
dither, buffer);
cucul_free_dither(dither);
}
#endif

@@ -513,7 +513,7 @@ static void draw_circle(int *buffer, int xo, int yo, int r, int mask, int val);

static void demo_render(void)
{
struct cucul_bitmap *bitmap;
struct cucul_dither *dither;
int buffer[256*256];
int *dest;
int x, y, z, xo, yo;
@@ -546,10 +546,10 @@ static void demo_render(void)
for(z = 0; z < 240; z++)
draw_circle(buffer, xo, yo, z, 0x000000ff, 200);

bitmap = cucul_create_bitmap(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
cucul_set_bitmap_invert(bitmap, 1);
cucul_draw_bitmap(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, bitmap, (char *)buffer);
cucul_free_bitmap(bitmap);
dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
cucul_set_dither_invert(dither, 1);
cucul_dither_bitmap(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, dither, (char *)buffer);
cucul_free_dither(dither);
}

static void draw_circle(int *buffer, int x, int y, int r, int mask, int val)


+ 6
- 6
test/export.c Прегледај датотеку

@@ -35,7 +35,7 @@ uint32_t pixels[256*256];
int main(int argc, char *argv[])
{
cucul_t *qq;
struct cucul_bitmap *bitmap;
struct cucul_dither *dither;
struct cucul_export *buffer;
int x, y;

@@ -72,12 +72,12 @@ int main(int argc, char *argv[])
}
}

bitmap = cucul_create_bitmap(32, 256, 256, 4 * 256,
dither = cucul_create_dither(32, 256, 256, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
cucul_draw_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
bitmap, pixels);
cucul_free_bitmap(bitmap);
cucul_dither_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
dither, pixels);
cucul_free_dither(dither);

cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(qq, 0, 0, WIDTH - 1, HEIGHT - 1);


+ 14
- 14
test/gamma.c Прегледај датотеку

@@ -36,7 +36,7 @@ int main(void)
struct caca_event ev;
cucul_t *qq, *gg, *mask;
caca_t *kk;
struct cucul_bitmap *left, *right;
struct cucul_dither *left, *right;
float gam = 1.0;
int x;

@@ -54,9 +54,9 @@ int main(void)
buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0);
}

left = cucul_create_bitmap(32, 256, 4, 4 * 256,
left = cucul_create_dither(32, 256, 4, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
right = cucul_create_bitmap(32, 256, 4, 4 * 256,
right = cucul_create_dither(32, 256, 4, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
caca_set_delay(kk, 20000);

@@ -80,16 +80,16 @@ int main(void)
cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq));
cucul_set_size(mask, cucul_get_width(qq), cucul_get_height(qq));

/* Draw the regular bitmap on the main canvas */
cucul_draw_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
left, buffer);
/* Draw the regular dither on the main canvas */
cucul_dither_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
left, buffer);

/* Draw the gamma-modified bitmap on the spare canvas */
cucul_set_bitmap_gamma(right, gam);
cucul_draw_bitmap(gg, 0, 0,
cucul_get_width(gg) - 1, cucul_get_height(gg) - 1,
right, buffer);
/* Draw the gamma-modified dither on the spare canvas */
cucul_set_dither_gamma(right, gam);
cucul_dither_bitmap(gg, 0, 0,
cucul_get_width(gg) - 1, cucul_get_height(gg) - 1,
right, buffer);

/* Draw something on the mask */
cucul_clear(mask);
@@ -111,8 +111,8 @@ int main(void)
caca_display(kk);
}

cucul_free_bitmap(left);
cucul_free_bitmap(right);
cucul_free_dither(left);
cucul_free_dither(right);

caca_detach(kk);
cucul_free(qq);


+ 6
- 6
test/hsv.c Прегледај датотеку

@@ -32,7 +32,7 @@ int main(void)
cucul_t *qq;
caca_t *kk;

struct cucul_bitmap *bitmap;
struct cucul_dither *dither;
int x, y;

qq = cucul_create(0, 0);
@@ -44,12 +44,12 @@ int main(void)
buffer[y * 256 + x] = ((y * x / 256) << 16) | ((y * x / 256) << 8) | (x<< 0);
}

bitmap = cucul_create_bitmap(32, 256, 256, 4 * 256,
dither = cucul_create_dither(32, 256, 256, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
cucul_draw_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
bitmap, buffer);
cucul_free_bitmap(bitmap);
cucul_dither_bitmap(qq, 0, 0,
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
dither, buffer);
cucul_free_dither(dither);

caca_display(kk);



Loading…
Откажи
Сачувај