1 //////////////////////////////////////////////////////////////////////////////// 2 // 3 // File: GIFSave.h 4 // 5 // Date: December 1999 6 // 7 // Author: Daniel Switkin 8 // 9 // Copyright 2003 (c) by Daniel Switkin. This file is made publically available 10 // under the BSD license, with the stipulations that this complete header must 11 // remain at the top of the file indefinitely, and credit must be given to the 12 // original author in any about box using this software. 13 // 14 //////////////////////////////////////////////////////////////////////////////// 15 16 #ifndef GIFSAVE_H 17 #define GIFSAVE_H 18 19 #include <DataIO.h> 20 #include <Bitmap.h> 21 #include "SavePalette.h" 22 #include "SFHash.h" 23 #include "Prefs.h" 24 25 #define HASHSIZE 9973 26 #define HASHSTEP 2039 27 28 #define HASH(index, lastbyte) (((lastbyte << 8) ^ index) % HASHSIZE) 29 30 class GIFSave { 31 public: 32 GIFSave(BBitmap *bitmap, BPositionIO *output); 33 ~GIFSave(); 34 35 bool fatalerror; 36 37 private: 38 void WriteGIFHeader(); 39 void WriteGIFControlBlock(); 40 void WriteGIFImageHeader(); 41 void WriteGIFImageData(); 42 void OutputCode(short code, int BITS, bool flush=false); 43 44 unsigned char NextPixel(int pixel); 45 void InitFrame(); 46 void ResetHashtable(); 47 int CheckHashtable(int s, unsigned char c); 48 void AddToHashtable(int s, unsigned char c); 49 50 BPositionIO *output; 51 BBitmap *bitmap; 52 SavePalette *palette; 53 SFHash *hash; 54 Prefs *prefs; 55 56 short *code_value, *prefix_code; 57 unsigned char *append_char; 58 int BITS, max_code; 59 char code_size; 60 short clear_code, end_code, next_code; 61 int string_code; 62 unsigned char character; 63 int table_size; 64 65 int bit_count; 66 unsigned int bit_buffer; 67 int byte_count; 68 unsigned char byte_buffer[257]; 69 int pass, row, pos; 70 71 unsigned char *gifbits; 72 73 int width, height; 74 75 // For dithering 76 int32 *red_error, *green_error, *blue_error; 77 int16 red_side_error, green_side_error, blue_side_error; 78 }; 79 80 #endif 81 82