On Mon, 31 Mar 2003 20:26:47 -0500 (EST) Mark Vojkovich <[EMAIL PROTECTED]>
babbled:

> 
> 
> On Tue, 1 Apr 2003, Carsten Haitzler wrote:
> 
> > On Mon, 31 Mar 2003 17:13:58 -0500 "Josh Davis" <[EMAIL PROTECTED]>
> > babbled:
> > 
> > > I am trying to create an XImage, but after the function call to 
> > > XCreateImage(), my XImage pointer's value is 0.  I really don't know much 
> > > about Xlib.  I want to create an XImage for image data that I already
> > > have.
> > > 
> > > Can someone give me a list of steps to follow that lead to a properly 
> > > created XImage?
> > > 
> > > I am currently getting the WindowAttributes from the root window and
> > > passing its Visual* to the XCreateImage() function, while guessing at some
> > > of the other values.  The image data that I have is for a 24-bit image.  I
> > > assume that I should put the data into a contiguous char array.  Below is
> > > the relevant portion of my code...
> > > --------------------------------------
> > > const int DEPTH = 24;
> > 
> > try DEPTH=32 (24 isn't really allowed)
> 
>    Careful Carsten.  Don't mix up your terminology.  

true... but the pixels will still be padded out to 32bpp in the ximage :)

>  You can create an Ximage in any depth the server supports:
> 
>     depth 1, bits_per_pixel 1, scanline_pad 32
>     depth 4, bits_per_pixel 8, scanline_pad 32
>     depth 8, bits_per_pixel 8, scanline_pad 32
>     depth 15, bits_per_pixel 16, scanline_pad 32
>     depth 16, bits_per_pixel 16, scanline_pad 32
>     depth 24, bits_per_pixel 32, scanline_pad 32
>     depth 32, bits_per_pixel 32, scanline_pad 32
> 
>   The point is that depth != bitsPerPixel.  If you're going
> to Put an XImage into a Window, the depths of the Window and
> XImage must match, and since there aren't any depth 32 Windows,
> he most certainly wants a depth 24 XImage.  But according to
> the pixmap formats, depth 24 is 32 bits per pixel. 

thats what i was getting at :)

> 
>                       Mark.
> 
> 
> > 
> > > const int WIDTH = 100;
> > > const int HEIGHT = 100;
> > > const int FORMAT = ZPixmap;
> > > const int OFFSET = 0;
> > > const int BITMAP_PAD = 0;
> > > const int BYTES_PER_LINE = (WIDTH * 3);
> > 
> > try this:
> > XImage *
> > my_new_ximage(Display *display, Visual *visual, int width, int height, void
> > *data)
> > {
> >   /* this creates an ximage of the same depth as the specified visual */
> >   /* NOTE: Ximages must have pixels aligned to 8, 16 or 32bit boundaries. */
> >   /* 24bit (ie 3 bytes per pixel) is not valid and must be padded out to 32
> >   *//* bits per pixel (4 bytes). The red, greeb and blue masks for your
> >   visual *//* will let you know what parst of the pixel are used for which
> >   color or *//* are padding. You really should use XPutPixel(ximage, x, y,
> >   value); to *//* set pixels if you want to not have portability problems.
> >   *//* If you don't you need to be VERY careful how you address the data of
> >   *//* the XImage *./
> >   XImage *ximage;
> >   XVisualInfo visualinfo, *visualinfo_return;
> >   int number_return;
> > 
> >   if ((width < 1) || (height < 1) || (!display) || (!visual)) return NULL;
> >   visualinfo.visualid = visual->visualid;
> >   visualinfo_return = XGetVisualInfo(display, VisualIDMask, &visualid,
> >                                      &number_return);
> >   /* no pointer return. abort */
> >   if (!visualinfo_return) return NULL;
> >   /* should only return 1 visual with that id */
> >   if (number_return != 1) return NULL;
> > 
> >   ximage = XCreateImage(display, visual, visualinfo_return[0].depth,
> >   ZPixmap, 
> >                         data, width, height, 32, 0);
> >   return ximage;
> > }
> > 
> > read the comments above. you can't do what you are doing as XImages cant be
> > 24bit. you will have to either work with your data in 32 bit or have a 24bit
> > to 32 bit converter. Also note that if you aren't running 32bpp (or 24bpp)
> > you can't just make 32bit XImages and have X do the color conversion fro you
> > - you need to handle each bit depth yourself. So if the server is running
> > 16bpp or 15bpp or 8bpp or even monochrome this will simply not work. This is
> > why there are many libraries and toolkits that handle this work for you.
> > 
> > Several:
> > Imlib2
> > SDL
> > GTK+ (Gdk)
> > Qt
> > and others... I'll leave it to you to do the research, or do the hard work
> > all yourself. :)
> > 
> > > const int IMAGE_BYTES = WIDTH * HEIGHT * 3;
> > > 
> > > XWindowAttributes* rootWindowAttributes = new XWindowAttributes;
> > > 
> > > Visual* visual = rootWindowAttributes->visual;
> > > 
> > > char* data = new char[IMAGE_BYTES];
> > > 
> > > XImage* xImage = XCreateImage(display,
> > >                               visual,
> > >                               DEPTH,
> > >                               FORMAT,
> > >                               OFFSET,
> > >                               data,
> > >                               WIDTH,
> > >                               HEIGHT,
> > >                               BITMAP_PAD,
> > >                               BYTES_PER_LINE);
> > > --------------------------------------
> > > 
> > > Josh Davis
> > > 
> > > 
> > > _________________________________________________________________
> > > Protect your PC - get McAfee.com VirusScan Online  
> > > http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
> > > 
> > > _______________________________________________
> > > Devel mailing list
> > > [EMAIL PROTECTED]
> > > http://XFree86.Org/mailman/listinfo/devel
> > 
> > 
> > -- 
> > --------------- Codito, ergo sum - "I code, therefore I am"
> > -------------------- The Rasterman (Carsten Haitzler)   
> > [EMAIL PROTECTED]
> >                                     [EMAIL PROTECTED]
> > Mobile Phone: +61 (0)413 451 899    Home Phone: 02 9698 8615
> > _______________________________________________
> > Devel mailing list
> > [EMAIL PROTECTED]
> > http://XFree86.Org/mailman/listinfo/devel
> > 


-- 
--------------- Codito, ergo sum - "I code, therefore I am" --------------------
The Rasterman (Carsten Haitzler)    [EMAIL PROTECTED]
                                    [EMAIL PROTECTED]
Mobile Phone: +61 (0)413 451 899    Home Phone: 02 9698 8615
_______________________________________________
Devel mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/devel

Reply via email to