Subject: Re: rasterfile format

From: [email-masked] (Regis Houde)
Date: Mon, 9 May 1994 20:23:40 GMT

In article [email-masked], [email-masked] (Majid Barazande-Pour) writes:
>
>Hi,
>
>Does any one know  how an image is saved in  sun rasterfile format? What is the range
>of pixel value in pixel image part, 0 to +255 or -125 to +125?
>
>Please reply to: [email-masked]
>
>Thanks,
>

Sun raster image or rasterfile is an image format invented by Sun Microsystems.
It supports images with different depth (1, 8 and 24 as I know) and and be compressed
or not. When it's compressed, it uses the runlength encoding technique. I include
the file "rasterfile.h" at the end of this mail so you can now more about
the file format. I also include the man page that explains this format.

Hope it helps

--------------------------------------------------------------------
Regis Houde                             [email-masked]
Institut de recherche d'Hydro-Quebec    [email-masked]
1800, montee Sainte-Julie		(514) 652-8107
Varennes, Que., Canada   J3X 1S1	FAX : (514) 652-8435
--------------------------------------------------------------------

RASTERFILE(5)             FILE FORMATS              RASTERFILE(5)

NAME
     rasterfile - Sun's file format for raster images

SYNOPSIS
     #include <rasterfile.h>

DESCRIPTION
     A rasterfile is composed of three  parts:  first,  a  header
     containing  8  integers;  second,  a (possibly empty) set of
     colormap values; and third, the pixel image, stored  a  line
     at a time, in increasing y order.  The image is layed out in
     the file as in a memory pixrect.  Each line of the image  is
     rounded up to the nearest 16 bits.

     The header is defined by the following structure:

          struct rasterfile {
               int  ras_magic;
               int  ras_width;
               int  ras_height;
               int  ras_depth;
               int  ras_length;
               int  ras_type;
               int  ras_maptype;
               int  ras_maplength;
          };

     The ras_magic field always contains the following constant:

          #define   RAS_MAGIC 0x59a66a95

     The ras_width, ras_height, and ras_depth fields contain  the
     image's  width  and  height in pixels, and its depth in bits
     per pixel, respectively.   The  depth  is  either  1  or  8,
     corresponding   to   standard   frame  buffer  depths.   The
     ras_length field contains the length in bytes of  the  image
     data.   For  an  unencoded  image, this number is computable
     from the ras_width, ras_height, and  ras_depth  fields,  but
     for  an  encoded image it must be explicitly stored in order
     to be available without decoding the  image  itself.   Note:
     the  length of the header and of the (possibly empty) color-
     map values are not included in the value of  the  ras_length
     field;  it  is  only  the image data length.  For historical
     reasons, files of type RT_OLD will usually have a 0  in  the
     ras_length  field,  and software expecting to encounter such
     files should be prepared to compute the  actual  image  data
     length  if needed.  The ras_maptype and ras_maplength fields
     contain the type and length in bytes of the colormap values,
     respectively.   If  ras_maptype  is  not  RMT_NONE  and  the
     ras_maplength is not 0, then the  colormap  values  are  the
     ras_maplength  bytes  immediately  after  the header.  These
     values are either  uninterpreted  bytes  (usually  with  the
     ras_maptype  set  to RMT_RAW) or the equal length red, green
     and blue vectors, in that order  (when  the  ras_maptype  is
     RMT_EQUAL_RGB).  In  the latter case, the ras_maplength must
     be three times the size in bytes of any one of the vectors.
 
SEE ALSO
     SunView 1 Programmer's Guide
     
Sun Release 4.1   Last change: 19 October 1987                  1

/*	@(#)rasterfile.h 1.11 89/08/21 SMI	*/

/*
 * Description of header for files containing raster images
 */

#ifndef _rasterfile_h
#define _rasterfile_h

struct rasterfile {
	int	ras_magic;		/* magic number */
	int	ras_width;		/* width (pixels) of image */
	int	ras_height;		/* height (pixels) of image */
	int	ras_depth;		/* depth (1, 8, or 24 bits) of pixel */
	int	ras_length;		/* length (bytes) of image */
	int	ras_type;		/* type of file; see RT_* below */
	int	ras_maptype;		/* type of colormap; see RMT_* below */
	int	ras_maplength;		/* length (bytes) of following map */
	/* color map follows for ras_maplength bytes, followed by image */
};
#define	RAS_MAGIC	0x59a66a95

	/* Sun supported ras_type's */
#define RT_OLD		0	/* Raw pixrect image in 68000 byte order */
#define RT_STANDARD	1	/* Raw pixrect image in 68000 byte order */
#define RT_BYTE_ENCODED	2	/* Run-length compression of bytes */
#define RT_FORMAT_RGB	3	/* XRGB or RGB instead of XBGR or BGR */
#define RT_FORMAT_TIFF	4	/* tiff <-> standard rasterfile */
#define RT_FORMAT_IFF	5	/* iff (TAAC format) <-> standard rasterfile */
#define RT_EXPERIMENTAL 0xffff	/* Reserved for testing */

	/* Sun registered ras_maptype's */
#define RMT_RAW		2
	/* Sun supported ras_maptype's */
#define RMT_NONE	0	/* ras_maplength is expected to be 0 */
#define RMT_EQUAL_RGB	1	/* red[ras_maplength/3],green[],blue[] */

/*
 * NOTES:
 * 	Each line of the image is rounded out to a multiple of 16 bits.
 *   This corresponds to the rounding convention used by the memory pixrect
 *   package (/usr/include/pixrect/memvar.h) of the SunWindows system.
 *	The ras_encoding field (always set to 0 by Sun's supported software)
 *   was renamed to ras_length in release 2.0.  As a result, rasterfiles
 *   of type 0 generated by the old software claim to have 0 length; for
 *   compatibility, code reading rasterfiles must be prepared to compute the
 *   true length from the width, height, and depth fields.
 */

#endif /*!_rasterfile_h*/

---
--------------------------------------------------------------------
Regis Houde                             [email-masked]
Institut de recherche d'Hydro-Quebec    [email-masked]
1800, montee Sainte-Julie		(514) 652-8107
Varennes, Que., Canada   J3X 1S1	FAX : (514) 652-8435
--------------------------------------------------------------------