ftp.nice.ch/pub/next/developer/resources/libraries/SurfImage.1.0.s.tar.gz#/SurfImage/SurfGIFSupport.subproj/SurfGIFDecoder.h

This is SurfGIFDecoder.h in view mode; [Download] [Up]

/*  
** Copyright (c) 1995 Netsurfer Inc.  All Rights Reserved.
**
** Author: <bbum@friday.com>
*/

/*  This object is included in the MiscKit by permission from the author
**  and its use is governed by the MiscKit license, found in the file
**  "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
**  for a list of all applicable permissions and restrictions.
*/

typedef struct _SurfColorEntry32 {
	unsigned char 	red:8;
	unsigned char	green:8;
	unsigned char	blue:8;
	unsigned char	alpha:8;
} SurfColorEntry32;

typedef struct _SurfColorEntry16 {
	unsigned char 	red:4;
	unsigned char	green:4;
	unsigned char	blue:4;
	unsigned char	alpha:4;
} SurfColorEntry16;

#define GCT_MAX_ENTRIES (256)
#define GCT_MAX_BYTES   (256 * sizeof(SurfColorEntry32))

/* The following are used for two purposes;  one) to identify the
   appropriate color plane within the planar data in the NXBitmapImageRep
   and two) to retrieve the appropriate byte from the color tabel.
 */
#define RED_PLANE 0
#define GREEN_PLANE 1
#define BLUE_PLANE 2
#define ALPHA_PLANE 3

@interface SurfGIFDecoder:SurfDecoder
{
	struct __GIFDecodeFlags {
		unsigned char	showColorTable:1; /*"dump color table?"*/

        /* if YES, the decoder will produce Silhouettes of the input
           gif-- that is, anywhere there is color in the original
           image, the result will be white.  Likewise, anywhere
           there is transparency in the original image, the result
           will be transparent.  Default is NO.
         */
		unsigned char 	produceSilhouette:1;/*"produce silhouette?"*/

        /* ++++++ Global Color Table FLAGS
         */

        /* If YES, decoder will zero any bytes in GCT beyond last
           color of current image.
         */
		unsigned char   gctZeroUnused:1; /*"zero unspecified bytes?"*/

        /* If YES, GIF stream has a global color table.
         */
		unsigned char	gctPresent:1;/*"gct present in stream?"*/

        /* If YES, global color table is sorted in order of decreasing
           importance.
         */
		unsigned char   gctSorted:1;/*"gct sorted most to least significant?"*/
		
        /* +++++ Graphical Control Extension FLAGS
         */

        /* if YES, then a GCE was decoded immediately before what
           should be the next ImageDescriptor.  The Graphic Control
           Extension should, therefore, modify the decoding of the
           Image Descriptor.  If NO, then no GCE was present and
           the Image Descriptor should be decoded according to teh
           configuration found in the Logical Screen Descriptor,
           etc.
         */
		unsigned char	gcePresent:1;/*"graphic control extension?"*/

        /* If YES, then gceTransparentColorIndex will contain the
           index of the color within the color table that should be
           rendered fully transparent.  NOTE:   this flag should
           NEVER be set if gcePresent is NOT ALSO SET-- the decoder
           does NOT check BOTH FLAGS!
         */
		unsigned char   gceUseTransparency:1;/*"image has transparency?"*/

        /* +++++ Local Image Descriptor FLAGS
         */

        /* If YES, indicates that a local color table has been
           allocated/read and should be used instead of the
           globalColorTable during decoding.
         */
		unsigned char   lctPresent:1;/*"local color table?"*/

        /* If YES, the local color table is sorted in order of
           decreasing importance.
         */
		unsigned char	lctSorted:1;/*"local color table sorted?"*/

        /* If YES, image descriptor is interlaced
         */
		unsigned char 	idInterlaced:1;/*"interlaced iamge?"*/
	} _SGIFDFlags;

	char	version[4]; /*"GIF stream version;  typically "87a" or "89a"."*/

    /* Graphic Control Extension Information
     */

    /* If _SGIFDFlags.gceUseTransparency is set [and
       _SGIFDFlags.gcePresent must be set, as well], then this
       instance variable will hold the index of the color within
       the local/global color table that should be rendered fully
       transparent.
     */
	unsigned char 		gceTransparentColorIndex;/*"transparent color"*/

    /* Logical Screen Descriptor
     */
	unsigned short		lsdWidth;/*"logical screen width"*/
	unsigned short		lsdHeight;/*"logical screen height"*/

	unsigned char   	lsdColorResolution;/*"logical screen resolution"*/
	unsigned short		lsdGlobalColorTableSize;/*"ls table size"*/
	unsigned char		lsdBackgroundIndex;/*"ls background color index"*/

	/* Global COLOR TABLE

	   Always allocated to the maximum size [if an image is decoded
	   that resuses a previous GCT, but the new image's GCT size is
	   defined to be larger than the previous GCT, this prevents
	   serious memory access errors-- but does not prevent the new
	   image from decoding incorrectly.  This is as the gif89a spec
	   defines things to be.

       Unlike the gif spec, this color table is designed to
       contain 256 32 bit color entries-- that is 256 8 bit sample
       RGBA entries.
	 */
	unsigned char		globalColorTable[GCT_MAX_BYTES]; /*"color table"*/

    /* Image Descriptor Variables
       
       The following iVars are set and used during the image decoding
       process. They only remain valid through the decoding of a
       single <image descriptor>.  There main purpose is to allow
       for the internal implementation to be broken up across multiple
       methods without requiring HUGE argument lists-- that and for
       abstract debugging purposes.

	   See also the Image Descriptor FLAGS above
     */

    /* Dimensions and Location of current image descriptor
     */
	unsigned short 		idX;/*" local image descriptor X location "*/
	unsigned short 		idY;/*" local image descriptor Y location "*/
	unsigned short		idWidth;/*" local image descriptor width "*/
	unsigned short		idHeight;/*" local image descriptor height "/

    /* Size of and pointer to Local Color Table-- note:  localColorTable
       will point to globalColorTable if there is no localColorTable
       present.
     */
	unsigned char       lctSize;/*" local color table size "*/
	unsigned char 		*localColorTable;/*" local color table "*/

	LWZState 			*decompressionState; /*"LWZ decompression engine"*/
}

/*"
 * Instantiation
"*/
+ sharedInstance;

/*"
 * Class query
"*/
+ (const char *const *)imageUnfilteredFileTypes;
+ (BOOL)canLoadFromStream:(NXStream *)stream;

/*" Custom GIF Features
 "*/
- (BOOL) produceSilhouette;
- (void) setProduceSilhouette:(BOOL) aFlag;

- (BOOL) gctZeroUnused;
- (void) setGctZeroUnused:(BOOL) aFlag;

- (void) setShowColorTable:(BOOL) aFlag;
- (BOOL) showColorTable;
@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.