home *** CD-ROM | disk | FTP | other *** search
- #include "jpegenco.h"
-
- using namespace std ;
-
- JpegEncoder::JpegEncoder (ostream &strm)
- {
- output_stream = &strm ;
- bit_count = 0 ;
- return ;
- }
- void JpegEncoder::OutputByte (UBYTE1 data)
- {
- output_stream->write ((char *) &data, 1) ;
- return ;
- }
-
- void JpegEncoder::OutputBits (int bits, unsigned int count)
- {
- for (unsigned int ii = 0 ; ii < count ; ++ ii)
- {
- bit_buffer <<= 1 ;
- ++ bit_count ;
- bit_buffer |= ((bits >> (count - ii - 1)) & 0x1) ;
- if (bit_count == 8)
- {
- OutputByte (bit_buffer) ;
- bit_buffer = 0 ;
- bit_count = 0 ;
- }
- }
- return ;
- }
-
- void JpegEncoder::FlushBitBuffer ()
- {
- if (bit_count != 0)
- {
- bit_buffer <<= (8 - bit_count) ;
- OutputByte (bit_buffer) ;
- }
- return ;
- }
-