Ipelib: ipe::Bitmap Class Reference

Ipelib

- Main Page
- Related Pages
- Modules
- Classes

- Class List
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
ipe::Bitmap Class Reference
Ipe Base

`#include <ipebitmap.h>`

## Classes
class | MRenderData

## Public Types
enum | TFilter { EDirect, EFlateDecode, EDCTDecode }
enum | TColorSpace { EDeviceRGB, EDeviceGray, EDeviceCMYK }

## Public Member Functions
| Bitmap ()
| Bitmap (int width, int height, TColorSpace colorSpace, int bitsPerComponent, Buffer data, TFilter filter, bool deflate=false)
| Bitmap (const XmlAttributes &attr, String data)
| Bitmap (const XmlAttributes &attr, Buffer data)
| Bitmap (const Bitmap &rhs)
| ~Bitmap ()
Bitmap & | operator= (const Bitmap &rhs)
void | saveAsXml (Stream &stream, int id, int pdfObjNum=-1) const
bool | isNull () const
bool | equal (Bitmap rhs) const
TColorSpace | colorSpace () const
TFilter | filter () const
int | components () const
int | bitsPerComponent () const
int | width () const
int | height () const
int | colorKey () const
void | setColorKey (int key)
const char * | data () const
int | size () const
int | objNum () const
void | setObjNum (int objNum) const
MRenderData * | renderData () const
void | setRenderData (MRenderData *data) const
Buffer | pixelData () const
bool | operator== (const Bitmap &rhs) const
bool | operator!= (const Bitmap &rhs) const
bool | operator< (const Bitmap &rhs) const

## Static Public Member Functions
static const char * | readJpegInfo (FILE *file, int &width, int &height, Vector &dotsPerInch, TColorSpace &colorSpace, int &bitsPerComponent)
static Bitmap | readJpeg (const char *fname, Vector &dotsPerInch, const char *&errmsg)
static Bitmap | readPNG (const char *fname, bool deflate, Vector &dotsPerInch, const char *&errmsg)

## Detailed Description

A bitmap.

Bitmaps are explicitely shared using reference-counting. Copying is cheap, so Bitmap objects are meant to be passed by value.

The bitmap can cache data to speed up rendering. This data can be set only once (as the bitmap is conceptually immutable).

The bitmap also provides a slot for short-term storage of an "object number". The PDF embedder, for instance, sets it to the PDF object number when embedding the bitmap, and can reuse it when "drawing" the bitmap.

## Member Enumeration Documentation

enum ipe::Bitmap::TFilter

Enumerator
EDirect |
EFlateDecode |
EDCTDecode |

enum ipe::Bitmap::TColorSpace

Enumerator
EDeviceRGB |
EDeviceGray |
EDeviceCMYK |

## Constructor & Destructor Documentation

Bitmap::Bitmap | ( |  | ) |

Default constructor constructs null bitmap.

Referenced by readJpeg(), and ipe::Bitmap::MRenderData::~MRenderData().

Bitmap::Bitmap | ( | int | width,
|  | int | height,
|  | TColorSpace | colorSpace,
|  | int | bitsPerComponent,
|  | Buffer | data,
|  | TFilter | filter,
|  | bool | deflate = `false`
| ) |  |

Create a new image.

filter specifies the format of the data. If filter is EDirect, then setting deflate compresses the bitmap and changes the filter to EFlateDecode.

References bitsPerComponent(), colorSpace(), data(), ipe::Buffer::data(), ipe::DeflateStream::deflate(), EDeviceCMYK, EDeviceGray, EDeviceRGB, EDirect, EFlateDecode, filter(), height(), ipe::Buffer::size(), and width().

Bitmap::Bitmap | ( | const XmlAttributes & | attr,
|  | String | data
| ) |  |

Create from XML stream.

References ipe::String::data(), ipe::Base64Source::getChar(), ipe::Lex::getHexByte(), and ipe::String::size().

Bitmap::Bitmap | ( | const XmlAttributes & | attr,
|  | Buffer | data
| ) |  |

Create from XML using external raw data.

References bitsPerComponent(), components(), data(), EDCTDecode, EDeviceCMYK, EDeviceGray, EDeviceRGB, EDirect, EFlateDecode, ipe::Lex::getHexNumber(), ipe::Lex::getInt(), ipe::XmlAttributes::has(), height(), ipe::Buffer::size(), and width().

Bitmap::Bitmap | ( | const Bitmap & | rhs | ) |

Copy constructor.

Since Bitmaps are reference counted, this is very fast.

Bitmap::~Bitmap | ( |  | ) |

Destructor.

## Member Function Documentation

Bitmap & Bitmap::operator= | ( | const Bitmap & | rhs | ) |

Assignment operator (takes care of reference counting).

Very fast.

void Bitmap::saveAsXml | ( | Stream & | stream,
|  | int | id,
|  | int | pdfObjNum = `-1`
| ) |  | const

Save bitmap in XML stream.

References bitsPerComponent(), ipe::Base64Stream::close(), colorSpace(), data(), EDCTDecode, EDeviceCMYK, EDeviceGray, EDeviceRGB, EFlateDecode, filter(), height(), ipe::Base64Stream::putChar(), size(), and width().

Referenced by ipe::Page::saveAsIpePage(), ipe::Document::saveAsXml(), ipe::StyleSheet::saveAsXml(), and ipe::Page::saveSelection().

bool ipe::Bitmap::isNull | ( |  | ) | const
| inline

Is this a null bitmap?

Referenced by ipe::ImlParser::parseObject().

bool Bitmap::equal | ( | Bitmap | rhs | ) | const

Bitmap::TColorSpace ipe::Bitmap::colorSpace | ( |  | ) | const
| inline

Return the color space of the image.

Referenced by Bitmap(), readJpeg(), saveAsXml(), and ipe::PdfWriter::~PdfWriter().

Bitmap::TFilter ipe::Bitmap::filter | ( |  | ) | const
| inline

Return the data filter of the image data.

Referenced by Bitmap(), pixelData(), saveAsXml(), and ipe::PdfWriter::~PdfWriter().

int ipe::Bitmap::components | ( |  | ) | const
| inline

Return number of components per pixel.

Referenced by Bitmap(), and pixelData().

int ipe::Bitmap::bitsPerComponent | ( |  | ) | const
| inline

Return the number of bits per component.

Referenced by Bitmap(), pixelData(), readJpeg(), saveAsXml(), and ipe::PdfWriter::~PdfWriter().

int ipe::Bitmap::width | ( |  | ) | const
| inline

Return width of pixel array.

Referenced by Bitmap(), ipe::CairoPainter::doDrawBitmap(), pixelData(), readJpeg(), saveAsXml(), and ipe::PdfWriter::~PdfWriter().

int ipe::Bitmap::height | ( |  | ) | const
| inline

Return height of pixel array.

Referenced by Bitmap(), ipe::CairoPainter::doDrawBitmap(), pixelData(), readJpeg(), saveAsXml(), and ipe::PdfWriter::~PdfWriter().

int Bitmap::colorKey | ( |  | ) | const

Return rgb representation of the transparent color.

Returns -1 if the bitmap is not color keyed.

Referenced by pixelData(), and ipe::PdfWriter::~PdfWriter().

void Bitmap::setColorKey | ( | int | key | ) |

Set transparent color.

Use key == -1 to disable color key.

Referenced by readPNG().

const char * ipe::Bitmap::data | ( |  | ) | const
| inline

Return a pointer to the image data (in PDF arrangement).

Referenced by Bitmap(), pixelData(), saveAsXml(), setRenderData(), and ipe::PdfWriter::~PdfWriter().

int ipe::Bitmap::size | ( |  | ) | const
| inline

Return size (number of bytes) of image data (in PDF arrangement).

Referenced by saveAsXml(), and ipe::PdfWriter::~PdfWriter().

int ipe::Bitmap::objNum | ( |  | ) | const
| inline

Return object number of the bitmap.

Referenced by ipe::PdfPainter::doDrawBitmap(), ipe::Image::saveAsXml(), ipe::Document::saveAsXml(), ipe::StyleSheet::saveAsXml(), and setObjNum().

void ipe::Bitmap::setObjNum | ( | int | objNum | ) | const
| inline

Set object number of the bitmap.

References objNum().

Referenced by ipe::Page::saveAsIpePage(), ipe::Page::saveSelection(), and ipe::PdfWriter::~PdfWriter().

Bitmap::MRenderData * ipe::Bitmap::renderData | ( |  | ) | const
| inline

Return cached bitmap for rendering.

Referenced by ipe::CairoPainter::doDrawBitmap().

void Bitmap::setRenderData | ( | MRenderData * | data | ) | const

Set a cached bitmap for fast rendering.

References data().

Referenced by ipe::CairoPainter::doDrawBitmap().

Buffer Bitmap::pixelData | ( |  | ) | const

Convert bitmap data to a height x width pixel array in rgb format.

Returns empty buffer if it cannot decode the bitmap information. Otherwise, returns a buffer of size width() * height() uint32_t's.

References bitsPerComponent(), colorKey(), components(), data(), ipe::Buffer::data(), EDCTDecode, EDirect, EFlateDecode, filter(), height(), ipe::Buffer::size(), and width().

Referenced by ipe::CairoPainter::doDrawBitmap().

bool ipe::Bitmap::operator== | ( | const Bitmap & | rhs | ) | const
| inline

Two bitmaps are equal if they share the same data.

bool ipe::Bitmap::operator!= | ( | const Bitmap & | rhs | ) | const
| inline

Two bitmaps are equal if they share the same data.

bool ipe::Bitmap::operator< | ( | const Bitmap & | rhs | ) | const
| inline

Less operator, to be able to sort bitmaps.

The checksum is used, when it is equal, the shared address. This guarantees that bitmaps that are == (share their implementation) are next to each other, and blocks of them are next to blocks that are identical in contents.

const char * Bitmap::readJpegInfo | ( | FILE * | file,
|  | int & | width,
|  | int & | height,
|  | Vector & | dotsPerInch,
|  | TColorSpace & | colorSpace,
|  | int & | bitsPerComponent
| ) |  |
| static

Read information about JPEG image from file.

Returns NULL on success, an error message otherwise.

References EDeviceCMYK, EDeviceGray, and EDeviceRGB.

Referenced by readJpeg().

Bitmap Bitmap::readJpeg | ( | const char * | fname,
|  | Vector & | dotsPerInch,
|  | const char *& | errmsg
| ) |  |
| static

Read JPEG image from file.

Returns the image as a DCT-encoded Bitmap. Sets dotsPerInch if the image file contains a resolution, otherwise sets it to (0,0). If reading the file fails, returns a null Bitmap, and sets the error message errmsg.

References Bitmap(), bitsPerComponent(), colorSpace(), ipe::String::data(), EDCTDecode, ipe::Platform::fopen(), height(), ipe::Platform::readFile(), readJpegInfo(), ipe::String::size(), and width().

Bitmap Bitmap::readPNG | ( | const char * | fname,
|  | bool | deflate,
|  | Vector & | dotsPerInch,
|  | const char *& | errmsg
| ) |  |
| static

Read PNG image from file.

Returns the image as a Bitmap. It will be compressed if deflate is set. Sets dotsPerInch if the image file contains a resolution, otherwise sets it to (0,0). If reading the file fails, returns a null Bitmap, and sets the error message errmsg.

References ipe::Buffer::data(), EDirect, ipe::Platform::fopen(), and setColorKey().

The documentation for this class was generated from the following files:

- ipebitmap.h
- ipebitmap.cpp
- ipebitmap_unix.cpp
- ipebitmap_win.cpp