Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dw::core::Imgbuf Class Referenceabstract

The platform independent interface for image buffers. More...

#include <imgbuf.hh>

Public Types

enum  Type {
  RGB , RGBA , GRAY , INDEXED ,
  INDEXED_ALPHA
}
 

Public Member Functions

 Imgbuf ()
 
 ~Imgbuf ()
 
virtual void setCMap (int *colors, int num_colors)=0
 
virtual void copyRow (int row, const byte *data)=0
 
virtual void newScan ()=0
 
virtual ImgbufgetScaledBuf (int width, int height)=0
 
virtual void getRowArea (int row, dw::core::Rectangle *area)=0
 
virtual int getRootWidth ()=0
 
virtual int getRootHeight ()=0
 
virtual ImgbufcreateSimilarBuf (int width, int height)=0
 Creates an image buffer with same parameters (type, gamma etc.) except size.
 
virtual void copyTo (Imgbuf *dest, int xDestRoot, int yDestRoot, int xSrc, int ySrc, int widthSrc, int heightSrc)=0
 Copies another image buffer into this image buffer.
 
virtual void ref ()=0
 
virtual void unref ()=0
 
virtual bool lastReference ()=0
 
virtual void setDeleteOnUnref (bool deleteOnUnref)=0
 
virtual bool isReferred ()=0
 
- Public Member Functions inherited from lout::object::Object
virtual ~Object ()
 The destructor is defined as virtual (but not abstract), so that destruction of Object's works properly.
 
virtual bool equals (Object *other)
 Returns, whether two objects are equal.
 
virtual int hashValue ()
 Return a hash value for the object.
 
virtual Objectclone ()
 Return an exact copy of the object.
 
virtual void intoStringBuffer (misc::StringBuffer *sb)
 Store a textual representation of the object in a misc::StringBuffer.
 
const char * toString ()
 Use object::Object::intoStringBuffer to return a textual representation of the object.
 
virtual size_t sizeOf ()
 Return the number of bytes, this object totally uses.
 
- Public Member Functions inherited from lout::signal::ObservedObject
virtual ~ObservedObject ()
 
void connectDeletion (DeletionReceiver *receiver)
 

Detailed Description

The platform independent interface for image buffers.

Image buffers depend on the platform (see Images and Backgrounds in Dw), but have this general, platform independent interface. The purpose of an image buffer is

  1. storing the image data,
  2. handling scaled versions of this buffer, and
  3. drawing.

The latter must be done independently from the window.

Creating

Image buffers are created by calling dw::core::Platform::createImgbuf.

Storing Image Data

dw::core::Imgbuf supports five image types, which are listed in the table below. The representation defines, how the colors are stored within the data, which is passed to dw::core::Imgbuf::copyRow.

Type (dw::core::Imgbuf::Type) Bytes per Pixel Representation
dw::core::Imgbuf::RGB 3 red, green, blue
dw::core::Imgbuf::RGBA 4 red, green, blue, alpha
dw::core::Imgbuf::GRAY 1 gray value
dw::core::Imgbuf::INDEXED 1 index to colormap
dw::core::Imgbuf::INDEXED_ALPHA 1 index to colormap

The last two types need a colormap, which is set by dw::core::Imgbuf::setCMap, which must be called before dw::core::Imgbuf::copyRow. This function expects the colors as 32 bit unsigned integers, which have the format 0xrrbbgg (for indexed images), or 0xaarrggbb (for indexed alpha), respectively.

Scaling

The buffer with the original size, which was created by dw::core::Platform::createImgbuf, is called root buffer. Imgbuf provides the ability to scale buffers. Generally, both root buffers, as well as scaled buffers, may be shared, memory management is done by reference counters.

Via dw::core::Imgbuf::getScaledBuf, you can retrieve a scaled buffer. Generally, something like this must work always, in an efficient way:

dw::core::Imgbuf *curBuf, *oldBuf;
int width, heigt,
// ...
oldBuf = curBuf;
curBuf = oldBuf->getScaledBuf(oldBuf, width, height);
oldBuf->unref();
The platform independent interface for image buffers.
Definition imgbuf.hh:162
virtual Imgbuf * getScaledBuf(int width, int height)=0
virtual void unref()=0

oldBuf may both be a root buffer, or a scaled buffer.

The root buffer keeps a list of all children, and all methods operating on the image data (dw::core::Imgbuf::copyRow and dw::core::Imgbuf::setCMap) are delegated to the scaled buffers, when processed, and inherited, when a new scaled buffer is created. This means, that they must only be performed for the root buffer.

A possible implementation could be (dw::fltk::FltkImgbuf does it this way):

  • If the method is called with an already scaled image buffer, this is delegated to the root buffer.

  • If the given size is the original size, the root buffer is returned, with an increased reference counter.

  • Otherwise, if this buffer has already been scaled to the given size, return this scaled buffer, with an increased reference counter.

  • Otherwise, return a new scaled buffer with reference counter 1.

Special care is to be taken, when the root buffer is not used anymore, i.e. after dw::core::Imgbuf::unref the reference counter is 0, but there are still scaled buffers. Since all methods operating on the image data (dw::core::Imgbuf::copyRow and dw::core::Imgbuf::setCMap) are called for the root buffer, the root buffer is still needed, and so must not be deleted at this point. This is, how dw::fltk::FltkImgbuf solves this problem:

In the following example:

dw::core::Imgbuf *rootbuf =
layout->createImgbuf (dw::core::Imgbuf::RGB, 100, 100);
dw::core::Imgbuf *scaledbuf = rootbuf->getScaledBuf (50, 50);
rootbuf->unref ();
scaledbuf->unref ();
The central class for managing and drawing a widget tree.
Definition layout.hh:17
static Layout * layout
static FltkPlatform * platform

the root buffer is not deleted, when dw::core::Imgbuf::unref is called, since a scaled buffer is left. After calling dw::core::Imgbuf::unref for the scaled buffer, it is deleted, and after it, the root buffer.

Drawing

dw::core::Imgbuf provides no methods for drawing, instead, this is done by the views (implementation of dw::core::View).

There are two situations, when drawing is necessary:

  1. To react on expose events, the function dw::core::View::drawImage should be used, with the following parameters:

    • of course, the image buffer,
    • where the root of the image would be displayed (as xRoot and yRoot), and
    • the region within the image, which should be displayed (x, y, width, height).

  2. When a row has been copied, it has to be drawn. To determine the area, which has to be drawn, the dw::core::Imgbuf::getRowArea should be used. The result can then passed to dw::core::View::drawImage.
See also
Images and Backgrounds in Dw

Definition at line 161 of file imgbuf.hh.

Member Enumeration Documentation

◆ Type

Enumerator
RGB 
RGBA 
GRAY 
INDEXED 
INDEXED_ALPHA 

Definition at line 164 of file imgbuf.hh.

Constructor & Destructor Documentation

◆ Imgbuf()

dw::core::Imgbuf::Imgbuf ( )
inline

Definition at line 166 of file imgbuf.hh.

References DBG_OBJ_BASECLASS, and DBG_OBJ_CREATE.

◆ ~Imgbuf()

dw::core::Imgbuf::~Imgbuf ( )
inline

Definition at line 172 of file imgbuf.hh.

References DBG_OBJ_DELETE.

Member Function Documentation

◆ copyRow()

virtual void dw::core::Imgbuf::copyRow ( int  row,
const byte data 
)
pure virtual

◆ copyTo()

virtual void dw::core::Imgbuf::copyTo ( Imgbuf dest,
int  xDestRoot,
int  yDestRoot,
int  xSrc,
int  ySrc,
int  widthSrc,
int  heightSrc 
)
pure virtual

Copies another image buffer into this image buffer.

◆ createSimilarBuf()

virtual Imgbuf * dw::core::Imgbuf::createSimilarBuf ( int  width,
int  height 
)
pure virtual

Creates an image buffer with same parameters (type, gamma etc.) except size.

Implemented in dw::fltk::FltkImgbuf.

Referenced by dw::core::style::StyleImage::StyleImgRenderer::setBuffer().

◆ getRootHeight()

virtual int dw::core::Imgbuf::getRootHeight ( )
pure virtual

◆ getRootWidth()

◆ getRowArea()

virtual void dw::core::Imgbuf::getRowArea ( int  row,
dw::core::Rectangle area 
)
pure virtual

Implemented in dw::fltk::FltkImgbuf.

◆ getScaledBuf()

virtual Imgbuf * dw::core::Imgbuf::getScaledBuf ( int  width,
int  height 
)
pure virtual

◆ isReferred()

virtual bool dw::core::Imgbuf::isReferred ( )
pure virtual
Todo:
Comment

Implemented in dw::fltk::FltkImgbuf.

Referenced by solution2().

◆ lastReference()

virtual bool dw::core::Imgbuf::lastReference ( )
pure virtual
Todo:
Comment

Implemented in dw::fltk::FltkImgbuf.

Referenced by solution1().

◆ newScan()

virtual void dw::core::Imgbuf::newScan ( )
pure virtual

Implemented in dw::fltk::FltkImgbuf.

◆ ref()

virtual void dw::core::Imgbuf::ref ( )
pure virtual

◆ setCMap()

virtual void dw::core::Imgbuf::setCMap ( int *  colors,
int  num_colors 
)
pure virtual

Implemented in dw::fltk::FltkImgbuf.

◆ setDeleteOnUnref()

virtual void dw::core::Imgbuf::setDeleteOnUnref ( bool  deleteOnUnref)
pure virtual
Todo:
Comment

Implemented in dw::fltk::FltkImgbuf.

Referenced by solution2().

◆ unref()


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