[comp.windows.news] X window

ccli@nysnet.nysnet (Chia-Chih Li) (11/28/90)

Hi,
  I've been tring to display an image which is a tiff file  created by scanner 
on the OpenLook X window. The image displaying will be placed in the expose 
procedure of stub widget under the parent widget, scrolledwindow widget. I used
Xlib functions, XReadBitmapFile and XPutImage, for image displaying inside the
expose procedure, but they are not really working. Core dump occurred in the 
earlier testing and I'm getting errors for XReadBitmapFile now. The brief code 
for displaying is listed below. If anyone does have the experience of dealing
image displaying on OpenLook X window using Xlib functions other than what I'm
using now, I'll appreiate if you could drop a line.


*******************************************************************************

#define LONG 4

Display *display;
Screen *screen;
char *filename = "/usr/accts/ccli/ski.tif";


/* creating the pixmap image using XReadBitmapFile to fill in the pixmap */

create_read_imagepix(imagep, filename, width, height)
Pixmap *imagep; /* returned created imagep */
char *filename;
unsigned int * width, *height;
{
	int depth=1;
	int value;
	int x_hot, y_hot;

	value = XReadBitmapFile(display, RootWindow(display, screen),filename,
			width, height, imagep, &x_hot, &y_hot);
	return(vaule);  /* returns BitmapSuccess if everything worked */
}


/* CreateDrawableCanvas */

Widget
CreateDrawableCanvas(name, parent, width, height)
char *name;
Widget parent;
int width, height;
{
	Widget canvas;
	Arg arg[4];
	int n = 0;

	 
	XtSetArg(arg[n], XtNwidht,	(Dimension) width); n++;
	XtSetArg(arg[n], XtNheight,	(Dimension) height); n++;

	canvas = XtCreateManagedWidget(name, stubWidgetClass, parent, arg, n);
	return(canvas);
}


/* exposeHandler */

void exposeHandler(w, xevent, region)
Widget w;
XEvent *xevent;
Region region;
{
	GC gc;
	XGCValues gc_values;
	Window paint_win;
	XImage *image;
	unsigned int width, height;
	Pixmap *imagep;

	display = XtDisplay(w);
	paint_win = XtWindow(w);

	
	unsigned int width, height;
	Pixmap *imagep;

        display = XtDisplay(w);
	paint_win = XtWindow(w);


        Pixmap *imagep;

	display = XtDisplay(w);
	paint_win = XtWindow(w);

	image->width=LONG;
	image->height=LONG;
	image->xoffset=512;
	image->format=XYPixmap;
	image->data=imagep;
	image->byte_order=LSBFirst;
	image->bitmap_unit=8;
	image->bitmap_bit_order=LSBFirst;
	image->bitmap_pad=8;
	image->depth=1;
	image->bytes_per_line=512;
	image->bits_per_pixel=8;

	XPutImage(display,paint_win,gc,image,0,0,0,0,widht,height);
}
 

main(argc,argv)
int argc;
char **argv;
{
	Arg args[10];
	Widget canvas;
	Pixmap imagepix;
	unsigned int imagep_width, imagep_height;

	if(create_read_imagepix(&imagepix, filename, &imagep_width, 
		&imagep_height) != BitmapSuccess)
	fprintf(stderr, "Can't read bitmap\n");

	/* stub widget: this will be used as a drawing board */

	canvas = CreateDrawableCanvas("canvas", scrolledwindow, 350, 500);
	i = 0;
	XtSetArg(args[i], XtNexpose,	(XtArgVal) exposeHandler); i++;
	XtSetArg(canvas, args, i);

	XtRealizeWidget(toplevel);
	XtMainLoop();
}
*******************************************************************************

ccl@cs.albany.edu (Chia-Chih Li) (11/29/90)

Hi World,

I've been trying to display an image which is a tiff file created by scanner 
on an OpenLook X window. The displaying will be taken place in the expose 
procedure of stub widget under the parent widget, scrolledwindow widget. I 
used two Xlib routines, XReadBitmapFile and XPutImage, for the displaying 
inside the expose procedure. Core dump occurred in the earlier testing and now
 I'm getting errors for XReadBitmapFile. I'm not really sured the two Xlib 
routines that I used is appropreiated for image displaying. If anyone does 
have the experiences of dealing image displaying on OpenLook X window using 
different Xlib routines or some methods other than what I'm doing here, I'll 
appreiate if you could drop a line. I have a brief code of what I did of image
 displaying listed below. 


*******************************************************************************

#define LONG 4

Display *display;
Screen *screen;
char *filename = "/usr/accts/ccli/ski.tif";

/* creating the Pixmap image using XReadBitmapFile to fill in the pixmap */
create_read_imagepix(imagep, filename, width, height)
Pixmap *imagep;  /* returned created imagep */
char *filename;
unsigned int *width, *height;
{
	int depth=1;
	int value;
	int x_hot, y_hot;

	value = XReadBitmapFile(display, RootWindow(display, screen), filename,
			width, height, imagep, &x_hot, &y_hot);
	return(value);
}


/* CreateDrawableCanvas */
Widget
CreateDrawableCanvas(name, parent, width, height)
char *name;
Widget parent;
int width, height;
{
	Widget canvas;
	Arg arg[4];
	int n = 0;

	XtSetArg(arg[n], XtNwidth,	(Dimension) width); n++;
	XtSetArg(arg[n], XtNheight, 	(Dimension) height); n++;

	canvas = XtCreateManagedWidget(name, stubWidgetClass, parent, arg, n);
	return(canvas);
}


/* exposeHandler */
void exposeHandler(w, xevent, region)
Widget w;
XEvent *xevent;
Region region;
{
	GC gc;
	XGCValues gc_values;
	Window paint_win;
	XImage *image;
	unsigned int width, height;
	Pixmap *imagep;

	display = XtDisplay(w);
	paint_win = XtWindow(w);

	image->width=LONG;
	image->height=LONG;
	image->xoffset=512;
	image->format=XYPixmap;
	image->data=imagep;
	image->byte_order=LSBFirst;
	image->bitmap_unit=8;
	image->bitmap_bit_order=LSBFirst;
	image->bitmap_pad=8;
	image->depth=1;
	image->bytes_per_line=512;
	image->bits_per_pixel=8;

	XPutImage(display,paint_win,gc,image,0,0,0,0,width,height);
}


main(argc, argv)
int argc;
char **argv;
{
	Widget canvas;
	Pixmap imagepix;
	unsigned int imagep_width, imagep_height;

	if(create_read_imagepix(&imagepix, filename, &imagep_width, 
			&imagep_height) != BitmapSuccess)
	fprintf(stderr,"Can't read bitmap\n);

	/* Stub widget: this will be used as a drawing board */
	canvas = CreateDrawableCanvas("canvas", scrolledwindow, 350, 500);
	i = 0;
	XtSetArg(args[i], XtNexpose, 	(XtArgVal) exposeHandler); i++;
	XtSetArg(canvas, args, i);

	XtRealizeWidget(toplevel);
	XtMainLoop();
}
*******************************************************************************

                                                       Jason Li
                                                       Strategic System Lab
                                                       State of New York 
                                                       11/28/90  

west@widgit.enet.dec.com (Jim West (Stealth Contractor)) (11/29/90)

In article <499@lovelace.albany.edu>, ccl@cs.albany.edu (Chia-Chih Li) writes...

>Hi World,
> 
>>used two Xlib routines, XReadBitmapFile and XPutImage, for the displaying 
>>inside the expose procedure. Core dump occurred in the earlier testing and now
>> I'm getting errors for XReadBitmapFile. I'm not really sured the two Xlib 

  Here is the start of the problem.  TIFF format is not Bitmap format.  A
bitmap has only a depth of 1 plane and is stored in a file in a particular
manner.

  TIFF is an image format that is foreign to the X Window environment.  What
you will need to do is write your application so that it can understand the
TIFF format and then convert to an image format the X understands.

  This is usually not trivial.  You may want to look in comp.sources.x for
several utilities, like the Portable Bitmap Plus (PBM+) utilties that can
do this for you.

					-=> Jim <=-


----------------------------------------------------------------------
 Jim West                      |  The Schainker Converse
 west@widgit.enet.dec.com      |  to Hoare's Law :
                               |
 These are my opinions.        |   Inside every small problem
 Digital has no idea           |     is a larger problem struggling
 what I'm  saying.             |       to get out.
----------------------------------------------------------------------