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

pdf::graph::CImage Class Reference

PDF image class. More...

#include <Image.hh>

Inheritance diagram for pdf::graph::CImage:

Inheritance graph
Collaboration diagram for pdf::graph::CImage:

Collaboration graph
List of all members.

Public Types

Public Methods

Protected Methods

Private Methods

Static Private Methods

Private Attributes

Detailed Description

PDF image class.

an image is a PDF XObject that holds an array of pixel and information about its format. this class represent a PDF image XObject. it actually contain the pixels. a document can have multiple instance of a single image, with different transformation (such as scaling and position). such instances are represented by the page::CXObjInst class.

an image is a resource (as all XObjects do), so it must be added to the document before use.

this class is different from the image::CImage class, although they have the same name but different namespaces. the image::CImage class serves as a container of pixels and its format. It is totally PDF independent, so it is not put in the pdf namespace. In contrast, this class acts as a PDF image XObject. it concentrated in how to store the underlying image::CImage in an PDF document.

Constructor & Destructor Documentation

pdf::graph::CImage::CImage const image::CImage &    image,
EFilter    filter = none

constructor initialize the object. an PDF image XObject contains the actual image data (stored in image::CImage) and its filter.

image  actual image data which will be stored in the PDF document
filter  PDF stream filter. it specify how to compress the pixel data when storing in the PDF file. see core::CStream for details.

00049     : m_image( image ), m_filter( filter )
00050 {
00051 }


destructor does nothing

00056 {
00057 }

Member Function Documentation

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

virtual copy constructor.

Implements pdf::core::CObject.

00062 {
00063     return new CImage( *this ) ;
00064 }

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

write the resource to the PDF file

Implements pdf::common::CResource.

00128 {
00129     return file.AddObj( new core::CProxyObj( this ) ) ;
00130 }

const image::CImage & pdf::graph::CImage::Image   const

gets the underlying image container. it will be the same as the one passed to the constructor if it is not modified.

00080 {
00081     return m_image ;
00082 }

const core::CStream::CByteVec & pdf::graph::CImage::GetContent CByteVec &    output const [protected, virtual]

the derived classes should override this function in order to provide the stream data. the prototype of this function is strange, but it allows the the derived classes to return a constrant reference of its own vector, such that a data copy can be avoided. in other cases, the derived classes can put the stream data to the output vector and return it.

output  a temperatory buffer that can be used to stored data.
the actual stream data that will be stored in the stream object. for classes that has an internel buffer, it can just return it and ignores the output parameter. otherwise it can put the data in the output buffer and return it.

Implements pdf::core::CStream.

00067 {
00068     switch ( m_filter )
00069     {
00070         case inflate :  return Inflate( output ) ;
00071         case DCT :      return DCTEncode( output ) ;
00072         default :       return m_image.Pixels( ) ;
00073     }
00074 }

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

this function will add the necessary fields to the stream dictionary. these fields include image width, height, colour space etc. they are handled by the CImgBase::MakeDictionary( ) function.

00137 {
00138     CImgBase::MakeDictionary( dict ) ;
00140     if ( m_filter != none )
00141         dict.AddPair( "Filter", FilterName( m_filter ) ) ;
00142 }

const core::CStream::CByteVec & pdf::graph::CImage::DCTEncode CByteVec &    output const [private]

this function will encode the image using the DCT filter. according to the PDF spec, the whole JPEG image file should be stored in the image xobject stream, including the JPEG image header. so this function will simple call the CJpegEncoder class to encode the image in a string stream. then copy the string stream to the output byte vector.

00101 {
00102     using namespace std ;
00104     // encode the image into a string stream
00105     stringstream str ;
00106     image::CJpegEncoder jpeg ;
00107     jpeg.Encode( m_image, str.rdbuf( ) ) ;
00109     // copy the string stream to the output byte vector
00110     output.assign( istreambuf_iterator<char>( str ),
00111                    istreambuf_iterator<char>( ) ) ;
00113     return output ;
00114 }

const core::CStream::CByteVec & pdf::graph::CImage::Inflate CByteVec &    output const [private]

this function will encode the image using the deflate filter. the PDF spec said that only the pixels should be put in the image xobject stream. it is not the same as the DCT filter, which includes the whole image file to the stream.

00122 {
00123     zlib::Compress( m_image.Pixels( ), output ) ;
00124     return output ;
00125 }

const std::string & pdf::graph::CImage::FilterName EFilter    filter [static, private]

helper functions to lookup the filter name for a given filter enum.

00147 {
00148     assert( filter >= inflate || filter < none ) ;
00150     static const std::string table[] =
00151     {
00152         "FlateDecode",
00153         "DCTDecode"
00154     } ;
00156     return table[filter] ;
00157 }

Member Data Documentation

image::CImage pdf::graph::CImage::m_image [private]

the real image object

EFilter pdf::graph::CImage::m_filter [private]

the filter

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