Ipelib: ipe::Bitmap Class Reference

Ipelib

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

`#include <ipebitmap.h>`

## Public Types
enum | Flags { ERGB = 0x01, EAlpha = 0x02, EDCT = 0x04, EInflate = 0x08, ENative = 0x10 }

## Public Member Functions
| Bitmap ()
| Bitmap (int width, int height, uint32_t flags, Buffer data)
| Bitmap (const XmlAttributes &attr, String data)
| Bitmap (const XmlAttributes &attr, Buffer data, Buffer smask)
| 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
int | width () const
int | height () const
bool | isJpeg () const
bool | isGray () const
bool | hasAlpha () const
int | colorKey () const
Buffer | pixelData ()
int | objNum () const
void | setObjNum (int objNum) const
std::pair< Buffer, Buffer > | embed () const
bool | operator== (const Bitmap &rhs) const
bool | operator!= (const Bitmap &rhs) const
bool | operator< (const Bitmap &rhs) const
void | savePixels (const char *fname)

## Static Public Member Functions
static const char * | readJpegInfo (FILE *file, int &width, int &height, Vector &dotsPerInch, uint32_t &flags)
static Bitmap | readJpeg (const char *fname, Vector &dotsPerInch, const char *&errmsg)
static Bitmap | readPNG (const char *fname, 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 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

## ◆ Flags

enum ipe::Bitmap::Flags

Enumerator
ERGB |
EAlpha |
EDCT |
EInflate |
ENative |

## Constructor & Destructor Documentation

## ◆ Bitmap() [1/5]

Bitmap::Bitmap | ( |  | ) |

Default constructor constructs null bitmap.

Referenced by readJpeg().

## ◆ Bitmap() [2/5]

Bitmap::Bitmap | ( | int | width,
|  | int | height,
|  | uint32_t | flags,
|  | Buffer | data
| ) |  |

Create a new image from given image data.

If you already have data in native-endian ARGB32 without premultiplication, pass it with flag ENative. Otherwise pass a byte stream and set ERGB and EAlpha correctly: EAlpha: each pixel starts with one byte of alpha channel, ERGB: each pixel has three bytes of R, G, B, in this order, otherwise each pixel has one byte of gray value.

References colorKey(), ipe::Buffer::data(), EAlpha, EDCT, EInflate, ENative, ERGB, hasAlpha(), height(), isGray(), isJpeg(), ipe::Buffer::size(), and width().

## ◆ Bitmap() [3/5]

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

Create from XML stream.

References ipe::String::data(), ipe::Buffer::data(), ipe::Base64Source::getChar(), ipe::Lex::getHexByte(), height(), isGray(), ipe::String::size(), and width().

## ◆ Bitmap() [4/5]

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

Create from XML using external raw data.

References EAlpha, EDCT, EInflate, ERGB, ipe::Lex::getHexNumber(), ipe::Lex::getInt(), ipe::XmlAttributes::has(), isJpeg(), ipe::String::left(), ipe::String::right(), and ipe::String::size().

## ◆ Bitmap() [5/5]

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

Copy constructor.

Since Bitmaps are reference counted, this is very fast.

## ◆ ~Bitmap()

Bitmap::~Bitmap | ( |  | ) |

Destructor.

## Member Function Documentation

## ◆ operator=()

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

Assignment operator (takes care of reference counting).

Very fast.

## ◆ saveAsXml()

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

Save bitmap in XML stream.

References ipe::Base64Stream::close(), colorKey(), embed(), hasAlpha(), height(), isGray(), isJpeg(), ipe::Base64Stream::putChar(), and width().

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

## ◆ isNull()

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

Is this a null bitmap?

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

## ◆ equal()

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

## ◆ width()

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

Return width of pixel array.

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

## ◆ height()

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

Return height of pixel array.

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

## ◆ isJpeg()

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

Is this bitmap a JPEG photo?

References EDCT.

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

## ◆ isGray()

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

Is the bitmap grayscale?

References ERGB.

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

## ◆ hasAlpha()

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

Does the bitmap have transparency?

Bitmaps with color key will return false here.

References EAlpha.

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

## ◆ colorKey()

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

Return the color key or -1 if none.

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

## ◆ pixelData()

Buffer Bitmap::pixelData | ( |  | ) |

Return pixels for rendering.

Returns empty buffer if it cannot decode the bitmap information. Otherwise, returns a buffer of size width() * height() uint32_t's. The data is in cairo ARGB32 format, that is native-endian uint32_t's with premultiplied alpha.

References colorKey(), hasAlpha(), height(), isJpeg(), and width().

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

## ◆ objNum()

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

Return object number of the bitmap.

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

## ◆ 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().

## ◆ embed()

std::pair< Buffer, Buffer > Bitmap::embed | ( |  | ) | const

Create the data to be embedded in an XML or PDF file.

For Jpeg images, this is simply the bitmap data. For other images, rgb/grayscale data and alpha channel are split and deflated separately.

References ipe::Buffer::data(), ipe::DeflateStream::deflate(), hasAlpha(), height(), isGray(), isJpeg(), ipe::Buffer::size(), and width().

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

## ◆ operator==()

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

Two bitmaps are equal if they share the same data.

## ◆ operator!=()

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

Two bitmaps are equal if they share the same data.

## ◆ operator<()

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.

## ◆ readJpegInfo()

const char * Bitmap::readJpegInfo | ( | FILE * | file,
|  | int & | width,
|  | int & | height,
|  | Vector & | dotsPerInch,
|  | uint32_t & | flags
| ) |  |
| static

Read information about JPEG image from file.

Returns NULL on success, an error message otherwise. Sets flags to EDCT and possibly ERGB.

References EDCT, and ERGB.

Referenced by readJpeg().

## ◆ 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(), ipe::String::data(), ipe::Platform::fopen(), height(), ipe::Platform::readFile(), readJpegInfo(), ipe::String::size(), and width().

## ◆ readPNG()

Bitmap Bitmap::readPNG | ( | const char * | fname,
|  | 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(), EAlpha, ERGB, and ipe::Platform::fopen().

## ◆ savePixels()

void Bitmap::savePixels | ( | const char * | fname | ) |

References ipe::Buffer::data(), ipe::Platform::fopen(), height(), isJpeg(), and width().

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

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