next up previous contents
Next: Binary images Up: Image file I/O Previous: Filling an image with   Contents


Converting a pixel to a given format/type

Gandalf routines taking Gan_Pixel structure pointers as arguments, such as gan_image_fill_const(), require that the format and type of the pixel and image arguments match. This can be done by using the routines in this section. To convert a pixel to a specific format and type use the routine
      Gan_Pixel Pixel1, Pixel2; /* declare pixels 1 & 2 */

      /* let's initialise pixel 1 to a grey-level unsigned character value */
      Pixel1.format = GAN_GREY_LEVEL_IMAGE;
      Pixel1.type = GAN_UCHAR;
      Pixel1.data.gl.uc = 255;

      /* now convert pixel to RGB format and floating point type */
      gan_image_convert_pixel_q ( &Pixel1, GAN_RGB_COLOUR_IMAGE, GAN_FLOAT,
                                  &Pixel2 );

      /* print new pixel value, which should be R=G=B=1 */
      printf ( "pixel RGB value %f %f %f\n", Pixel2.data.rgb.f.R,
               Pixel2.data.rgb.f.G, Pixel2.data.rgb.f.B );
Another version of this function returns the result as a new pixel:
      /* convert pixel to RGB format and floating point type */
      Pixel2 = gan_image_convert_pixel_s ( &Pixel1, GAN_RGB_COLOUR_IMAGE, GAN_FLOAT );
There is also a routine that converts the format and type in-place in the input pixel:
      /* convert pixel to RGB format and floating point type in-place */
      gan_image_convert_pixel_i ( &Pixel1, GAN_RGB_COLOUR_IMAGE, GAN_FLOAT );



2006-03-17