Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Image Class Reference

represents one image (actually a SDL_Context wrapper ..) More...

#include <Image.h>

List of all members.

Public Types

enum  { GRAY_MASK = 1 }
 Converts the image to vector. More...


Public Member Functions

 Image (unsigned xs, unsigned ys)
 new image of undefined content in default RGBA pixel format

void resize (unsigned xs, unsigned ys)
 ~Image ()
void toFile (const std::string &fileName)
 Save image to file (BMP).

ImagesubImage (unsigned width, unsigned height, unsigned xOffset=0, unsigned yOffset=0) const
 Create a sub-image of the original.

void setSubImage (const Image &src, unsigned xo=0, unsigned yo=0)
 Copy contents of image from the src image to given offset.

Color getAverageColor () const throw (Exception)
ImagetoRGBA () const
 Image pixel format will be converted to RGBA (one pixel = one byte) Unless you know the input image format, you should convert image with this function before making training examples from a loaded image.

Imageclone () const
 copy this image (the result is independent)

ImageupsideDown () const
 flip image

ImagetoGray () const
 Image will be converted to 32-RGBA (one pixel = four bytes).

unsigned getWidth () const
unsigned getHeight () const
unsigned getBPP () const
Vector toVector (uint8_t bytes_mask) const
void display (unsigned xo=0, unsigned yo=0) const
 display to the video window (offsets are relative to win coords) if !gl, the video surface is flipped automatically (so far) - under GL you have to do it yourself (in GL mode, the offset is passed directly to glRasterPos --> it's up to caller to give it sense

void clear ()
void rect (const Color &c, uint x1, uint y1, uint x2, uint y2)
void putPixel (const Color &c, uint x, uint y)
 draw a pixel TODO: avoid frequent locking???

Color getPixel (uint x, uint y) const
 get a pixel

real getPixelGray (uint x, uint y) const
 return the pixel as [0,1] gray


Static Public Member Functions

ImagefromFile (const std::string &fileName)
ImagefromVector (const Vector &v, unsigned width, bool gray)
 Creates an image from a vector of [0,1] reals.


Protected Member Functions

 Image (SDL_Surface *i)
 Create image wrapping the given surface.

int glFormat () const
void setGlPixelStore (bool unpack) const
SDL_Surface * createSameSurface (uint width, uint height) const
 create void surface with the same flags as this

SDL_Surface * createSameSurface () const
void glDraw () const
 direct GL draw (assuming rasterPosition is set)

void colorless ()
 Average the color components.

uint32_t color2SDL (const Color &c) const
uint32_t getPixelRaw (uint x, uint y) const
Color sdl2color (uint32_t p) const

Protected Attributes

SDL_Surface * surface


Detailed Description

represents one image (actually a SDL_Context wrapper ..)

Unless you force it by to* functions, you can assume nothing about pixel format of the image! Typical use would therefore be:

Image *raw = Image::fromFile(...); if(!raw) ... Image *rgb_img = raw->toRGBA(); delete(raw); if(!rgb_img) ... rgb_img-toVector(...) delete(rgb_img);

NOTE: some const functions may in theory change state of the Image because they lock the surface Image uses window coordinates where 0,0 is top-left

Todo:
use exceptions instead of NULL ?


Member Enumeration Documentation

anonymous enum
 

Converts the image to vector.

Each choosen byte is mapped into [0,1] real (0=black)

Parameters:
bytes_mask. Sets the bytes you want from each pixel (system-dependent-endian) - e.g. 0x2 | 0x8 means you want 0x00FF0000 and 0x000000FF XXX
Note: you have to make sure the image is in proper pixel format - this function just blindly reads given bytes
Enumeration values:
GRAY_MASK 


Constructor & Destructor Documentation

Image unsigned  xs,
unsigned  ys
 

new image of undefined content in default RGBA pixel format

~Image  ) 
 

Image SDL_Surface *  i  )  [inline, protected]
 

Create image wrapping the given surface.

The created image owns the surface and will free in destructor.


Member Function Documentation

void clear  ) 
 

Image* clone  )  const
 

copy this image (the result is independent)

uint32_t color2SDL const Color c  )  const [protected]
 

void colorless  )  [protected]
 

Average the color components.

The surface must have 4-bytes-per-pixel. The result is a grayscale-looking surface (but it is still RGBA!)

SDL_Surface* createSameSurface  )  const [protected]
 

SDL_Surface* createSameSurface uint  width,
uint  height
const [protected]
 

create void surface with the same flags as this

void display unsigned  xo = 0,
unsigned  yo = 0
const
 

display to the video window (offsets are relative to win coords) if !gl, the video surface is flipped automatically (so far) - under GL you have to do it yourself (in GL mode, the offset is passed directly to glRasterPos --> it's up to caller to give it sense

Image* fromFile const std::string &  fileName  )  [static]
 

Returns:
NULL on failure

Image* fromVector const Vector v,
unsigned  width,
bool  gray
[static]
 

Creates an image from a vector of [0,1] reals.

The real images are mapped into color component bytes (R,G,B or Y,Y,Y (graY))

Parameters:
width x-size of the created image
gray if true, only one value will be used for the three color components (--> resulting in grayscale) else each pixel has three components

Color getAverageColor  )  const throw (Exception)
 

Parameters:
out - [3] vector for color components - will be [0,1]

unsigned getBPP  )  const
 

unsigned getHeight  )  const
 

Color getPixel uint  x,
uint  y
const
 

get a pixel

real getPixelGray uint  x,
uint  y
const
 

return the pixel as [0,1] gray

uint32_t getPixelRaw uint  x,
uint  y
const [protected]
 

unsigned getWidth  )  const
 

void glDraw  )  const [protected]
 

direct GL draw (assuming rasterPosition is set)

int glFormat  )  const [protected]
 

void putPixel const Color c,
uint  x,
uint  y
 

draw a pixel TODO: avoid frequent locking???

void rect const Color c,
uint  x1,
uint  y1,
uint  x2,
uint  y2
 

void resize unsigned  xs,
unsigned  ys
 

Color sdl2color uint32_t  p  )  const [protected]
 

void setGlPixelStore bool  unpack  )  const [protected]
 

void setSubImage const Image src,
unsigned  xo = 0,
unsigned  yo = 0
 

Copy contents of image from the src image to given offset.

The source image can be smaller, but not larger

Image* subImage unsigned  width,
unsigned  height,
unsigned  xOffset = 0,
unsigned  yOffset = 0
const
 

Create a sub-image of the original.

Resulting image has the same pixel format.

Returns:
NULL on failure

void toFile const std::string &  fileName  ) 
 

Save image to file (BMP).

Image* toGray  )  const
 

Image will be converted to 32-RGBA (one pixel = four bytes).

But all three RGB components are equal, so the image is grayscale-only. TODO: could we use one-byte SDL surface? We'd probably need to use palleted surface so the displayed image would be correct.

Image* toRGBA  )  const
 

Image pixel format will be converted to RGBA (one pixel = one byte) Unless you know the input image format, you should convert image with this function before making training examples from a loaded image.

Vector toVector uint8_t  bytes_mask  )  const
 

Image* upsideDown  )  const
 

flip image

Returns:
the flipped clone


Member Data Documentation

SDL_Surface* surface [protected]
 


The documentation for this class was generated from the following file:
Generated on Fri Jun 18 13:18:59 2004 for Annie by doxygen 1.3.5