Gan_Image *pImage; /* create grey-level signed short image */ pImage = gan_image_alloc_gl_s ( 200, 100 ); /* fill with constant */ gan_image_fill_const_gl_s ( pImage, 23 );which fills each pixel with the value 23. For other formats of image you will need to build a structure of the relevant type, for instance
Gan_Image *pImage; Gan_RGBPixel_uc rgbucPixel; /* create RGB unsigned character image */ pImage = gan_image_alloc_rgb_uc ( 200, 100 ); /* set up pixel */ rgbucPixel.R = 34; rgbucPixel.G = 2; rgbucPixel.B = 65; /* fill with constant RGB value */ gan_image_fill_const_rgb_uc ( pImage, &rgbucPixel );
Higher level routines are available using the Gan_Pixel structure:
Gan_Image *pImage; Gan_Pixel Pixel; /* create RGBA single precision floating point image */ pImage = gan_image_alloc_rgba_f ( 200, 100 ); /* set up pixel */ Pixel.format = GAN_RGB_COLOUR_ALPHA_IMAGE; Pixel.type = GAN_FLOAT; Pixel.data.rgba.f.R = 0.1F; Pixel.data.rgba.f.G = 0.2F; Pixel.data.rgba.f.B = 0.3F; Pixel.data.rgba.f.A = 0.4F; /* fill with constant RGBA value. The format & type of the pixel and image should match */ gan_image_fill_const ( pImage, &Pixel );
If the Gan_Pixel structure has a different format/type to the image, use gan_image_convert_pixel_[qsi]() to convert it to the format & type of the image before calling gan_image_fill_const(). See Section 4.3.4 for details.
There is a special function gan_image_fill_zero() to fill an image with zero, whatever format and type it has:
Gan_Image *pImage; /* create RGBA single precision floating point image */ pImage = gan_image_alloc_rgba_f ( 200, 100 ); /* set all image pixels to zero */ gan_image_fill_zero ( pImage );
For boolean images (Section 4.4), ``zero'' is interpreted as false (GAN_FALSE), and for pointer images (Section 4.5) ``zero'' means NULL. To fill a single pixel with zero, use
/* set a single pixel at position row=10, column=21 to zero */ gan_image_set_pix_zero ( pImage, 10, 21 );
There are also routines to fill a rectangular sub-region of an image, either with a constant value or zero:
Gan_Image *pImage; Gan_Pixel Pixel; /* create grey-level signed short image */ pImage = gan_image_alloc_gl_s ( 200, 100 ); /* set pixels in 30x40 (heightxwidth) pixel region starting at position 100,30 (row,column) to constant value 125 */ Pixel.format = GAN_GREY_LEVEL_IMAGE; Pixel.type = GAN_SHORT; Pixel.data.gl.s = 125; gan_image_fill_const_window ( pImage, 100, 30, 30, 40, &Pixel ); /* reset image to RGB unsigned character */ gan_image_set_rgb_uc ( pImage, 100, 50 ); /* set pixels in 20x15 (heightxwidth) pixel region starting at position 10,35 (row,column) to zero */ gan_image_fill_zero_window ( pImage, 10, 35, 20, 15 );
Error detection: The image filling routines return a boolean value, so a return value of GAN_FALSE indicates failure, with the Gandalf error handling module being invoked.