Logo Search packages:      
Sourcecode: libcaca version File versions  Download package

struct caca_bitmap* caca_create_bitmap ( unsigned int  bpp,
unsigned int  w,
unsigned int  h,
unsigned int  pitch,
unsigned int  rmask,
unsigned int  gmask,
unsigned int  bmask,
unsigned int  amask 
) [read]

Create an internal bitmap object.

Create a bitmap 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 caca_set_bitmap_palette() function. For depths greater than 8 bits per pixel, a zero alpha mask causes the alpha values to be ignored.

Parameters:
bpp Bitmap depth in bits per pixel.
w Bitmap width in pixels.
h Bitmap height in pixels.
pitch Bitmap pitch in bytes.
rmask Bitmask for red values.
gmask Bitmask for green values.
bmask Bitmask for blue values.
amask Bitmask for alpha values.
Returns:
Bitmap object, or NULL upon error.

Definition at line 189 of file bitmap.c.

{
    struct caca_bitmap *bitmap;

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

    bitmap = malloc(sizeof(struct caca_bitmap));
    if(!bitmap)
        return NULL;

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

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

    bitmap->rmask = rmask;
    bitmap->gmask = gmask;
    bitmap->bmask = bmask;
    bitmap->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);
    }

    /* In 8 bpp mode, default to a grayscale palette */
    if(bpp == 8)
    {
        int i;
        bitmap->has_palette = 1;
        bitmap->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;
        }
    }

    return bitmap;
}


Generated by  Doxygen 1.6.0   Back to index