Pyro higlevel API
Classes | Public Member Functions | Static Public Member Functions | List of all members
os::BitmapImage Class Reference

Container for bitmap image data. More...

Inheritance diagram for os::BitmapImage:
os::Image

Classes

class  Private
 

Public Member Functions

 BitmapImage (uint32 nFlags=Bitmap::SHARE_FRAMEBUFFER)
 Default constructor. More...
 
 BitmapImage (const BitmapImage &cSource, uint32 nFlags=Bitmap::SHARE_FRAMEBUFFER)
 Copy constructor. More...
 
 BitmapImage (StreamableIO *pcSource, uint32 nFlags=Bitmap::SHARE_FRAMEBUFFER)
 Constructor. More...
 
 BitmapImage (const uint8 *pData, const IPoint &cSize, color_space eColorSpace, uint32 nFlags=Bitmap::SHARE_FRAMEBUFFER)
 Constructor. More...
 
virtual ~BitmapImage ()
 
virtual const String ImageType (void) const
 Get object type. More...
 
virtual bool IsValid (void) const
 Find out if the bitmap object is valid. More...
 
virtual status_t Load (StreamableIO *pcSource, const String &cType="")
 Load bitmap from a stream (file, memory, resource etc.). More...
 
virtual status_t Save (StreamableIO *pcDest, const String &cType)
 Write bitmap to a stream. More...
 
virtual void Draw (const Point &cPos, View *pcView)
 Draw an image to a View. More...
 
virtual void Draw (const Rect &cSource, const Rect &cDest, View *pcView)
 Draw an image to a View. More...
 
virtual status_t SetSize (const Point &cSize)
 Scale the bitmap. More...
 
virtual Point GetSize (void) const
 Get bitmap size. More...
 
void SetBitmapData (const uint8 *pData, const IPoint &cSize, color_space eColorSpace, uint32 nFlags=Bitmap::SHARE_FRAMEBUFFER)
 Set raw bitmap data. More...
 
color_space GetColorSpace () const
 Get bitmap colour space. More...
 
virtual status_t SetColorSpace (color_space eColorSpace)
 Set colour space. More...
 
virtual BitmapLockBitmap (void)
 Lock the internal Bitmap object. More...
 
virtual void UnlockBitmap (void)
 Unlock the internal Bitmap object. More...
 
virtual BitmapImageoperator= (const BitmapImage &cSource)
 Copy the contents of another bitmap. More...
 
virtual ViewGetView ()
 Obtain a View for rendering into the bitmap. More...
 
virtual void ResizeCanvas (const Point &cSize)
 Change the size of the bitmap. More...
 
virtual uint32 * operator[] (int row)
 Direct access to pixels. More...
 
void Sync ()
 Flush the render queue, and wait til the rendering is done. More...
 
void Flush ()
 Flush the render queue. More...
 
virtual status_t ApplyFilter (const Message &cFilterData)
 
status_t GrayFilter (void)
 Create a greyed image. More...
 
status_t HighlightFilter (void)
 Make the image highlighted. More...
 
status_t AlphaToOverlay (uint32 cTransparentColor)
 Convert alpha channel to overlay. More...
 
status_t GlowFilter (Color32_s cInnerColor, Color32_s cOuterColor, int nRadius)
 Add glow effect to the image. More...
 
status_t ColorizeFilter (Color32_s cColor)
 
- Public Member Functions inherited from os::Image
 Image ()
 Default constructor. More...
 
virtual ~Image ()
 
Rect GetBounds (void) const
 Get image bounds. More...
 
virtual status_t ApplyFilter (uint32 nFilterID)
 

Static Public Member Functions

static os::BitmapImageGetImageFromResource (const os::String &cName)
 

Additional Inherited Members

- Public Types inherited from os::Image
enum  {
  F_NONE,
  F_GRAY,
  F_HIGHLIGHT,
  F_ALPHA_TO_OVERLAY,
  F_GLOW,
  F_COLORIZE
}
 Filter types. More...
 
- Public Attributes inherited from os::Image
enum os::Image:: { ... }  FilterType
 

Detailed Description

Description:
The BitmapImage class contains image data in the form of a bitmap and implements methods for loading and saving images via Translators.
Example:
File cFile( "picture.png" );
Image *pcImage;
pcImage = new BitmapImage( &cFile ); // Load picture.png
pcImage->GrayFilter();
See Also
os::Image, os::VectorImage, os::Bitmap
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

Constructor & Destructor Documentation

BitmapImage::BitmapImage ( uint32  nFlags = Bitmap::SHARE_FRAMEBUFFER)
Parameters
nFlagsBitmap flags, see os::Bitmap.
See Also
os::Bitmap, os::BitmapImage::IsValid()
Note
This constructor does not create the internal Bitmap object. Thus BitmapImage::IsValid() will return false after this creator is used. Note that the methods BitmapImage::Load(), BitmapImage::SetBitmapData(), BitmapImage::SetSize(), BitmapImage::ResizeCanvas() (re)initialise the internal Bitmap object, so one of these must be called before operations such as BitmapImage::Draw(), BitmapImage::GetSize() etc can be used.
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::BitmapImage::Private::m_nBitmapFlags.

BitmapImage::BitmapImage ( const BitmapImage cSource,
uint32  nFlags = Bitmap::SHARE_FRAMEBUFFER 
)
Parameters
cSourceOriginal BitmapImage object to copy.
nFlagsBitmap flags, see os::Bitmap.
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::BitmapImage::Private::m_nBitmapFlags.

BitmapImage::BitmapImage ( StreamableIO pcSource,
uint32  nFlags = Bitmap::SHARE_FRAMEBUFFER 
)
Parameters
pcSourceA pointer to a StreamableIO object. Could be a file, a resource or any data source that can be represented as a stream of data. The Translator API is used to try to recognize the format and load it as bitmap data. If you need to explicitly specify the file format, use Load().
nFlagsBitmap flags, see os::Bitmap.
See Also
Load(), os::Bitmap
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References Load(), and os::BitmapImage::Private::m_nBitmapFlags.

BitmapImage::BitmapImage ( const uint8 *  pData,
const IPoint cSize,
color_space  eColorSpace,
uint32  nFlags = Bitmap::SHARE_FRAMEBUFFER 
)
Parameters
pDataPointer to an array of raw bitmap data.
cSizeThe size of the bitmap in pixels.
eColorSpaceColor space, for instance CS_RGB32.
nFlagsBitmap flags, see os::Bitmap.
See Also
os::color_space, os::Bitmap
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::BitmapImage::Private::m_nBitmapFlags, and SetBitmapData().

BitmapImage::~BitmapImage ( )
virtual

Member Function Documentation

status_t BitmapImage::AlphaToOverlay ( uint32  cTransparentColor)
Description:
Convert an image with alpha transparency to overlay transparency. Overlay may provide better rendering performance, but does not support gradual transparency; it's either fully transparent or entirely opaque.
The conversion is done by setting all pixels with >25%
transparency to TRANSPARENT_RGB32, which is pure white. Any pixel that is pure white, will have it's colour changed. (The blue component is tweaked +/- one LSB).
Parameters
cTransparentColorThe colour that will be transparent. Typically you will use the default, TRANSPARENT_RGB32.
See Also
os::View, os::Bitmap, os::View::DrawBitmap()
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::BitmapImage::Private::AssertBitmapFlags(), CS_RGB32, os::Bitmap::GetBounds(), os::Bitmap::GetBytesPerRow(), GetColorSpace(), os::Rect::Height(), os::Bitmap::LockRaster(), os::BitmapImage::Private::m_pcBitmap, os::Bitmap::SHARE_FRAMEBUFFER, and os::Bitmap::UnlockRaster().

Referenced by ApplyFilter().

status_t BitmapImage::ApplyFilter ( const Message cFilterData)
virtual
status_t BitmapImage::ColorizeFilter ( Color32_s  cColor)
void BitmapImage::Draw ( const Point cPos,
View pcView 
)
virtual
Description:
This method renders the image to a View object.
Parameters
cPosPosition in the destination View to draw at.
pcViewThe View to draw in.
See Also
os::View
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

Implements os::Image.

References os::View::DrawBitmap(), GetSize(), os::BitmapImage::Private::m_pcBitmap, os::Point::x, and os::Point::y.

Referenced by os::TreeViewNode::_DrawExpanderCross(), and SplashView::Paint().

void BitmapImage::Draw ( const Rect cSource,
const Rect cDest,
View pcView 
)
virtual
Description:
This method renders the image to a View object.
Parameters
cSourceRectangular region in the source Image to draw.
cDestRectangular region in the destination View to draw the image in. If the size of cDest is not equal to cSource, the image data from cSource will be scaled to fit.
pcViewThe View to draw in.
Todo:
Implement scaling. Needs support from os::View.
See Also
os::View
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

Implements os::Image.

References os::View::DrawBitmap(), and os::BitmapImage::Private::m_pcBitmap.

void BitmapImage::Flush ( void  )
Description:
See Window::Sync().
See Also
Window::Sync(), Bitmap::Sync(), GetView()
Author
Henrik Isaksson

References os::Bitmap::Flush(), and os::BitmapImage::Private::m_pcBitmap.

color_space BitmapImage::GetColorSpace ( ) const
Description:
Returns the colour space for the image.
Return values
Thebitmap's colour space, one of the values in os::color_space.
See Also
os::color_space, SetColorSpace()
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References CS_RGB32, os::Bitmap::GetColorSpace(), and os::BitmapImage::Private::m_pcBitmap.

Referenced by AlphaToOverlay(), GlowFilter(), operator=(), ResizeCanvas(), and SetSize().

static os::BitmapImage* os::BitmapImage::GetImageFromResource ( const os::String cName)
static
Point BitmapImage::GetSize ( void  ) const
virtual
View * BitmapImage::GetView ( )
virtual
Description:
Returns a pointer to a View, that can be used for rendering into the bitmap. This is useful for double buffering.
Note
When finished drawing to the View, you need to call Sync(). The drawing operations might not take place until you have done so.
The BitmapImage should be initialized with the flag ACCEPT_VIEWS. If it isn't, GetView() will try to re-allocate the bitmap, changing this flag.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::Bitmap::ACCEPT_VIEWS, os::Bitmap::AddChild(), os::BitmapImage::Private::AssertBitmapFlags(), os::Bitmap::GetBounds(), os::BitmapImage::Private::m_pcBitmap, and os::BitmapImage::Private::m_pcView.

status_t BitmapImage::GlowFilter ( Color32_s  cInnerColor,
Color32_s  cOuterColor,
int  nRadius 
)
Description:
Adds a "glowing" outline to the image.
Parameters
cInnerColorThe colour nearest the edge of the picture.
cOuterColorThe colour at the edge of the glow. Tip: set a low opacity here, to blend the glow with the background.
nRadiusThe width of the glow.
Note
This function requires an image with correct alpha channel data.
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::Color32_s::alpha, os::BitmapImage::Private::AssertBitmapFlags(), os::Color32_s::blue, os::Bitmap::GetBytesPerRow(), GetColorSpace(), GetSize(), os::Color32_s::green, os::Bitmap::LockRaster(), os::BitmapImage::Private::m_nBitmapFlags, os::BitmapImage::Private::m_pcBitmap, os::Color32_s::red, os::BitmapImage::Private::SetBitmap(), os::Bitmap::SHARE_FRAMEBUFFER, os::Bitmap::UnlockRaster(), os::Point::x, and os::Point::y.

Referenced by ApplyFilter().

status_t BitmapImage::GrayFilter ( void  )
Description:
Removes colour information and makes the image brighter, primarily intended for GUI components, where it will be used to create "disabled" icons.
Note
The greying algorithm may change in future versions. On certain systems it may also be adapted to suit their displays.
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::BitmapImage::Private::AssertBitmapFlags(), os::Color32_s::blue, CLAMP255, os::COL_NORMAL, os::get_default_color(), os::Bitmap::GetBounds(), os::Bitmap::GetBytesPerRow(), os::Color32_s::green, os::Rect::Height(), os::Bitmap::LockRaster(), os::BitmapImage::Private::m_pcBitmap, os::Color32_s::red, os::Bitmap::SHARE_FRAMEBUFFER, and os::Bitmap::UnlockRaster().

Referenced by ApplyFilter().

status_t BitmapImage::HighlightFilter ( void  )
Description:
Make the image highlighted, for use with icons, for instance.
Note
The highlighting algorithm may change in future versions. On certain systems it may also be adapted to suit their displays.
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::BitmapImage::Private::AssertBitmapFlags(), os::Color32_s::blue, CLAMP255, os::COL_SEL_WND_BORDER, os::get_default_color(), os::Bitmap::GetBounds(), os::Bitmap::GetBytesPerRow(), os::Color32_s::green, os::Rect::Height(), os::Bitmap::LockRaster(), os::BitmapImage::Private::m_pcBitmap, os::Color32_s::red, os::Bitmap::SHARE_FRAMEBUFFER, and os::Bitmap::UnlockRaster().

Referenced by ApplyFilter().

const String BitmapImage::ImageType ( void  ) const
virtual
Description:
Used for run-time type checking. Returs the class name, "BitmapImage".
See Also
Image::ImageType()
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

Implements os::Image.

bool BitmapImage::IsValid ( void  ) const
virtual
Description:
Use to find out if the object contains a usable bitmap.
See Also
Image::IsValid()
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

Implements os::Image.

References os::BitmapImage::Private::m_pcBitmap.

status_t BitmapImage::Load ( StreamableIO pcSource,
const String cType = "" 
)
virtual
Description:
This method loads and translates bitmaps in any format supported by the Translators from any data source that can be represented as a stream.
Parameters
pcSourceA pointer to a StreamableIO object. Could be a file, a resource or any data source that can be represented as a stream of data. The Translator API is used to try to recognize the format and load it as bitmap data.
cTypeUsed to specify a specific file format, if the automatic recognition is not enough.
Example:
File cFile( "picture.png" );
myImage->Load( &cFile, "image/png" );
See Also
Save(), os::File, os::StreamableIO, os::MemFile
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

Implements os::Image.

References os::Translator::AddData(), os::BitmapFrameHeader::bf_bytes_per_row, os::BitmapFrameHeader::bf_data_size, os::BitmapFrameHeader::bf_frame, os::BitmapHeader::bh_bounds, os::IRect::bottom, CS_RGB32, os::TranslatorFactory::FindTranslator(), os::Bitmap::GetBytesPerRow(), os::TranslatorFactory::GetDefaultFactory(), os::IRect::Height(), os::IRect::left, os::Bitmap::LockRaster(), os::BitmapImage::Private::m_nBitmapFlags, os::BitmapImage::Private::m_pcBitmap, os::StreamableIO::Read(), os::Translator::Read(), os::BitmapImage::Private::SetBitmap(), os::Bitmap::SHARE_FRAMEBUFFER, os::IRect::top, and os::IRect::Width().

Referenced by BitmapImage(), os::IconDirectoryView::DragSelection(), os::IconDirectoryView::GetDirIcon(), os::IconDirectoryView::Private::GetDriveIcon(), os::RegistrarManager::GetTypeAndIcon(), os::IconDirectoryView::HandleMessage(), and MountDialogScanner::ScanPath().

Bitmap * BitmapImage::LockBitmap ( void  )
virtual
Description:
Lock the internal Bitmap object so it can be safely manipulated.
Example:
Bitmap *myBitmap = myImage->LockBitmap();
if( myBitmap ) {
...
myImage->UnlockBitmap();
}
Note
Don't forget to Unlock the Bitmap by calling UnlockBitmap().
Return values
Pointerto the locked Bitmap. If the internal Bitmap is not valid, returns NULL (see IsValid()).
See Also
UnlockBitmap(), IsValid(), os::Bitmap
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::BitmapImage::Private::m_pcBitmap.

BitmapImage & BitmapImage::operator= ( const BitmapImage cSource)
virtual
Description:
Copy the contents of another bitmap.
Note
The source bitmap must be created with SHARE_FRAMEBUFFER flag. If not, the assignment has no effect.
See Also
os::Bitmap

References GetColorSpace(), GetSize(), os::Bitmap::LockRaster(), os::BitmapImage::Private::m_nBitmapFlags, os::BitmapImage::Private::m_pcBitmap, SetBitmapData(), os::Point::x, and os::Point::y.

uint32 * BitmapImage::operator[] ( int  row)
virtual
Description:
Returns a pointer to a row of raw pixel data.
Note
The BitmapImage should be initialized with the flag SHARE_FRAMEBUFFER. If it isn't, this method will try to re-allocate the bitmap, changing this flag.
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References os::BitmapImage::Private::AssertBitmapFlags(), os::Bitmap::GetBytesPerRow(), os::Bitmap::LockRaster(), os::BitmapImage::Private::m_pcBitmap, and os::Bitmap::SHARE_FRAMEBUFFER.

void BitmapImage::ResizeCanvas ( const Point cSize)
virtual
Description:
Changes the size of the bitmap to the specified size. Returns an error if memory for a new bitmap can not be allocated. Note that the image data is lost. To change the size of the image, use SetSize() instead.
Parameters
cSizeThe new size.
See Also
SetSize(), GetSize()
Author
Henrik Isaksson (henri.nosp@m.k@is.nosp@m.aksso.nosp@m.n.tk)

References GetColorSpace(), os::BitmapImage::Private::m_nBitmapFlags, os::BitmapImage::Private::SetBitmap(), os::Point::x, and os::Point::y.

status_t BitmapImage::Save ( StreamableIO pcDest,
const String cType 
)
virtual
Description:
This method translates and writes bitmaps to a stream in any Translator supported format. (Note! At the time of writing there are no Translators capable of translating from the internal format to any other format.)
Parameters
pcDestA pointer to a StreamableIO object.
cTypeString that describes the file format, eg "image/png".
Example:
File cFile( "picture.png" );
myImage->Save( &cFile, "image/png" );
Note
This method can only be used if the bitmap was created with the SHARE_FRAMEBUFFER flag.
See Also
Load(), os::File, os::StreamableIO, os::MemFile
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

Implements os::Image.

References os::Translator::AddData(), os::BitmapFrameHeader::bf_bytes_per_row, os::BitmapFrameHeader::bf_color_space, os::BitmapFrameHeader::bf_data_size, os::BitmapFrameHeader::bf_frame, os::BitmapFrameHeader::bf_header_size, os::BitmapFrameHeader::bf_time_stamp, os::BitmapHeader::bh_bounds, os::BitmapHeader::bh_bytes_per_row, os::BitmapHeader::bh_color_space, os::BitmapHeader::bh_data_size, os::BitmapHeader::bh_flags, os::BitmapHeader::bh_frame_count, os::BitmapHeader::bh_header_size, os::IRect::bottom, CS_RGB32, os::TranslatorFactory::FindTranslator(), os::TranslatorFactory::GetDefaultFactory(), GetSize(), os::IRect::left, os::Bitmap::LockRaster(), os::BitmapImage::Private::m_nBitmapFlags, os::BitmapImage::Private::m_pcBitmap, os::Translator::Read(), os::IRect::right, os::Bitmap::SHARE_FRAMEBUFFER, os::IRect::top, os::StreamableIO::Write(), os::Point::x, and os::Point::y.

void BitmapImage::SetBitmapData ( const uint8 *  pData,
const IPoint cSize,
color_space  eColorSpace,
uint32  nFlags = Bitmap::SHARE_FRAMEBUFFER 
)
Description:
Set raw bitmap data.
Parameters
pDataPointer to an array of raw bitmap data.
cSizeThe size of the bitmap in pixels.
eColorSpaceColor space, for instance CS_RGB32.
nFlagsBitmap flags, see os::Bitmap. SHARE_FRAMEBUFFER is assumed.
See Also
os::color_space, os::Bitmap
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::Bitmap::GetBytesPerRow(), os::Bitmap::LockRaster(), os::BitmapImage::Private::m_nBitmapFlags, os::BitmapImage::Private::SetBitmap(), os::Bitmap::SHARE_FRAMEBUFFER, os::IPoint::x, and os::IPoint::y.

Referenced by BitmapImage(), and operator=().

status_t BitmapImage::SetColorSpace ( color_space  eColorSpace)
virtual
Description:
Transform the bitmap to a different colour space. This method may reduce the quality of the image data!
Parameters
eColorSpaceThe colour space, eg. CS_RGB32.
Return values
0for success, -1 for failure.
Todo:
Implement BitmapImage::SetColorSpace
See Also
os::color_space, GetColorSpace()
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)
status_t BitmapImage::SetSize ( const Point cSize)
virtual
Description:
Scales the bitmap to the specified size. Returns an error if memory for a new bitmap can not be allocated. SetSize may provide better quality scaling than Draw(), which is optimized for speed rather than quality. The image will remain unchanged if memory allocation fails.
Parameters
cSizeThe new size.
See Also
GetSize(), ResizeCanvas()
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

Reimplemented from os::Image.

References filter_lanczos3, GetColorSpace(), os::BitmapImage::Private::m_nBitmapFlags, os::BitmapImage::Private::m_pcBitmap, Scale(), os::BitmapImage::Private::SetBitmap(), os::Point::x, and os::Point::y.

Referenced by os::IconDirectoryView::DragSelection(), os::IconDirectoryView::Private::GetDriveIcon(), os::RegistrarManager::GetTypeAndIcon(), os::IconDirectoryView::HandleMessage(), and MountDialogScanner::ScanPath().

void BitmapImage::Sync ( void  )
Description:
Call this method before accessing bitmap data that you have created by rendering to the View associated with this BitmapImage.
See Also
Window::Sync(), Bitmap::Sync(), GetView()
Author
Henrik Isaksson

References os::BitmapImage::Private::m_pcBitmap, and os::Bitmap::Sync().

void BitmapImage::UnlockBitmap ( void  )
virtual
Description:
Unlock the internal Bitmap object
See Also
LockBitmap(), os::Bitmap
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)