IM_WRITE

im_write - write pixels to a KUIM image file

Synopsis

void im_write(Image, PixType, Data)
   IM_TYPE *Image;
   int PixType;
   char *Data;

Description

The im_write routine writes pixel data from a pixel buffer to a previously created KUIM image file. The actual pixel data type in the Data buffer is specified by the PixType argument. If this type is different from the pixel type specified by im_create, the data will be converted before it is written. The pixel buffer Data is assumed to have been previously allocated using one of the im_alloc routines (or equivalent malloc calls). No range of image dimensions need be specified, the whole image is written at once. The parameters to this routine are:

Image - This is a pointer to a IM_TYPE data structure which was previously initialized using im_create.

PixType - This is a value which specifies the type of pixel data stored in the Data buffer. Valid values for this field are: BYTE, SHORT, INT, FLOAT, DOUBLE, COMPLEX, COLOR, PSEUDO (all defined in IM.h).

Data - This is the address of the pixel buffer which is to hold the image being written. It is assumed that this space has been allocated using one of the im_alloc routines. For multidimensional images, take care to pass the address of the first pixel to the routine and NOT simply the address of the 2D or 3D access array (see example below).

Examples

To write a 1D SHORT image to file "test1.IM" use:

   IM_TYPE *Image1;
   SHORT_TYPE *Data1;
   int PixType, Xdim,Ydim,Zdim, DimCnt;
   Image1 = im_create("test1.IM", SHORT ,Xdim ,Ydim, Zdim);
   Data1 = (SHORT_TYPE **)im_alloc1D(Image1, SHORT);
   im_write(Image1, SHORT, Data1);
   

To write a 2D FLOAT image to file "test2.IM" use:

   IM_TYPE *Image2;
   FLOAT_TYPE **Data2;
   int PixType, Xdim,Ydim,Zdim, DimCnt;
   Image2 = im_create("test2.IM", SHORT, Xdim, Ydim, Zdim);
   Data2 = (FLOAT_TYPE **)im_alloc2D(Image2, FLOAT);
   im_write(Image2, FLOAT, &(Data2[0][0]));
   

Files

Source is in $KUIM/src/libIM

See Also

im_create, im_open, im_read, im_write, im_get_title, im_put_title, im_get_cmap, im_put_cmap, im_alloc1D, im_alloc2D, im_alloc3D, im_free1D, im_free2D, im_free3D.

Author

John M. Gauch
Electrical Engineering and Computer Science
University of Kansas

Diagnostics

When this routine succeeds, the Data buffer is updated. Upon occurrence of any error condition, a message is printed and the program exits.

Bugs

At present, an image can only be written once after it has been created. To re-write an image, you must create a new file. This is an artifact of the fact that im_write writes the image header and image pixels and closes the file.