Subject: CVS hippo: Improved CGradient

From: CVS <[email-masked]>
Date: Tue, 25 May 1999 09:14:59 -0500 (CDT)

CVSROOT:	/home/cvs/fvwm
Module name:	fvwm
Changes by:	hippo	99/05/25 09:14:59

Modified files:
	fvwm           : Makefile.am colors.c 

Log message:
Improved CGradient
I used and XImage, can anyone provide a working XCreateImage so it doesn't
have to do an XGetImage?

--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Brad Giaccio <[email-masked]>
Date: Tue, 25 May 1999 10:34:43 -0400

Well reading your comment now I understand what you want.

call XCreatimage making data an array of the appropriate size
 so you would do
char *data = (char*) calloc(width*width, sizeof(char));
image = XCreateImage(dpy, Scr.viz, Scr.depth, XYPIxmap, 0, data, 
					width, width, 8, 0); 

That should do the trick if I'm understanding you correctlly.

-- 
--- There are two kinds of knowledge, you either know the answer or
			you know where to find it
		      -Kane, Johnson, and anonymous
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Tim Phipps <[email-masked]>
Date: Tue, 25 May 1999 15:40:15 +0100

> image = XCreateImage(dpy, Scr.viz, Scr.depth, XYPIxmap, 0, data,

Do I have to have an XInitImage() after the XCreateImage()? I tried it
and the XInitImage caused a core dump.

Cheers,
Tim.

---

From: Brad Giaccio <[email-masked]>
Date: Tue, 25 May 1999 10:52:12 -0400

> and the XInitImage caused a core dump.

XInitImage?? I've never heard of that call and its not in my trusty X books where are you reading about that function.  But no nothing else should need to be done at that point you can strt calling X drawing functions to fill the XImage struct.

Brad

---

From: Tim Phipps <[email-masked]>
Date: Tue, 25 May 1999 15:56:40 +0100

Brad Giaccio wrote:
> XInitImage?? I've never heard of that call and its not in my trusty X books
> where are you reading about that function.

It's at the top of the XCreateImage man page.

>  But no nothing else should need to be done at that point you can strt calling
> X drawing functions to fill the XImage struct.

I'll give it a go then.
Cheers,
Tim.

---

From: Brad Giaccio <[email-masked]>
Date: Tue, 25 May 1999 11:07:35 -0400

On Tue, May 25, 1999 at 03:56:40PM +0100, Tim Phipps wrote:

> Brad Giaccio wrote:
>
> > XInitImage?? I've never heard of that call and its not in my trusty
> > X books where are you reading about that function.
>
> >  But no nothing else should need to be done at that point you can
> > strt calling X drawing functions to fill the XImage struct.
>
> I'll give it a go then.  Cheers, Tim.

Now I see it, odd that its not in the O'Reilly book.  From what I
read in the man page it is designed moree to properlly initialize a
structure that you create without using Xlib, since you are calling
XCreateImage there is no need for you to initalize the image structure
with XInitImage.

If it still doesn't work try and see if you are getting any error
matches and BadDrawables or BadMatch errors or anything along with the
core dump, also just for debuging check the return value of XCreateImage
and make sure it is not NULL.

Brad

---

From: Tim Phipps <[email-masked]>
Date: Wed, 26 May 1999 15:11:53 +0100

> and make sure it is not NULL.

I've got it to work but I'm not sure it will work on all client
architectures and servers.  It was core dumping because I had used 8 as
the bitmap_pad, switching to 16 fixed it.  I've now got it working
really fast by specifying ZPixmap as the format and writing the pixel
values directly to memory (using XPutPixel doesn't work!) but I've got a
feeling that I'm being lucky not to hit and endian problem.

Does this look OK?

  Pixel *imageData, pixels;
  imageData = (Pixel *)safemalloc(width * width * sizeof(Pixel));
  image = XCreateImage(dpy, Scr.viz, Scr.depth, ZPixmap, 0,
                       (char *)imageData, width, width, sizeof(Pixel) *
8,
                       0);
  for (i = 0; i < width; i++)
    for (j = 0; j < width; j++) {
      register int x = (i - width / 2), y = (j - width / 2);
      register long distance = sqrt((x * x + y * y) / 2);
      imageData[i * width + j] = pixels[distance];
    }
  XPutImage(dpy, pixmap, gc, image, 0, 0, 0, 0, width, width);
  XDestroyImage(image);
 
I don't know why using XPutPixel int the inner loop doesn't work, any
ideas?

Cheers,
Tim.

---

From: Brad Giaccio <[email-masked]>
Date: Wed, 26 May 1999 10:54:06 -0400

> feeling that I'm being lucky not to hit and endian problem.

You right you did want 16 that was my fault, and ZPixmap is right for
what you want I just happen to have been working with XYPIxmaps all
day.  As for XPutPixel I seem to remember having trouble with that when
I created the data member myself but running your for loop actually does
the samething as the call to XPutPixel so you should be ok.  As for
endian order you should be fine, but we can verify that when you are
done.  You even remembered the XDestroyImage good work.  This should all work.

Are you getting any error messages with the XPutPixel or just a core
dump?  Just trying to figure out what is happening here, but if we can't
your for loop should be fine.

---

From: Tim Phipps <[email-masked]>
Date: Wed, 26 May 1999 16:35:48 +0100

> your for loop should be fine.

I must have been malloc'ing too small an area for the image data, I
can't get it to core dump now but when it did it was in a call to
malloc() within XPutImage().

Anyway thanks for the help.
Cheers,
Tim.