|
Ipelib
|
#include <ipebitmap.h>
Public Types | |
| enum | Format { None , Png , Jpeg } |
| 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, String 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 |
| String | checksumId (int suffix=0) 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) |
| bool | save (const char *fname) const |
Static Public Member Functions | |
| static void | saveBitmaps (Stream &stream, std::vector< Bitmap > &bitmaps) |
| 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) |
| static Bitmap | read (const char *fname, Vector &dotsPerInch, const char *&errmsg) |
| static Format | formatFromFile (const char *fname) |
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::Format |
| enum ipe::Bitmap::Flags |
| Bitmap::Bitmap | ( | ) |
Default constructor constructs null bitmap.
Referenced by read(), 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.
Save bitmap in XML stream.
References ipe::Base64Stream::close(), colorKey(), embed(), hasAlpha(), height(), isGray(), isJpeg(), ipe::Base64Stream::putChar(), ipe::Stream::putXmlString(), and width().
Referenced by ipe::Document::saveAsXml().
|
inline |
Is this a null bitmap?
Referenced by ipe::Painter::drawExternalBitmap(), ipe::Image::Image(), save(), ipe::Document::saveAsXml(), saveBitmaps(), and ipe::Image::setBitmap().
| bool Bitmap::equal | ( | Bitmap | rhs | ) | const |
|
inline |
Return width of pixel array.
Referenced by Bitmap(), Bitmap(), ipe::CairoPainter::doDrawBitmap(), embed(), pixelData(), readJpeg(), readJpegInfo(), readPNG(), save(), saveAsXml(), and savePixels().
|
inline |
Return height of pixel array.
Referenced by Bitmap(), Bitmap(), ipe::CairoPainter::doDrawBitmap(), embed(), pixelData(), readJpeg(), readJpegInfo(), readPNG(), save(), saveAsXml(), and savePixels().
|
inline |
Is this bitmap a JPEG photo?
References EDCT.
Referenced by embed(), pixelData(), save(), 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::Document::saveAsXml(), ipe::Image::saveAsXml(), saveBitmaps(), and setObjNum().
|
inline |
| String Bitmap::checksumId | ( | int | suffix = 0 | ) | const |
Return checksum as a hexadecimal string, possibly augmented by suffix.
References ipe::Stream::putHexByte().
Referenced by ipe::Image::saveAsXml(), and saveBitmaps().
Save all the bitmaps, assigning objNum to distinguish equal checksums.
References checksumId(), isNull(), objNum(), and setObjNum().
Referenced by ipe::Page::saveAsIpePage(), ipe::StyleSheet::saveAsXml(), ipe::Document::saveAsXml(), 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.
| bool Bitmap::operator< | ( | const Bitmap & | rhs | ) | const |
Less operator, to be able to sort bitmaps.
The checksum is used. When checksums are equal, compares the actual contents. After sorting, bitmaps with equal checksum form contiguous blocks. Identical bitmaps form smaller blocks within those blocks, and bitmaps with shared implementation form even smaller blocks within those.
|
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().
Referenced by ipe::BitmapCache::load(), and read().
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().
Referenced by ipe::BitmapCache::load(), and read().
References Bitmap(), formatFromFile(), Jpeg, Png, readJpeg(), and readPNG().
|
static |
References ipe::Platform::fopen(), Jpeg, None, and Png.
Referenced by read().
| void Bitmap::savePixels | ( | const char * | fname | ) |
References ipe::Buffer::data(), ipe::Platform::fopen(), height(), isJpeg(), and width().
| bool Bitmap::save | ( | const char * | fname | ) | const |
Save as JPEG (without re-encoding) or PNG, preserving straight-alpha pixels.
Returns false if the bitmap is null, encoding fails, or writing fails.
References ipe::Platform::fopen(), height(), isJpeg(), isNull(), ipe::size(), and width().