+bool wxGIFHandler::SetupCompress(wxOutputStream *stream, int bpp)
+{
+ m_LZBuf[0] = 0; // Nothing was output yet.
+ m_clearCode = (1 << bpp);
+ m_EOFCode = m_clearCode + 1;
+ m_runningCode = m_EOFCode + 1;
+ m_runningBits = bpp + 1; // Number of bits per code.
+ m_maxCode1 = 1 << m_runningBits; // Max. code + 1.
+ m_crntCode = FIRST_CODE; // Signal that this is first one!
+ m_crntShiftState = 0; // No information in CrntShiftDWord.
+ m_crntShiftDWord = 0;
+
+ // Clear hash table and send Clear to make sure the decoder does the same.
+ ClearHashTable();
+
+ return wxGIFHandler_WriteByte(stream, (wxUint8)bpp)
+ && CompressOutput(stream, m_clearCode);
+}
+
+bool wxGIFHandler::CompressLine(wxOutputStream *stream,
+ const wxUint8 *line, int lineLen)
+{
+ int i = 0, crntCode, newCode;
+ unsigned long newKey;
+ wxUint8 pixel;
+ if (m_crntCode == FIRST_CODE) // It's first time!
+ crntCode = line[i++];
+ else
+ crntCode = m_crntCode; // Get last code in compression.
+
+ while (i < lineLen)
+ {
+ // Decode lineLen items.
+ pixel = line[i++]; // Get next pixel from stream.
+ // Form a new unique key to search hash table for the code combines
+ // crntCode as Prefix string with Pixel as postfix char.
+ newKey = (((unsigned long) crntCode) << 8) + pixel;
+ if ((newCode = ExistsHashTable(newKey)) >= 0)
+ {
+ // This Key is already there, or the string is old one, so
+ // simply take new code as our crntCode:
+ crntCode = newCode;
+ }
+ else
+ {
+ // Put it in hash table, output the prefix code, and make our
+ // crntCode equal to Pixel.
+ if (!CompressOutput(stream, crntCode))