Sourceforge.net - The VCF's Project Host
   The VCF Website Home   |   Online Discussion Forums   |   Sourceforge.net Project Page   

VCF::AbstractImage Class Reference

AbstractImage represents a base implementation of the Image interface. More...

#include <vcf/GraphicsKit/AbstractImage.h>

Inheritance diagram for VCF::AbstractImage:

VCF::Image VCF::Object VCF::Persistable VCF::GrayScaleImage VCF::GTKImage VCF::OSXImage VCF::Win32Image VCF::X11Image VCF::XCBImagePeer VCF::Win32GrayScaleImage List of all members.

Public Member Functions

 AbstractImage (const bool &needsMemAlloc=true)
virtual ~AbstractImage ()
virtual void setSize (const uint32 &width, const uint32 &height)
virtual uint32 getWidth ()
virtual uint32 getHeight ()
virtual void addImageSizeChangedHandler (EventHandler *handler)
 This macro creates a method for adding a listener to the AbstractImage's ImageSizeChangedHandler events.
virtual void removeImageSizeChangedHandler (EventHandler *handler)
 This macro creates a method for removing a listener to the AbstractImage's ImageSizeChangedHandler events.
virtual GraphicsContextgetImageContext ()
 This retreives a graphics context for drawing on.
virtual ColorgetTransparencyColor ()
 returns the color that is used to blend with the contents of a GraphicsContext when the Image is drawn.
virtual void setTransparencyColor (Color *transparencyColor)
virtual bool isTransparent ()
 Indicates whether or not the Image is using a transparent color.
virtual void setIsTransparent (const bool &transparent)
virtual void saveToStream (OutputStream *stream)
 Write the object to the specified output stream.
virtual void loadFromStream (InputStream *stream)
 Read the object from the specified input stream.
virtual Image::ImageType getType () const
 returns the type of image that this Image instance represents.
virtual Image::ImageChannelSize getChannelSize () const
 returns the number of bits each channel value represents.
virtual Image::ImageChannelType getChannelType () const
 returns whether the values for a channel are integer based or floating point based.
virtual Image::PixelLayoutOrder getPixelLayoutOrder () const
 returns the pixel layout order.
virtual void * getData ()

Public Attributes

VCF::Delegate ImageSizeChanged

Protected Attributes

unsigned char * dataBuffer_
int height_
int width_
GraphicsContextcontext_
Color transparencyColor_
bool isTransparent_
bool needsMemAlloc_
ImageDescriptor flags_
 Implementer note: flags_ needs to be intialized in the constructor of the platform implementation of the Image class.

Detailed Description

AbstractImage represents a base implementation of the Image interface.

It implements common functions, such as getWidth, etc, but still requires actually image class to be derived from it. It also provides basic support for ImageSizeChangedHandlers, so derived classes do not have to baother with it. See Image for more information on what the functions do.

Version:
1.0
Author:
Jim Crafton
See also:
Image
Event Delegates for this class:


Constructor & Destructor Documentation

VCF::AbstractImage::AbstractImage const bool &  needsMemAlloc = true  ) 
 

virtual VCF::AbstractImage::~AbstractImage  )  [virtual]
 


Member Function Documentation

virtual void VCF::AbstractImage::addImageSizeChangedHandler EventHandler handler  )  [inline, virtual]
 

This macro creates a method for adding a listener to the AbstractImage's ImageSizeChangedHandler events.

Implements VCF::Image.

virtual Image::ImageChannelSize VCF::AbstractImage::getChannelSize  )  const [virtual]
 

returns the number of bits each channel value represents.

For example, by default, on Win32 systems, an Image is a full color RGBA image, with each value of a channel taking 8 bits, thus a single of pixel of this type of image takes up 32 bits - 4 channels with each channel component 8 bits in size.

Returns:
the channel's component size. Can be one of the following values:
  • Image::ics8Bit - each channel component is 8 bits in sizem, thus the numerical value of this enum is 8.
  • Image::ics16Bit - each channel component is 8 bits in sizem, thus the numerical value of this enum is 16.
  • Image::ics32Bit - each channel component is 8 bits in sizem, thus the numerical value of this enum is 32.
The last two types (Image::ics16Bit and Image::ics32Bit) are typically used for high end imaging.

Implements VCF::Image.

virtual Image::ImageChannelType VCF::AbstractImage::getChannelType  )  const [virtual]
 

returns whether the values for a channel are integer based or floating point based.

Returns:
ImageChannelType the image channel's value type. Can be one of

Implements VCF::Image.

virtual void* VCF::AbstractImage::getData  )  [virtual]
 

Implements VCF::Image.

virtual uint32 VCF::AbstractImage::getHeight  )  [virtual]
 

Implements VCF::Image.

virtual GraphicsContext* VCF::AbstractImage::getImageContext  )  [virtual]
 

This retreives a graphics context for drawing on.

Any drawing performed on the graphics context will be reflected in the internal pixel data of the image. On some platforms this may be "instantaneous" because the pixel data of the image is directly linked to the GraphicsContext (i.e. Win32), while on other platforms the drawing on the GraphicsContext needs to be "flushed" back to the images pixels. Because of this, you must call beginDrawing() before calling getImageContext(), and call finishedDrawing() when you're done with the GraphicsContext. Concrete implemententations of this class will transfer the image's contents to the GraphicsContext for beginDrawing(), finishedDrawing() will update the image's data due to any changes in the GraphicsContext. To ensure that you call these functions correctly, use the ImageContext class. An example:

    Image* image = getImage(); //get an image from somewhere

    //new code block...
    {
        ImageContext gc = image; //the ImageContext automatically calls beginDrawing()
        gc->rectangle( 20, 20, 400, 60 );
        gc->strokePath();

    } // the ImageContext destructor calls finishedDrawing() for you

See also:
ImageContext

Implements VCF::Image.

virtual Image::PixelLayoutOrder VCF::AbstractImage::getPixelLayoutOrder  )  const [virtual]
 

returns the pixel layout order.

This explains how the individual color components of each of the color channels are laid out.

Returns:
PixelLayoutOrder the binary layout order of a single pixel value. Can be one of
  • Image::ploRGBA - indicates the Red value is in the MSB position, followed by Green, Blue and finally Alpha values. In code it might look like this for an Image with integer based 8 bit color channels
                uint32 pixelColor = (redVal &lt;&lt; 24) | (greenVal &lt;&lt; 16) | (blueVal &lt;&lt; 8) | (alphaVal);
    
    Extracting the values from a single pixel color would be:
                redVal  = (pixelColor &amp; 0xFF000000) &gt;&gt; 24;
                greenVal = (pixelColor &amp; 0x00FF0000) &gt;&gt; 16;
                blueVal = (pixelColor &amp; 0x0000FF00) &gt;&gt; 8;
                alphaVal = (pixelColor &amp; 0x000000FF);
    
  • Image::ploBGRA - indicates the Blue value is in the MSB position, followed by Green, Red and finally Alpha values. In code it might look like this for an Image with integer based 8 bit color channels
                uint32 pixelColor = (blueVal &lt;&lt; 24) | (greenVal &lt;&lt; 16) | (redVal &lt;&lt; 8) | (alphaVal);
    
    Extracting the values from a single pixel color would be:
                blueVal = (pixelColor &amp; 0xFF000000) &gt;&gt; 24;
                greenVal = (pixelColor &amp; 0x00FF0000) &gt;&gt; 16;
                redVal = (pixelColor &amp; 0x0000FF00) &gt;&gt; 8;
                alphaVal = (pixelColor &amp; 0x000000FF);
    
  • Image::ploARGB - indicates the Alpha value is in the MSB position, followed by Red, Green and finally Blue values. In code it might look like this for an Image with integer based 8 bit color channels
                uint32 pixelColor = (alphaVal &lt;&lt; 24) | (redVal &lt;&lt; 16) | (greenVal &lt;&lt; 8) | (blueVal);
    
    Extracting the values from a single pixel color would be:
                alphaVal    = (pixelColor &amp; 0xFF000000) &gt;&gt; 24;
                redVal = (pixelColor &amp; 0x00FF0000) &gt;&gt; 16;
                greenVal = (pixelColor &amp; 0x0000FF00) &gt;&gt; 8;
                blueVal = (pixelColor &amp; 0x000000FF);
    
    This is typically the way it would be stored on a linux based port of VCF.
  • Image::ploABGR - indicates the Alpha value is in the MSB position, followed by Blue, Green and finally Red values. In code it might look like this for an Image with integer based 8 bit color channels
                uint32 pixelColor = (alphaVal &lt;&lt; 24) | (blueVal &lt;&lt; 16) | (greenVal &lt;&lt; 8) | (redVal);
    
    Extracting the values from a single pixel color would be:
                alphaVal    = (pixelColor &amp; 0xFF000000) &gt;&gt; 24;
                blueVal = (pixelColor &amp; 0x00FF0000) &gt;&gt; 16;
                greenVal = (pixelColor &amp; 0x0000FF00) &gt;&gt; 8;
                redVal = (pixelColor &amp; 0x000000FF);
    
    This is typically the way it would be stored on a Win32 based port of VCF.

Implements VCF::Image.

virtual Color* VCF::AbstractImage::getTransparencyColor  )  [inline, virtual]
 

returns the color that is used to blend with the contents of a GraphicsContext when the Image is drawn.

Only used when the Image is set to Transparent

Implements VCF::Image.

virtual Image::ImageType VCF::AbstractImage::getType  )  const [virtual]
 

returns the type of image that this Image instance represents.

The integer value also indicates the number of color channels the Image has. Currently there are only 2 types, full color 4 channel RGBA images, and 1 channel grayscale images.

Returns:
ImageType the value that represent the images type. The values have the follwing meanings:
  • Image::itColor - indicate a full color image with red, green, blue, and alpha channels present. The integer value of this is 4 and can be used in operations to determine the total data size of the image, for example.
  • Image::itGrayscale - indicates a grayscale image with a single channel. The numerical value of this is 1.

Implements VCF::Image.

virtual uint32 VCF::AbstractImage::getWidth  )  [virtual]
 

Implements VCF::Image.

virtual bool VCF::AbstractImage::isTransparent  )  [inline, virtual]
 

Indicates whether or not the Image is using a transparent color.

Returns:
bool if this is true then the Image is transparent and the contents of the underlying GraphicsContext will show through wherever a pixel in the image is found that is the transparency color

Implements VCF::Image.

virtual void VCF::AbstractImage::loadFromStream InputStream stream  )  [virtual]
 

Read the object from the specified input stream.

Implements VCF::Persistable.

virtual void VCF::AbstractImage::removeImageSizeChangedHandler EventHandler handler  )  [inline, virtual]
 

This macro creates a method for removing a listener to the AbstractImage's ImageSizeChangedHandler events.

Implements VCF::Image.

virtual void VCF::AbstractImage::saveToStream OutputStream stream  )  [virtual]
 

Write the object to the specified output stream.

Implements VCF::Persistable.

virtual void VCF::AbstractImage::setIsTransparent const bool &  transparent  )  [inline, virtual]
 

Implements VCF::Image.

virtual void VCF::AbstractImage::setSize const uint32 width,
const uint32 height
[virtual]
 

Implements VCF::Image.

Reimplemented in VCF::GrayScaleImage, VCF::OSXImage, VCF::Win32Image, and VCF::Win32GrayScaleImage.

virtual void VCF::AbstractImage::setTransparencyColor Color transparencyColor  )  [inline, virtual]
 

Implements VCF::Image.


Member Data Documentation

GraphicsContext* VCF::AbstractImage::context_ [protected]
 

unsigned char* VCF::AbstractImage::dataBuffer_ [protected]
 

ImageDescriptor VCF::AbstractImage::flags_ [protected]
 

Implementer note: flags_ needs to be intialized in the constructor of the platform implementation of the Image class.

For Win32 an example might be:

    ImageBits::Traits::setChannelType( flags_, ImageBits::Traits::getTraitsChannelType() );
    ImageBits::Traits::setChannelSize( flags_, ImageBits::Traits::getTraitsChannelSize() );
    ImageBits::Traits::setImageType( flags_, ImageBits::Traits::getTraitsImageType() );
    ImageBits::Traits::setPixelLayoutOrder( flags_, Image::ploBGRA );

int VCF::AbstractImage::height_ [protected]
 

VCF::Delegate VCF::AbstractImage::ImageSizeChanged
 

Event Delegate:
ImageSizeChanged this is fired when the image's dimensions are changed by calling setSize().
event class: ImageEvent
event type: IMAGE_EVENT_WIDTH_CHANGED
event type: IMAGE_EVENT_HEIGHT_CHANGED
See also:
setSize()

bool VCF::AbstractImage::isTransparent_ [protected]
 

bool VCF::AbstractImage::needsMemAlloc_ [protected]
 

Color VCF::AbstractImage::transparencyColor_ [protected]
 

int VCF::AbstractImage::width_ [protected]
 


The documentation for this class was generated from the following file:
   Comments or Suggestions?    License Information