Re: clearing a gdk_image through memset



"Tara M" <learfox furry ao net> writes: 
You should clear it like this (assuming image is in ZPixmap format):

void ImageClear(GdkImage *img, guint depth)
{
      guint bpp;      /* Bytes per pixel. */

      switch(depth)
      {
        case 8: bpp = 1; break;
        case 15: bpp = 2; break;
        case 16: bpp = 2; break;
        case 24: bpp = 3; break;      /* Note on this below. */
        case 32: bpp = 4; break;
      }

Just using img->bpp would be easier. ;-)


      memset(img->mem, 0x00, img->width * img->height * bpp);

This is wrong. 0x00 isn't necessarily any particular color. 
img->width is wrong, you want img->bpl (which is the equivalent of
'rowstride' in GdkPixbuf).
 
I am not sure where you got the black_color.pixel from, this
is a color for GdkPixmap and GdkWindow, not GdkImage.

Owen says same difference, except that endianness may differ, and you
need to be careful about how many bits in the pixel are relevant.
 
Next issue, the pixel format of the GdkImage and the GdkColor
structure have nothing in common, meaning you can't mix the two
togeather.

They are related. The pixel field in a GdkColor can be losslessly
converted to/from the pixel format in the image, and they will have
the same number of bits per pixel. You just have to worry about
endianness changing.

The GdkImage has the following if your X server's Visual is set
to TrueColor.

But of course you still have to handle all the non-truecolor
cases. ;-)

GdkImage is super-painful. One does not want to go there unless you
really, really need the speed, or are implementing something like
gdk_pixbuf_get_from_drawable() or GdkRGB. i.e. if you aren't
converting to/from RGB data, you should be using RGB data, not the raw
display format.

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]