[comp.windows.x] X window

doloughlin@GTEWIS.ARPA (08/27/87)

I am curious about any attempts to port Xwindow to Unix System V, and
in particular to Xenix System V.

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

Hi,
  I've been working on OPEN LOOK GUI & TOOLKITS in trying to display a tif file
, bitmap file actually, to be a child widget on the scrolledwindow widget. The
displaying of image failed for unknown reason in which I suspect if the 
scrolledwindow widget does have the functionality to accommodate image. In 
addition to that, I also used one of the Xlib functions, XPutImage, to be an
alternative. XPutImage failed to display the image either and caused core dump.
If anyone does have the experience of dealing image displaying with OPEN LOOK
GUI & TOOLKITS, I'll appreciate that precious information. Thank you.

                                                    Jason Li
                                                    Startegic System Lab
                                                    State of New York

aim@corp.sun.COM (Amy) (11/09/90)

>>From xpert-mailer@expo.lcs.mit.edu Wed Nov  7 19:46:33 1990
>>Organization: New York State Office of General Services, Albany, NY.
>>Subject: X window
>>Sender: xpert-request@expo.lcs.mit.edu
>>To: xpert@expo.lcs.mit.edu
>>
>>
>>Hi,
>>  I've been working on OPEN LOOK GUI & TOOLKITS in trying to display a tif file
>>, bitmap file actually, to be a child widget on the scrolledwindow widget. The
>>displaying of image failed for unknown reason in which I suspect if the 
>>scrolledwindow widget does have the functionality to accommodate image. In 
>>addition to that, I also used one of the Xlib functions, XPutImage, to be an
>>alternative. XPutImage failed to display the image either and caused core dump.
>>If anyone does have the experience of dealing image displaying with OPEN LOOK
>>GUI & TOOLKITS, I'll appreciate that precious information. Thank you.
`
I'm not sure exactly how you are trying to accomplish the above, but,
the ScrolledWindow widget in the OpenLook Intrinsics Toolkit is designed to
provide scrolling capabilities for a WIDGET created as its child.  What
you are looking for is scrolling canvas functionality - the way you get that
is to create a ScrolledWindow and create a Stub widget as it's child.  The Stub
which allows you to attach your own expose handler using the resource XtNexpose -
and it's in this procedure that you want to do any drawing (hence, this is where
you'd load your image).  Below is a simple program whichs sets this up for you.

Hope this helps.
Regards,
Amy Moore
aim@sun.com

#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Xol/OpenLook.h>
#include <Xol/Stub.h>
#include <Xol/ScrolledWi.h>

/******************************************************************
 * CreateDrawableCanvas: function to create a widget which can
 * be used for rendering xlib graphics.
 * This function returns the handle to the created Stub widget.
 *****************************************************************/
 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: routine called on Exposure events on the Canvas(Stub).
 ************************************************************************/
void exposeHandler(w, xevent, region)
Widget w;
XEvent *xevent;
Region region;
{
	Display *display;
	GC gc;
	XGCValues gc_values;
	Window paint_win;
	
	display = XtDisplay(w);
	paint_win = XtWindow(w);

 	/*************************************************
 	* All xlib drawing routines would go here....
 	*************************************************/
}
/**********************************************************************/


main(argc, argv)
int argc;
char **argv;
{
	Widget toplevel, scrollwin, canvas;
	Arg arg[10];
	int n = 0;

	toplevel = OlInitialize(argv[0], "Canvas Test", NULL,
						0, &argc, argv);

	XtSetArg(arg[n], XtNviewHeight,	150);	n++;
	XtSetArg(arg[n], XtNviewWidth,	150);	n++;
	scrollwin = XtCreateManagedWidget("scroller", 
				scrolledWindowWidgetClass,
				toplevel,
				arg,
				n);

	/* Create canvas (Stub) and set its expose Method */
	canvas = CreateDrawableCanvas("canvas", scrollwin, 300, 300);
	XtSetArg(arg[0], XtNexpose, 	(void)exposeHandler);
	XtSetValues(canvas, arg, 1);


	XtRealizeWidget(toplevel);
	XtMainLoop();

}
/*******************************END EXAMPLE*************************/

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.
----------------------------------------------------------------------

etaylor@wilkins.iaims.bcm.tmc.edu (Eric Taylor) (11/30/90)

You have already posted this note.

There are many problems with your code segment :

	Problem #1 :
		XReadBitmapFile does not read TIFF.

	Problem #2 :
		In exposeHandler, you begin setting the fields
		pointed to by image, but that pointer is UNITIALIZED.
		You should not use a pointer in this example.  Use
		the whole structure (change XImage *image to XImage image
			and change image-> to image.)  Also, your function
		block is not there.  Bus Error is the likely result.

	Problem #3 :
		You should construct your XImage ahead of time.
		You should not do it every time your widget is exposed.

	Problem #4 :
		You are cramming a pointer to a pixmap into the image->data
		field.  This is wrong, wrong, wrong.   A Pixmap is
		completely different from image data.

		Use XGetImage to get an image from a pixmap.

		You don't really, have to mess with XImages at all if you
		already have a bitmap.  Use XCopyArea or XCopyPlane instead.


If you have a tiff file already,  convert it to a ppm file and
use xloadimage.  If you have xtiff, you could display the image
using that.
--
					Eric Taylor
					Baylor College of Medicine
					etaylor@wilkins.bmc.tmc.edu
					(713) 798-3776