Re: clearing a gdk_image through memset



On Fri, 13 Jul 2001 12:06:38 +0000, MC_Vai said:


      Is it posible? (clear an image screen through memset)
      I'm trying this:
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      memset( (void *)oszi_image->mem,
              (int)black_color.pixel,
              sizeof(oszi_image->mem) * (oszi_height * oszi_width) );
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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;
        }

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

I am not sure where you got the black_color.pixel from, this
is a color for GdkPixmap and GdkWindow, not GdkImage.

In the case of 24 bit depth, this is where things get iffy.
You probably know that there really is no 24 bit data type,
some X servers treat 24 bit as 32 bit while others treat 24 bit
as 3 * 8 bit.

So you may need to check if 24 bit should be a bpp of 3 or a
bpp of 4.

Next issue, the pixel format of the GdkImage and the GdkColor
structure have nothing in common, meaning you can't mix the two
togeather.

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

8 bits   rrgg gbbb *or* rrrg ggbb
15 bits  arrr rrgg  gggb bbbb
16 bits  rrrr rrgg  gggb bbbb
24 bits  rrrr rrrr  gggg gggg  bbbb bbbb
32 bits  aaaa aaaa  rrrr rrrr  gggg gggg  bbbb bbbb

It's been a while since I dealt with GdkImage so I'm not 100%
sure about the above bit packing, corrections anyone?



-- 
--
Sincerely,                  ,"-_                         \|/
-Capt. Taura M.             ,   O=__                    --X--
.__                          ,_JNMNNEO=_                 /|\
OMNOUMmnne.                  {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn.               'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe              '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe.                "7OMMMMNNNNNWWEEEEOOOOOO"   "'.
EEBNNMMMNWNWWEEIMMNe.             __  7EMMMNNNNNWWWEEEEEEEOO.     " .
NNMMMMWWWMMMWEINMMMNn            "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._     .
                  http://furry.ao.net/~learfox/






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