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

#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 ()
 
Bitmapoperator= (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, Bufferembed () 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

Enumerator
ERGB 
EAlpha 
EDCT 
EInflate 
ENative 

Constructor & Destructor Documentation

◆ Bitmap() [1/5]

Bitmap::Bitmap ( )

Default constructor constructs null bitmap.

Referenced by readJpeg(), and readPNG().

◆ 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 height(), and width().

◆ Bitmap() [3/5]

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

◆ Bitmap() [4/5]

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

Create from XML using external raw data.

◆ 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

◆ isNull()

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

Is this a null bitmap?

Referenced by ipe::Image::Image(), and ipe::ImlParser::parseObject().

◆ equal()

bool Bitmap::equal ( Bitmap  rhs) const

◆ width()

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

◆ height()

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

◆ isJpeg()

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

Is this bitmap a JPEG photo?

References EDCT.

Referenced by embed(), pixelData(), saveAsXml(), and savePixels().

◆ isGray()

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

Is the bitmap grayscale?

References ERGB.

Referenced by Bitmap(), embed(), and saveAsXml().

◆ hasAlpha()

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

Does the bitmap have transparency?

Bitmaps with color key will return false here.

References EAlpha.

Referenced by embed(), pixelData(), and saveAsXml().

◆ colorKey()

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

Return the color key or -1 if none.

Referenced by pixelData(), and saveAsXml().

◆ 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

◆ setObjNum()

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

Set object number of the bitmap.

References objNum().

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

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

◆ 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, ERGB, height(), and width().

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 Bitmap(), ipe::Buffer::data(), EAlpha, ERGB, ipe::Platform::fopen(), height(), and width().

◆ savePixels()

void Bitmap::savePixels ( const char *  fname)

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