Image coding Isis software documentation

Image coding

This document explains routines for encoding and decoding still images in Isis, including reading and writing JPEG and GIF images.


GIF and JPEG

(read-jpeg port) # decode jpeg from input port (decode-jpeg inbuf bufsize) # decode jpeg from memory buffer (write-jpeg port image quality) # encode jpeg to output port (encode-jpeg image outbuf bufsize quality) # encode jpeg to memory buffer (read-gif port) # decode gif from input port (decode-gif buf) # decode gif in memory buffer This library defines functions to encode and decode JPEG images and decode GIF images (including transparent GIFs). Encoding GIF images is currently not supported. Images can be encoded/decoded to/from a file or a buffer in memory.

read-jpeg decodes a JPEG image from the given port and decode-jpeg decodes a JPEG image directly from a memory buffer. inbuf must be the address of the buffer and bufsize should be the size in bytes of the coded JPEG image in that buffer. Both functions return a new Isis image, or Null if there is an error.

write-jpeg encodes the given Isis image into a JPEG image and writes it to the given port. The quality argument is optional and should be an integer between 1 (worst) and 100 (best). encode-jpeg encodes the image directly to a memory buffer. outbuf should be the address of the output buffer and bufsize should be its size in bytes. The size must be large enough to handle the largest possible JPEG output for the given image (height * width * 2 + 4096 should be plenty). The actual size of the encoded JPEG image is returned, or Null if there is an error.

read-gif decodes a GIF image from the given port, and decode-gif decodes a GIF image directly from a memory buffer. Both functions return a list of Isis images, or Null if there is an error. If the GIF is not animated, there will be only one item in this list, otherwise there will be as many images as there are frames in the GIF animation.

Example

Converting a GIF image to a JPEG image:
(set infile (open-input "banjo.gif")) (set image ((read-gif infile) 0)) # using first and only frame in sequence (close infile) (set outfile (open-output "banjo.jpg")) (write-jpeg outfile image 50) (close outfile) (free-image image)


Requirements:
Scripts: (load "image-coding.isis")
Libraries: -lisis_jpeg -ljpeg -lisis_gif
Headers: isis_jpeg.h
isis_gif.h
Binders: bind_jpeg_library(script);
bind_gif_library(script);


written by: Stefan Agamanolis and Jeremy Lilley