Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

pdf::graph::CJpegImage Class Reference

an PDF image xobject create by an JPEG image file More...

#include <JpegImage.hh>

Inheritance diagram for pdf::graph::CJpegImage:

Inheritance graph
[legend]
Collaboration diagram for pdf::graph::CJpegImage:

Collaboration graph
[legend]
List of all members.

Public Methods

Protected Methods

Private Methods

Private Attributes


Detailed Description

an PDF image xobject create by an JPEG image file

like the graph::CImage class, this class represent an PDF image xobject. the only difference is that it is for JPEG image files only.

this class exists because of performance. the same job can be done by first reading and decoding the JPEG image file to an image::CImage and create a graph::CImage object, which is also an PDF image xobject. the difference is that this class won't decode the pixel data. it just read the header for information like width, height and colour space etc. it can increase performance by copy the JPEG file directly to the internel buffer, without decoding the image pixels.


Constructor & Destructor Documentation

pdf::graph::CJpegImage::CJpegImage const std::string &    filename
 

the constructor initialize the object with the JPEG filename.

Parameters:
filename  the filename of the JPEG image file

00052     : m_filename( filename )
00053 {
00054     ReadHeader( ) ;
00055 }

pdf::graph::CJpegImage::~CJpegImage  
 

nothing to destroy in destructor. it is a good design.

00060 {
00061 }


Member Function Documentation

core::CObject * pdf::graph::CJpegImage::Dup   const [virtual]
 

virtual copy constructor.

Implements pdf::core::CObject.

00066 {
00067     return new CJpegImage( *this ) ;
00068 }

const core::CObjRef pdf::graph::CJpegImage::Write core::CFile   file const [virtual]
 

write to PDF file. not used directly by client.

Implements pdf::common::CResource.

00080 {
00081     return file.AddObj( new core::CProxyObj( this ) ) ;
00082 }

const image::CHeader & pdf::graph::CJpegImage::Header   const
 

return the header of the image.

00073 {
00074     return m_header ;
00075 }

const CJpegImage::CByteVec & pdf::graph::CJpegImage::GetContent CByteVec &    output const [protected, virtual]
 

getting the image content is easy. just read the file and put the bytes in the output vector.

Implements pdf::core::CStream.

00088 {
00089     using namespace std ;
00090     ifstream file( m_filename.c_str( ), ios::in | ios::binary ) ;
00091     output.assign( istreambuf_iterator<char>( file ),
00092                    istreambuf_iterator<char>( ) ) ;
00093     return output ;
00094 }

void pdf::graph::CJpegImage::MakeDictionary core::CDictionary   dict const [protected]
 

this function will call GetImageInfo() to read image width/height, and then put it in an PDF dictionary.

00100 {
00101     // base class stuff
00102     CImgBase::MakeDictionary( dict ) ;
00103 
00104     // JPEG images must use DCT decode filter
00105     dict.AddPair( "Filter", "DCTDecode" ) ;
00106 }

void pdf::graph::CJpegImage::ReadHeader   [private]
 

this function will open the image file, and read its header for the image information. the image information will be returned by reference in the parameters.

00113 {
00114     using namespace image ;
00115 
00116     struct jpeg_decompress_struct cinfo ;
00117     struct jpeg_error_mgr jerr ;
00118 
00119     cinfo.err = jpeg_std_error( &jerr ) ;
00120     jpeg_create_decompress( &cinfo ) ;
00121 
00122     // open the file in binary mode
00123     FILE *infile = fopen( m_filename.c_str( ), "rb" ) ;
00124 
00125     // throw exception in case of any error
00126     if ( infile == NULL)
00127         throw util::CFileError( errno ) ;
00128 
00129     // read JPEG image file header
00130     jpeg_stdio_src( &cinfo, infile ) ;
00131     jpeg_read_header( &cinfo, TRUE ) ;
00132     
00133     // support only RGB and grayscale for now
00134     CColourSpace colour_space ;
00135     int channel_per_pixel = 0 ;
00136     switch ( cinfo.out_color_space )
00137     {
00138         case JCS_RGB :
00139             colour_space = image::CColourSpace::RGB( ) ;
00140             channel_per_pixel = 3 ;
00141             break ;
00142 
00143         case JCS_GRAYSCALE :
00144             colour_space = image::CColourSpace::Gray( ) ;
00145             channel_per_pixel = 1 ;
00146             break ;
00147             
00148         default :       break ;
00149     }
00150 
00151     // store info in header object.
00152     // hard coded to use 8 bit per channel
00153     m_header.Assign( cinfo.image_width, cinfo.image_height, channel_per_pixel,
00154                      8, colour_space, cinfo.X_density, cinfo.Y_density ) ;
00155 
00156     // clean up
00157     jpeg_destroy_decompress( &cinfo ) ;
00158     fclose( infile ) ;
00159 }


Member Data Documentation

const std::string pdf::graph::CJpegImage::m_filename [private]
 

filename of the JPEG file

image::CHeader pdf::graph::CJpegImage::m_header [private]
 

image header of the JPEG file


The documentation for this class was generated from the following files:
Generated on Sun Feb 2 09:17:24 2003 for libpdf++ by doxygen1.2.16