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 24 #include "GIFTranslator.h" 25 26 #define HASHSIZE 9973 27 #define HASHSTEP 2039 28 29 #define HASH(index, lastbyte) (((lastbyte << 8) ^ index) % HASHSIZE) 30 31 class GIFSave { 32 public: 33 GIFSave(BBitmap* bitmap, BPositionIO* output, TranslatorSettings* settings); 34 ~GIFSave(); 35 36 bool fatalerror; 37 38 private: 39 void WriteGIFHeader(); 40 void WriteGIFControlBlock(); 41 void WriteGIFImageHeader(); 42 void WriteGIFImageData(); 43 void OutputCode(short code, int BITS, bool flush=false); 44 45 unsigned char NextPixel(int pixel); 46 void InitFrame(); 47 void ResetHashtable(); 48 int CheckHashtable(int s, unsigned char c); 49 void AddToHashtable(int s, unsigned char c); 50 51 BPositionIO *output; 52 BBitmap *bitmap; 53 SavePalette *palette; 54 SFHash *hash; 55 TranslatorSettings *fSettings; 56 57 short *code_value, *prefix_code; 58 unsigned char *append_char; 59 int BITS, max_code; 60 char code_size; 61 short clear_code, end_code, next_code; 62 int string_code; 63 unsigned char character; 64 int table_size; 65 66 int bit_count; 67 unsigned int bit_buffer; 68 int byte_count; 69 unsigned char byte_buffer[257]; 70 int pass, row, pos; 71 72 unsigned char *gifbits; 73 74 int width, height; 75 76 // For dithering 77 int32 *red_error, *green_error, *blue_error; 78 int16 red_side_error, green_side_error, blue_side_error; 79 }; 80 81 #endif 82 83