1 / 23

Pixmaps, Bitmaps and Images

Pixmaps, Bitmaps and Images. How X applications can create, draw, or process rasters,. Rasters. Rasters are rectangular areas of pixels. X represents rasters as Pixmaps : X resources on which one can draw. Bitmaps : pixmaps with values of 1 bit Text files defining an array of bits

liza
Télécharger la présentation

Pixmaps, Bitmaps and Images

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

  4. Pixmaps and Windows • Pixmaps differ from windows • Some procedures do not apply to pixmaps • XClearArea( ) does not clear a pixmap but instead to clear an area one uses XFillRectangle( ) to set all pixels to aknown value. • 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 • Events cannot originate from pixmaps, only from the windows into which they are drawn.

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

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

  8. Pixmaps • 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 • A bitmap is a Pixmap with depth 1 or • a text file containing ASCII information that defines an array of bits. • XReadBitmapFile ( ) to create a bitmap from a file • 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 • 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 <Xm/Xm.h> #include <Xm/Label.h> #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 • X provides support for image manipulation • Images are typically large • 512x512 pixel image with 8 bit pixels = .25M • Images must be communicated to the client so go through the X protocol (network?) and are thus slow. • Xlib must translate for different forms of clients (for example big endian image and little endian clients)

  20. Images • 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 • 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) • 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 • Lots of tools to generate bitmaps • bitmap • and to convert formats • bmtoa • atobm • and between other image formats.

More Related