XForms: blitting images

Andrew McCready (mccready@andrew.cmu.edu)
Fri, 9 Apr 1999 10:53:54 -0400 (EDT)

# To subscribers of the xforms list from Andrew McCready <mccready@andrew.cmu.edu> :

I've got a 320x240 image in raw rgb values that I want to display. Is
there anyway to do this directly without first converting it to
something like a pixmap? I looked through the archive for the list, but
the best I found suggested doing the pixmap conversion, which goes
something like this (this may look very familar to someone):

void show_img(int width, int height, unsigned char *img, FL_FORM *form,FL_OBJECT *obj)
{
XImage *i;
Pixmap p;
XWindowAttributes xwa;
Display *dpy;
Window w;
char *data;
int x,y;
unsigned long r,g,b;

dpy = fl_get_display();
w=FL_ObjWin(obj); // window of Pixmap object
XGetWindowAttributes(dpy, w, &xwa);
data=malloc(width*height*3);
p=XCreatePixmap(dpy, w, width, height, xwa.depth);
i=XCreateImage(dpy, xwa.visual, xwa.depth, ZPixmap,0, data, width,height, 8, 0);

for(x=0;x<width;x++) {
for(y=0;y<height;y++) {
r = img[(x+y*width)*3+0];
g = img[(x+y*width)*3+1];
b = img[(x+y*width)*3+2];
XPutPixel(i,x,y,(r << 16 | g << 8 | b ));
}
}

XPutImage(dpy, p, fl_state[fl_get_form_vclass(form)].gc[0],i, 0,0, 0,0,width,height);
XDestroyImage(i);
fl_free_pixmap_pixmap(obj);
fl_set_pixmap_pixmap(obj, p, 0);

return;
}

It seems that having to do this extra format conversion adds
unnecessary execution time to the program (ignore, for the moment, the
increadible time waste in indexing the image). Is there a way to draw
pixels directly to a pixmap or canvas object without having to do a
XCreateImage etc? (Right now, I'm passing a pixmap object to the obj
pointer).

Thanks, Andrew

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/