home *** CD-ROM | disk | FTP | other *** search
- #ifndef __PNGENCOD_H
- #define __PNGENCOD_H
- //
- // Copyright (c) 1997,1998 Colosseum Builders, Inc.
- // All rights reserved.
- //
- // Colosseum Builders, Inc. makes no warranty, expressed or implied
- // with regards to this software. It is provided as is.
- //
- // See the README.TXT file that came with this software for restrictions
- // on the use and redistribution of this file or send E-mail to
- // info@colosseumbuilders.com
- //
-
- //
- // Title: PNG Encoder Class Definition
- //
- // Author: John M. Miano miano@colosseumbuilders.com
- //
- // Description:
- //
- // This class implements PNG encoding.
- //
-
-
-
- #include "png.h"
- #include "bitimage.h"
-
- class PngHuffmanEncoder ;
-
- class PngEncoder : public BitmapImageEncoder
- {
- public:
- PngEncoder () ;
- PngEncoder (const PngEncoder &) ;
- virtual ~PngEncoder () ;
- PngEncoder &operator=(const PngEncoder &) ;
-
- void WriteImage (std::ostream &, BitmapImage &) ;
-
- // Property functions for predefined tEXt strings.
- void SetTitle (const std::string &) ;
- std::string GetTitle () const ;
-
- void SetAuthor (const std::string &) ;
- std::string GetAuthor () const ;
-
- void SetDescription (const std::string &) ;
- std::string GetDescription () const ;
-
- void SetCopyright (const std::string &) ;
- std::string GetCopyright () const ;
-
- void SetSoftware (const std::string &) ;
- std::string GetSoftware () const ;
-
- void SetDisclaimer (const std::string &) ;
- std::string GetDisclaimer () const ;
-
- void SetWarning (const std::string &) ;
- std::string GetWarning () const ;
-
- void SetSource (const std::string &) ;
- std::string GetSource () const ;
-
- void SetComment (const std::string &) ;
- std::string GetComment () const ;
-
- enum CompressionLevel
- {
- FastestCompression = 0,
- FastCompression = 1,
- DefaultCompression = 2,
- MaximumCompression = 3,
- } ;
-
- void SetCompressionLevel (CompressionLevel) ;
- CompressionLevel GetCompressionLevel () const ;
-
- void SetUseFilters (bool) ;
- bool GetUseFilters () const ;
-
- unsigned long GetBlockSize () const ;
- void SetBlockSize (unsigned long) ;
-
- protected:
- void Initialize () ;
- void DoCopy (const PngEncoder &) ;
-
- private:
- struct HashEntry
- {
- UBYTE2 index ; // Index into the LZ Window
- HashEntry *next ; // Next collision entry
- HashEntry *previous ;
- } ;
-
- void LongestMatch (unsigned int &length,
- unsigned int &offset) ;
- unsigned int HashValue (unsigned int) ;
-
- void MoveHashEntry (unsigned int entry, unsigned int hashvalue) ;
-
- HashEntry *hash_values ;
- HashEntry *hash_table ;
-
- BitmapImage *current_image ;
- std::ostream *output_stream ;
-
- unsigned int search_limit ;
-
- PngHuffmanEncoder *distance_table ;
- PngHuffmanEncoder *length_table ;
- PngHuffmanEncoder *length_length_table ;
-
- typedef void (PngEncoder::*LENGTHFUNCTION) (unsigned int index,
- unsigned int code,
- unsigned int length,
- unsigned int extra) ;
- void GatherLengthCounts (unsigned int,
- unsigned int code,
- unsigned int,
- unsigned int) ;
- void OutputLengthCounts (unsigned int index,
- unsigned int code,
- unsigned int extra,
- unsigned int value) ;
-
- void FindLengthCodes (LENGTHFUNCTION, UBYTE1 lengths [], unsigned int count) ;
-
- bool ProcessImageData () ;
-
- UBYTE1 *output_buffer ;
- UBYTE4 chunk_type ;
- UBYTE4 byte_position ;
- unsigned int bit_position ;
- void StartChunk (const char type [5]) ;
- void WriteCurrentChunk () ;
- void OutputBlock (const void *data, unsigned int length) ;
- void OutputByte (UBYTE1) ;
- void OutputDataBits (unsigned int data, unsigned int length) ;
- void FlushBitBuffer () ;
- void OutputAdler () ;
-
- void FreeBuffers () ;
- void FillBuffer (unsigned int count) ;
-
- unsigned int row_width ;
- void WriteText (const std::string &keyword, const std::string &value) ;
- void WriteTextBlocks () ;
-
- void CallProgressFunction (unsigned int) ;
-
- std::string title_string ;
- std::string author_string ;
- std::string description_string ;
- std::string copyright_string ;
- std::string software_string ;
- std::string disclaimer_string ;
- std::string warning_string ;
- std::string source_string ;
- std::string comment_string ;
-
- enum { FilterBufferCount = 5, } ;
- UBYTE1 *filter_buffers [FilterBufferCount] ;
- unsigned int current_filter ;
- unsigned int filter_mask ;
- unsigned int filter_width ;
- void FilterRow (unsigned int row) ;
-
- void DoWrite () ;
-
- CompressionLevel compression_level ;
-
- void InitializeHashTable () ;
- void InitializeLZWindow () ;
- void OutputDeflateHeader (bool lastblock) ;
- void OutputZLibHeader () ;
- void WriteImageData () ;
-
- UBYTE4 adler_value ;
- UBYTE1 *lz_window ;
- UBYTE2 *lookahead_buffer ;
- unsigned int lookahead_position ;
- unsigned int lz_position ;
- int image_row ; // Must be Signed
- unsigned int image_col ;
- bool image_end ;
-
- UBYTE2 *block_buffer ;
- unsigned int block_buffer_size ;
- unsigned int block_buffer_count ;
-
- void OutputBlockData () ;
- } ;
-
- inline void PngEncoder::SetTitle (const std::string &value)
- {
- title_string = value ;
- return ;
- }
-
- inline std::string PngEncoder::GetTitle () const
- {
- return title_string ;
- }
-
- inline void PngEncoder::SetAuthor (const std::string &value)
- {
- author_string = value ;
- return ;
- }
-
- inline std::string PngEncoder::GetAuthor () const
- {
- return author_string ;
- }
-
- inline void PngEncoder::SetDescription (const std::string &value)
- {
- description_string = value ;
- return ;
- }
-
- inline std::string PngEncoder::GetDescription () const
- {
- return description_string ;
- }
-
- inline void PngEncoder::SetCopyright (const std::string &value)
- {
- copyright_string = value ;
- return ;
- }
-
- inline std::string PngEncoder::GetCopyright () const
- {
- return copyright_string ;
- }
-
- inline void PngEncoder::SetSoftware (const std::string &value)
- {
- software_string = value ;
- return ;
- }
-
- inline std::string PngEncoder::GetSoftware () const
- {
- return software_string ;
- }
-
- inline void PngEncoder::SetDisclaimer (const std::string &value)
- {
- disclaimer_string = value ;
- return ;
- }
-
- inline std::string PngEncoder::GetDisclaimer () const
- {
- return disclaimer_string ;
- }
-
- inline void PngEncoder::SetWarning (const std::string &value)
- {
- warning_string = value ;
- return ;
- }
-
- inline std::string PngEncoder::GetWarning () const
- {
- return warning_string ;
- }
-
- inline void PngEncoder::SetSource (const std::string &value)
- {
- source_string = value ;
- return ;
- }
-
- inline std::string PngEncoder::GetSource () const
- {
- return source_string ;
- }
-
- inline void PngEncoder::SetComment (const std::string &value)
- {
- comment_string = value ;
- return ;
- }
-
- inline std::string PngEncoder::GetComment () const
- {
- return comment_string ;
- }
-
- inline unsigned long PngEncoder::GetBlockSize () const
- {
- return block_buffer_size ;
- }
-
- inline void PngEncoder::SetBlockSize (unsigned long value)
- {
- if (value < 500)
- block_buffer_size = 500 ;
- else
- block_buffer_size = value ;
- return ;
- }
-
-
- #endif
-
-
-