Sun Microsystems Documentation
Begin Tab Sub LinksActive Sub LinkView this Book Download this Book

Solaris XIL 1.3 AnswerBook >> XIL Programmer's Guide >> 9 Presentation Functions >> Casting an Image From One Data Type to Another

PreviousPrevious: Copying an Image to the Display

Casting an Image From One Data Type to Another

The xil_cast() function casts an XIL image from one data type to another. The function's prototype is shown below.

  void xil_cast(XilImage src, XilImage dst);  

The src parameter is a handle to your source image, and dst is a handle to a destination image. This destination must have the same width, height, and number of bands as the source image and must have the data type to which you want to cast the source image.
There are a number of instances in which you may need to use this function as you prepare an image for display. For example, you may have a single-band XIL_SHORT image that you want to display in an 8-bit window. To do this you need to follow these steps.
  1. Rescale the image.

    Unless the values in your XIL_SHORT image already fall in the range 0 to 255, you must use the xil_rescale() function to map them to that range, or a subset of that range. For more information about rescaling images, see "Rescaling an Image" on page 158.

  2. Cast the XIL_SHORT image to an XIL_BYTE image. Before you can display your image in an 8-bit window, you must cast the 16-bit values in the source image to 8-bit values, as shown in this code fragment.


  XilImage short_image, byte_image;  
  unsigned int width, height, nbands; /* Dimensions of images */  
  
  byte_image = xil_create(state, width, height, nbands,  
      XIL_BYTE);  
  xil_cast(short_image, byte_image);  

Similarly, if you have an XIL_BIT image that you want to display in an 8-bit window, you must cast the source image to an XIL_BYTE image before displaying it. In this cast, the values 0 and 1 in the XIL_BIT image are cast to indices 0 and 1 in the XIL_BYTE image. If you want different indices, convert the image by passing it through a lookup table rather than by casting its data type. For information about lookup tables, see "Passing an Image Through a Lookup Table" on page 271.

Note - When casting the image so you can display it, you may want to use a display image as the destination image for the cast. However, if you intend to use the converted image again, you can cast the source image to an interim destination image, then use xil_copy() to copy the interim image to the display.


NextNext: Dithering an Image
ContactAbout SunNewsEmploymentSite MapPrivacyTerms of UseTrademarksCopyright Sun Microsystems, Inc.