PIL API


Macros

pixel(Image *image, int x, int y)- returns a pointer to the pixel data at x,y in the image.  Because this is a macro, you must be careful to not index out of bounds.

PILImageType(Image *image)- return the type of  the image (RGB, HSV, or GRAY)

PILImageNumberOfBytes(Image *image) - returns the size of the image data in bytes

PILSameTypeAndDimensions(Image *image1, Image *image2) - returns whether or not the two images are of the same type and dimensions.

Functions

Image *PILImageAlloc(int width, int height, int type)
-Returns a new Image, of the given dimensions and type. Returns NULL on memory allocation errors.

Image *PILImageConvert(Image *source, int newType)
-Returns a new image of the given type. Returns NULL if the function fails.

Image *PILImageCopy(Image *source)
-Returns a copy of the given image. Returns NULL if the function fails.

Image *PILImageDiff(Image *image1, Image* image2)
-Returns a new image that is the result of subtracting image1 from image2. Returns NULL if the function fails.

void PILImageDrawCircle(Image *img, int X, int Y, double radius, RGBVAL rgb)
-Draws a circle in the given image, at X,Y.  The color for the circle is specified by rgb.

void PILImageDrawLine(Image *img, int fromX, int fromY, int toX, int toYh, RGBVAL rgb)
-Draws a line in the given image.  The color for the circle is specified by rgb.

void PILImageDrawBox(Image *img,int x, int y, int radius, RGBVAL rgb)
-Draws a box in the given image, at X,Y being the centre of the box.  The color for the circle is specified by rgb.

Image *PILImageExtractPlane(Image *sp, int plane)
- Returns a GRAY image whose data is the respective plane requested.
The following defines have been setup in image.h to aid this funciton

#define RedPlane   0
#define GreenPlane 1
#define BluePlane  2
#define HuePlane   0
#define SatPlane   1
#define ValuePlane 2


void PILImageFill(Image *image, RGBVAL rgb)
- Fills the given image with the colour specified by rgb.

void PILImageFree(Image *imgp)
- Frees up the Image structure and all data associated with it.

Image *PILImageLoad(char *filename)
- Loads and returns the image found at filename.  Returns NULL on failure.
Currently the function tries to invoke the right driver based the on the extention of the filename.  i.e. if filename is: picture.gif, it will try to load the file using the gif driver, and if picture.gif is not a real GIF file, it will return NULL

Image *PILImageMergeRGBPlanes(Image *image1, Image *image2, Image *image3)
- Returns an RGB  image with the 3 planes being R, G, and B respectively.  Returns NULL on failure.

Image *PILImageMergeHSVPlanes(Image *image1, Image *image2, Image *image3)
- Returns an HSV  image with the 3 planes being H,S, and V respectively.  Returns NULL on failure.

Image *PILImageMirrorX(Image *image)
-Returns an image that is a reflectoin in the X plane of the original.  Returns NULL on failure.

Image *PILImageMirrorY(Image *image)
-Returns an image that is a reflectoin in the Y plane of the original.  Returns NULL on failure.

Image *PILImageNegative(Image *image)
-Returns an image that is a photo negative of the original.  Returns NULL on failure.

Image *PILImageResize(Image *image, int newWidth, int newHeight)
-Returns an image that is the of the new specified height and width.  Returns NULL on failure.

Image *PILImageRotate(Image *image, double angle, int centreX, int centreY)
Image *PILImageRotate90(Image *image)
Image *PILImageRotate180(Image *image)
Image *PILImageRotate270(Image *image)
Image *PILImageRotateClip(Image *image, double angle)
-Returns an image with the specified rotation applied to the original.  Returns NULL on failure

int  PILImageSave(char *filename, Image* imgp, int extra)
- Saves the given image to the specified filename.  Like loading, it selects the driver based on the extention specified.
- The extra flag means different things for different image types.

  • When saving JPEG images, the extra flag indicates the quality/compression ratio.  Values of 0 - 100 are accepted.  The higher the quality, the lower the compression and vise versa.
  • When saving PPM, or PGM files, the extra flag indicates whether or not you want to save as a binary PPM/PGM or an ascii PPM/PGM.  Any non-zero value indicates saving in binary format, while a value of 0 indicates saving in ascii format.
  • When saving PNG,GIG,BMP,TIFF, the extra flag is ignored.