Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pixmaps, Bitmaps and Images How X applications can create, draw, or process rasters,

Similar presentations


Presentation on theme: "Pixmaps, Bitmaps and Images How X applications can create, draw, or process rasters,"— Presentation transcript:

1 Pixmaps, Bitmaps and Images How X applications can create, draw, or process rasters,

2 Rasters n Rasters are rectangular areas of pixels. X represents rasters as – Pixmaps : X resources on which one can draw. – Bitmaps : n pixmaps with values of 1 bit n Text files defining an array of bits – Images : data structures that can be drawn into windows or pixmaps.

3 Pixmaps n A pixmap is a drawable that has – width and height – depth – an associated screen n A pixmap is like a window – coordinates with (0,0) being upper left – sizes expressed in pixels

4 Pixmaps and Windows n Pixmaps differ from windows – Some procedures do not apply to pixmaps n XClearArea( ) does not clear a pixmap but instead to clear an area one uses XFillRectangle( ) to set all pixels to aknown value. n Pixmaps are drawn into windows, not mapped to the screen. – Pixmaps have no borders. – Pixmaps do not belong to a widget hierarchy as do windows.

5 Pixmaps vs Windows n Events cannot originate from pixmaps, only from the windows into which they are drawn.

6 Pixmaps n Three functions are important: create – XCreatePixmap( Display* display, – Drawable screen, – unsigned int width, – unsigned int height, – unsigned int depth); n The screen parameter must represent some existing Drawable, a window or pixmap.

7 Pixmaps n Three functions are important: destroy – XFreePixmap(display,pixmap) ; if an application no longer needs a pixmap

8 Pixmaps n Three functions are important: inquire – Status XGetGeometry(Display* display, – Drawable drawable, – Window *root, – int *x, int *y, – unsigned int *border_width, – int *depth) the pointers return the information and is useful when the drawable is a pixmap.

9 Bitmaps n A bitmap is a Pixmap with depth 1 or n a text file containing ASCII information that defines an array of bits. n XReadBitmapFile ( ) to create a bitmap from a file n XWriteBitmapFile( ) to write a bitmap file.

10 Bitmap file format #define arrow_width 16 #define arrow_height 16 #define arrow_x_hot 12 #define arrow_y_hot 1 static char arrow_bits[ ] = { 0x00, 0x00, 0x00, 0x10, … };

11 Reading the bitmap file n int status; status =XReadBitmapFile(display,drawable, filename, &width,&height, &pixmap, &x_hot, &y_hot); which creates a bitmap and returns it in the pixmap parameter.

12 An example /* label_pixmap.c */ #include #include "btbuxton.xbm" XtAppContext context; Widget toplevel, label;

13 An example unsigned int get_depth(Widget w) /* gets the depth of the display holding w. */ { Window r; unsigned int x,y,wd,ht,bw,depth; XGetGeometry(XtDisplay(w), RootWindowOfScreen(XtScreen(toplevel)), &r,&x,&y,&wd,&ht,&bw,&depth); return depth; }

14 An example main(int argc,char *argv) { Arg al[10]; int ac; int foreground,background; Pixmap pix; unsigned int depth; toplevel = XtAppInitialize(&context, "",NULL,0,&argc,argv,NULL,NULL,0); /* create the label */ ac=0; label=XmCreateLabel(toplevel,"label",al,ac); XtManageChild(label);

15 /* get colors of label */ ac=0; XtSetArg(al[ac], XmNforeground, &foreground); ac++; XtSetArg(al[ac], XmNbackground, &background); ac++; XtGetValues(label, al, ac); /* get the depth so pixmap can be created. */ depth=get_depth(toplevel); /* create the pixmap */ pix=XCreatePixmapFromBitmapData(XtDisplay(toplevel), RootWindowOfScreen(XtScreen(toplevel)), btbuxton_bits,btbuxton_width,btbuxton_height, foreground,background,depth);

16 /* set appropriate label resources to * attach the pixmap to the label */ ac=0; XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++; XtSetArg(al[ac], XmNlabelPixmap, pix); ac++; XtSetArg(al[ac], XmNshadowThickness, 4); ac++; XtSetValues(label, al, ac); XtRealizeWidget(toplevel); XtAppMainLoop(context); }

17 Another Example: Pixmap to Window. /* get the current fg and bg colors. */ ac=0; XtSetArg(al[ac], XmNforeground, &fc); ac++; XtSetArg(al[ac], XmNbackground, &bc); ac++; XtGetValues(drawing_area, al, ac); depth=get_depth(drawing_area); p=XCreatePixmapFromBitmapData( XtDisplay(drawing_area), XtWindow(drawing_area),btbuxton_bits, btbuxton_width,btbuxton_height, fc, bc, depth);

18 Another Example: Pixmap to Window. /* Draw the Pixmap in the drawing area */ XCopyArea(XtDisplay(drawing_area), p,XtWindow(drawing_area),gc,0,0, btbuxton_width, btbuxton_height, 100,100 ); /* Free up resources no longer needed */ XFreePixmap(XtDisplay(drawing_area),p);

19 Images n X provides support for image manipulation n Images are typically large – 512x512 pixel image with 8 bit pixels =.25M n Images must be communicated to the client so go through the X protocol (network?) and are thus slow. n Xlib must translate for different forms of clients (for example big endian image and little endian clients)

20 Images n Color maps are a problem. Many times one must translate pixel values from the image into values obtained from color cell allocation before the image is displayed.

21 XImages n XImage is an X datatype (struct) accompanied by formats – XYBitMap image format – XYPixMap image format – ZPixmap image format (organized as an array of pixel values, called pixel mode images) n input/output is binary i/o of objects of this type.

22 Example lines of code format = XYPixmap; bitmap_pad = 32; image = XCreateImage( display, DefaultVisual(display,screen), depth, format,0,0,width,height,bitmap_pad,0); newimage = XSubImage(image,x,y,width,height); pixel = XGetPixel(image, x,y); status = XPutPixel(image,x,y,pixel); XPutImage(display,drawable,gc,image,src_x,src_y,dest_x dest_y,width,height);

23 Tools n Lots of tools to generate bitmaps – bitmap n and to convert formats – bmtoa – atobm n and between other image formats.


Download ppt "Pixmaps, Bitmaps and Images How X applications can create, draw, or process rasters,"

Similar presentations


Ads by Google