Ipelib
|
#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) |
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.
enum ipe::Bitmap::Flags |
Bitmap::Bitmap | ( | ) |
Default constructor constructs null bitmap.
Referenced by readJpeg(), and readPNG().
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.
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::Bitmap | ( | const XmlAttributes & | attr, |
Buffer | data, | ||
Buffer | smask | ||
) |
Create from XML using external raw data.
Bitmap::Bitmap | ( | const Bitmap & | rhs | ) |
Copy constructor.
Since Bitmaps are reference counted, this is very fast.
Bitmap::~Bitmap | ( | ) |
Destructor.
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 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().
|
inline |
Is this a null bitmap?
Referenced by ipe::Image::Image(), and ipe::ImlParser::parseObject().
bool Bitmap::equal | ( | Bitmap | rhs | ) | const |
|
inline |
Return width of pixel array.
Referenced by Bitmap(), ipe::CairoPainter::doDrawBitmap(), embed(), pixelData(), readJpeg(), readJpegInfo(), readPNG(), saveAsXml(), and savePixels().
|
inline |
Return height of pixel array.
Referenced by Bitmap(), ipe::CairoPainter::doDrawBitmap(), embed(), pixelData(), readJpeg(), readJpegInfo(), readPNG(), saveAsXml(), and savePixels().
|
inline |
Is this bitmap a JPEG photo?
References EDCT.
Referenced by embed(), pixelData(), saveAsXml(), and savePixels().
|
inline |
|
inline |
Does the bitmap have transparency?
Bitmaps with color key will return false here.
References EAlpha.
Referenced by embed(), pixelData(), and saveAsXml().
|
inline |
Return the color key or -1 if none.
Referenced by pixelData(), and saveAsXml().
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().
|
inline |
Return object number of the bitmap.
Referenced by ipe::PdfPainter::doDrawBitmap(), ipe::StyleSheet::saveAsXml(), ipe::Document::saveAsXml(), ipe::Image::saveAsXml(), and setObjNum().
|
inline |
Set object number of the bitmap.
References objNum().
Referenced by ipe::Page::saveAsIpePage(), and ipe::Page::saveSelection().
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().
|
inline |
Two bitmaps are equal if they share the same data.
|
inline |
Two bitmaps are equal if they share the same data.
|
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.
|
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, ERGB, height(), and width().
Referenced by readJpeg().
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().
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 Bitmap(), ipe::Buffer::data(), EAlpha, ERGB, ipe::Platform::fopen(), height(), and width().
void Bitmap::savePixels | ( | const char * | fname | ) |
References ipe::Buffer::data(), ipe::Platform::fopen(), height(), isJpeg(), and width().