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// Additional authors: Stephan Aßmus, <superstippi@gmx.de> 17// Philippe Saint-Pierre, <stpere@gmail.com> 18// John Scipione, <jscipione@gmail.com> 19 20#ifndef GIF_SAVE_H 21#define GIF_SAVE_H 22 23 24#include <DataIO.h> 25#include <Bitmap.h> 26#include "SavePalette.h" 27#include "SFHash.h" 28 29#include "GIFTranslator.h" 30 31 32#define HASHSIZE 9973 33#define HASHSTEP 2039 34 35#define HASH(index, lastbyte) (((lastbyte << 8) ^ index) % HASHSIZE) 36 37 38class GIFSave { 39public: 40 GIFSave(BBitmap* bitmap, BPositionIO* output, 41 TranslatorSettings* settings); 42 virtual ~GIFSave(); 43 44 bool fatalerror; 45 46private: 47 status_t WriteGIFHeader(); 48 status_t WriteGIFControlBlock(); 49 status_t WriteGIFImageHeader(); 50 status_t WriteGIFImageData(); 51 status_t OutputCode(short code, int BITS, 52 bool flush = false); 53 54 unsigned char NextPixel(int pixel); 55 void InitFrame(); 56 void ResetHashtable(); 57 int CheckHashtable(int s, unsigned char c); 58 void AddToHashtable(int s, unsigned char c); 59 60 BPositionIO* output; 61 BBitmap* bitmap; 62 SavePalette* palette; 63 SFHash* hash; 64 TranslatorSettings* fSettings; 65 66 short* code_value; 67 short* prefix_code; 68 69 unsigned char* append_char; 70 int BITS; 71 int max_code; 72 char code_size; 73 short clear_code; 74 short end_code; 75 short next_code; 76 int string_code; 77 unsigned char character; 78 int table_size; 79 80 int bit_count; 81 unsigned int bit_buffer; 82 int byte_count; 83 unsigned char byte_buffer[257]; 84 int pass; 85 int row; 86 int pos; 87 88 unsigned char* gifbits; 89 90 int width; 91 int height; 92 93 // For dithering 94 int32* red_error; 95 int32* green_error; 96 int32* blue_error; 97 98 int16 red_side_error; 99 int16 green_side_error; 100 int16 blue_side_error; 101}; 102 103 104#endif // GIF_SAVE_H 105