Visualization Library v1.0.3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

vl::Image Class Reference

Implements a generic 1d, 2d, 3d and cubemap image that can have mipmaps. More...

#include <Image.hpp>

Inheritance diagram for vl::Image:
vl::Object vl::ImagePBO

List of all members.

Public Member Functions

virtual ~Image ()
 Image ()
 Image (const String &path)
 Image (int x, int y, int z, int bytealign, EImageFormat format, EImageType type)
 Note that the image is not allocated.
 Image (const Image &other)
Imageoperator= (const Image &other)
bool isCubemap () const
bool isValid () const
 Returns true if the image has valid width/height/depth, pitch and byte alignment, type/format combination.
EImageDimension dimension () const
void allocate ()
void allocate1D (int x, EImageFormat format, EImageType type)
void allocate2D (int x, int y, int bytealign, EImageFormat format, EImageType type)
void allocate3D (int x, int y, int z, int bytealign, EImageFormat format, EImageType type)
void allocateCubemap (int x, int y, int bytealign, EImageFormat format, EImageType type)
void reset (int x, int y, int z, int bytealign, EImageFormat format, EImageType type, bool is_cubemap)
 Sets up the image configuration & clears the local storage.
void reset ()
 Disposes all the pixel data and resets the image settings to its defaults.
int byteAlignment () const
 Returns the byte-alignment of the row of the image.
void setByteAlignment (int bytealign)
 Modifies the byte-alignment of the rows of the image, thus changing its pitch.
int bitsPerPixel () const
int requiredMemory () const
 Returns the number of bytes requested to store the image.
String print () const
String printType () const
String printFormat () const
void setWidth (int x)
void setHeight (int y)
void setDepth (int z)
void setFormat (EImageFormat format)
void setType (EImageType type)
bool hasAlpha () const
 Whether an image contains relevant alpha information.
void setHasAlpha (bool has_alpha)
 Whether an image contains relevant alpha information.
int alphaBits () const
 The number of bits dedicated to the alpha channel.
bool isNormalMap () const
 Whether an image represents a normal map.
void setIsNormalMap (bool is_normalmap)
 Whether an image represents a normal map.
const KeyValuestags () const
 A set of key/value couples that can be used to attach extra information to an image like DICOM information etc.
KeyValuestags ()
 A set of key/value couples that can be used to attach extra information to an image like DICOM information etc.
void setTags (KeyValues *tags)
 A set of key/value couples that can be used to attach extra information to an image like DICOM information etc.
void setImageBuffer (Buffer *buffer)
 The buffer used to store the image pixels.
BufferimageBuffer ()
 The buffer used to store the image pixels.
const BufferimageBuffer () const
 The buffer used to store the image pixels.
const unsigned char * pixels () const
unsigned char * pixels ()
bool empty ()
unsigned char * pixelsZSlice (int slice)
 Returns the pixels of the specified Z slice of a 3D image.
unsigned char * pixelsXP ()
unsigned char * pixelsXN ()
unsigned char * pixelsYP ()
unsigned char * pixelsYN ()
unsigned char * pixelsZP ()
unsigned char * pixelsZN ()
const unsigned char * pixelsXP () const
const unsigned char * pixelsXN () const
const unsigned char * pixelsYP () const
const unsigned char * pixelsYN () const
const unsigned char * pixelsZP () const
const unsigned char * pixelsZN () const
void setMipmaps (const std::vector< ref< Image > > &mipmaps)
const std::vector< ref< Image > > & mipmaps () const
std::vector< ref< Image > > & mipmaps ()
int width () const
int height () const
int depth () const
int pitch () const
EImageFormat format () const
EImageType type () const
int isCompressedFormat (EImageFormat fmt)
void flipVertically ()
ref< ImageconvertType (EImageType new_type) const
 Converts the type() of an image.
ref< ImageconvertFormat (EImageFormat new_format) const
 Converts the format() of an image.
bool equalize ()
 Equalizes the image. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps.
bool contrast (float black, float white)
 Adjusts the contrast of an image. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps.
bool contrastHounsfieldAuto ()
 Adjusts the contrast of an image using the window-center/window-with method used for CT images. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps.
bool contrastHounsfield (float center, float width, float intercept, float range)
 Adjusts the contrast of an image using the window-center/window-with method used for CT images. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps.
fvec4 sampleLinear (double x) const
 Performs a sampling on a 1d image using linear filtering.
fvec4 sampleLinear (double x, double y) const
 Performs a sampling on a 2d image using bilinear filtering.
fvec4 sampleLinear (double x, double y, double z) const
 Performs a sampling on a 3d image using trilinear filtering.
fvec4 sample (int x, int y=0, int z=0) const
 Returns the color associated to the specified pixel.
ref< ImagesubImage (int xstart, int ystart, int width, int height)
 Creates a new image containing the specified rectangular pixel area taken from the source image.
void copySubImage (Image *img_src, RectI src, ivec2 dst)
 Copies the rectangular area specified by src of img_src into an Image at position dst.
void substituteColorRGB_RGBA (unsigned int before, unsigned int after)
 Substitutes the color 'before' with the new color 'after'.
void substituteColorRGB_RGB (unsigned int before, unsigned int after)
 Substitutes the color 'before' with the new color 'after'.
void substituteColorGreenKey (unsigned int col0, unsigned int col1)
const StringfilePath () const
 The file from which the image was loaded.
void setFilePath (const String &path)
 The file from which the image was loaded.

Static Public Member Functions

static int bitsPerPixel (EImageType type, EImageFormat format)
 Returns the number of bits used to represents one pixel.
static int requiredMemory (int x, int y, int z, int bytealign, EImageFormat format, EImageType type, bool is_cubemap)
static int requiredMemory1D (int x, EImageFormat format, EImageType type)
static int requiredMemory2D (int x, int y, int bytealign, EImageFormat format, EImageType type)
static int requiredMemory3D (int x, int y, int z, int bytealign, EImageFormat format, EImageType type)
static int requiredMemoryCubemap (int x, int y, int bytealign, EImageFormat format, EImageType type)

Protected Member Functions

void updatePitch ()

Protected Attributes

ref< BuffermPixels
ref< KeyValuesmTags
String mFilePath
std::vector< ref< Image > > mMipmaps
int mWidth
int mHeight
int mDepth
int mPitch
int mByteAlign
EImageFormat mFormat
EImageType mType
bool mIsCubemap
bool mIsNormalMap
bool mHasAlpha

Detailed Description

Implements a generic 1d, 2d, 3d and cubemap image that can have mipmaps.

Remarks:
The copy operator performs a deep copy of all the pixel data and thus is to be considered an expensive operation.

Definition at line 54 of file Image.hpp.


Constructor & Destructor Documentation

Image::~Image (  ) [virtual]

Definition at line 51 of file Image.cpp.

References reset().

Image::Image (  )

Definition at line 56 of file Image.cpp.

References mPixels, reset(), and VL_DEBUG_SET_OBJECT_NAME.

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

Image::Image ( const String path )
Image::Image ( int  x,
int  y,
int  z,
int  bytealign,
EImageFormat  format,
EImageType  type 
)

Note that the image is not allocated.

Definition at line 101 of file Image.cpp.

References allocate1D(), allocate2D(), allocate3D(), mPixels, setByteAlignment(), and VL_DEBUG_SET_OBJECT_NAME.

Image::Image ( const Image other )

Definition at line 63 of file Image.cpp.

References mPixels, reset(), and VL_DEBUG_SET_OBJECT_NAME.


Member Function Documentation

Image & Image::operator= ( const Image other )
bool vl::Image::isCubemap (  ) const [inline]
bool Image::isValid (  ) const

Returns true if the image has valid width/height/depth, pitch and byte alignment, type/format combination.

Remarks:
In order to be valid an image must be at least 1x0x0 (1D image) or 1x1x0 (2D or cubemap image) or 1x1x1 (3D image). Sizes like Nx0xM, 0xNxM, 0xNx0, 0x0xN, 0x0x0 are not valid.
Invalid type/format combinations are for example:
  • OGL_RGB / IT_UNSIGNED_SHORT_4_4_4_4: since here the format has 3 components while the type has 4.
  • IF_COMPRESSED_RGB_S3TC_DXT1_EXT / IT_BYTE: since compressed formats require IT_IMPLICIT_TYPE.

Definition at line 127 of file Image.cpp.

References vl::Log::debug(), format(), vl::IF_BGR, vl::IF_BGRA, vl::IF_COMPRESSED_RGB_S3TC_DXT1, vl::IF_COMPRESSED_RGBA_S3TC_DXT1, vl::IF_COMPRESSED_RGBA_S3TC_DXT3, vl::IF_COMPRESSED_RGBA_S3TC_DXT5, vl::IF_DEPTH_STENCIL, vl::IF_RGB, vl::IF_RGBA, vl::IT_BYTE, vl::IT_FLOAT, vl::IT_FLOAT_32_UNSIGNED_INT_24_8_REV, vl::IT_IMPLICIT_TYPE, vl::IT_INT, vl::IT_SHORT, vl::IT_UNSIGNED_BYTE, vl::IT_UNSIGNED_BYTE_2_3_3_REV, vl::IT_UNSIGNED_BYTE_3_3_2, vl::IT_UNSIGNED_INT, vl::IT_UNSIGNED_INT_10_10_10_2, vl::IT_UNSIGNED_INT_10F_11F_11F_REV, vl::IT_UNSIGNED_INT_24_8, vl::IT_UNSIGNED_INT_2_10_10_10_REV, vl::IT_UNSIGNED_INT_5_9_9_9_REV, vl::IT_UNSIGNED_INT_8_8_8_8, vl::IT_UNSIGNED_INT_8_8_8_8_REV, vl::IT_UNSIGNED_SHORT, vl::IT_UNSIGNED_SHORT_1_5_5_5_REV, vl::IT_UNSIGNED_SHORT_4_4_4_4, vl::IT_UNSIGNED_SHORT_4_4_4_4_REV, vl::IT_UNSIGNED_SHORT_5_5_5_1, vl::IT_UNSIGNED_SHORT_5_6_5, vl::IT_UNSIGNED_SHORT_5_6_5_REV, mByteAlign, mDepth, mHeight, mWidth, pitch(), print(), and type().

Referenced by vl::DrawPixels::render_Implementation(), requiredMemory(), and vl::Texture::Texture().

EImageDimension Image::dimension (  ) const
void Image::allocate (  )

Definition at line 591 of file Image.cpp.

References mMipmaps, mPixels, and requiredMemory().

void Image::allocate1D ( int  x,
EImageFormat  format,
EImageType  type 
)
void Image::allocate2D ( int  x,
int  y,
int  bytealign,
EImageFormat  format,
EImageType  type 
)
void Image::allocate3D ( int  x,
int  y,
int  z,
int  bytealign,
EImageFormat  format,
EImageType  type 
)
void Image::allocateCubemap ( int  x,
int  y,
int  bytealign,
EImageFormat  format,
EImageType  type 
)
void Image::reset ( int  x,
int  y,
int  z,
int  bytealign,
EImageFormat  format,
EImageType  type,
bool  is_cubemap 
)

Sets up the image configuration & clears the local storage.

Definition at line 651 of file Image.cpp.

References mIsCubemap, reset(), setByteAlignment(), setDepth(), setFormat(), setHeight(), setType(), and setWidth().

Referenced by vl::readPixels().

void Image::reset (  )

Disposes all the pixel data and resets the image settings to its defaults.

Definition at line 664 of file Image.cpp.

References vl::IF_RGBA, vl::IT_UNSIGNED_BYTE, mByteAlign, mDepth, mFormat, mHasAlpha, mHeight, mIsCubemap, mIsNormalMap, mMipmaps, vl::Object::mObjectName, mPitch, mPixels, mType, and mWidth.

Referenced by allocate1D(), allocate2D(), allocate3D(), allocateCubemap(), Image(), reset(), and ~Image().

int Image::byteAlignment (  ) const

Returns the byte-alignment of the row of the image.

Possible return values are 1, 2, 4 and 8.

Definition at line 531 of file Image.cpp.

References mByteAlign.

Referenced by pixelsXN(), pixelsYN(), pixelsYP(), pixelsZN(), pixelsZP(), print(), vl::DrawPixels::render_Implementation(), requiredMemory(), and vl::Texture::setMipLevel().

void Image::setByteAlignment ( int  bytealign )

Modifies the byte-alignment of the rows of the image, thus changing its pitch.

Only values like 0, 1, 2, 4 and 8 are allowed. If 0 is passed the byte-alignment takes the value returned by "sizeof(unsigned char*)".

Remarks:
This function must be called before the allocate() function or in any case on a non allocated image otherwise it won't have any effect.

Definition at line 541 of file Image.cpp.

References mByteAlign, mPixels, updatePitch(), VL_CHECK, and VL_TRAP.

Referenced by allocate1D(), allocate2D(), allocate3D(), allocateCubemap(), Image(), and reset().

int Image::bitsPerPixel ( EImageType  type,
EImageFormat  format 
) [static]
int vl::Image::bitsPerPixel (  ) const [inline]

Definition at line 99 of file Image.hpp.

References bitsPerPixel().

Referenced by bitsPerPixel(), copySubImage(), requiredMemory(), subImage(), and updatePitch().

int Image::requiredMemory (  ) const

Returns the number of bytes requested to store the image.

Doesn't take into consideration mipmaps.

Definition at line 523 of file Image.cpp.

References byteAlignment(), depth(), format(), height(), isCubemap(), isValid(), type(), VL_CHECK, and width().

Referenced by allocate(), allocate1D(), allocate2D(), allocate3D(), allocateCubemap(), vl::createCubemap(), vl::loadDDS(), vl::saveTGA(), vl::saveTIFF(), and vl::Texture::setMipLevel().

int Image::requiredMemory ( int  x,
int  y,
int  z,
int  bytealign,
EImageFormat  format,
EImageType  type,
bool  is_cubemap 
) [static]
static int vl::Image::requiredMemory1D ( int  x,
EImageFormat  format,
EImageType  type 
) [inline, static]

Definition at line 105 of file Image.hpp.

static int vl::Image::requiredMemory2D ( int  x,
int  y,
int  bytealign,
EImageFormat  format,
EImageType  type 
) [inline, static]

Definition at line 107 of file Image.hpp.

Referenced by pixelsXN(), pixelsYN(), pixelsYP(), pixelsZN(), pixelsZP(), and vl::readPixels().

static int vl::Image::requiredMemory3D ( int  x,
int  y,
int  z,
int  bytealign,
EImageFormat  format,
EImageType  type 
) [inline, static]

Definition at line 109 of file Image.hpp.

static int vl::Image::requiredMemoryCubemap ( int  x,
int  y,
int  bytealign,
EImageFormat  format,
EImageType  type 
) [inline, static]

Definition at line 111 of file Image.hpp.

String Image::print (  ) const

Definition at line 342 of file Image.cpp.

References byteAlignment(), depth(), height(), vl::Object::objectName(), pitch(), printFormat(), printType(), and width().

Referenced by isValid().

String Image::printType (  ) const
String Image::printFormat (  ) const
void vl::Image::setWidth ( int  x ) [inline]

Definition at line 119 of file Image.hpp.

Referenced by allocate1D(), allocate2D(), allocate3D(), allocateCubemap(), and reset().

void vl::Image::setHeight ( int  y ) [inline]

Definition at line 121 of file Image.hpp.

Referenced by allocate1D(), allocate2D(), allocate3D(), allocateCubemap(), and reset().

void vl::Image::setDepth ( int  z ) [inline]

Definition at line 123 of file Image.hpp.

Referenced by allocate1D(), allocate2D(), allocate3D(), allocateCubemap(), and reset().

void vl::Image::setFormat ( EImageFormat  format ) [inline]

Definition at line 125 of file Image.hpp.

Referenced by allocate1D(), allocate2D(), allocate3D(), allocateCubemap(), and reset().

void vl::Image::setType ( EImageType  type ) [inline]

Definition at line 127 of file Image.hpp.

Referenced by allocate1D(), allocate2D(), allocate3D(), allocateCubemap(), and reset().

bool vl::Image::hasAlpha (  ) const [inline]

Whether an image contains relevant alpha information.

Definition at line 130 of file Image.hpp.

void vl::Image::setHasAlpha ( bool  has_alpha ) [inline]

Whether an image contains relevant alpha information.

Definition at line 133 of file Image.hpp.

int Image::alphaBits (  ) const
bool vl::Image::isNormalMap (  ) const [inline]

Whether an image represents a normal map.

Definition at line 139 of file Image.hpp.

void vl::Image::setIsNormalMap ( bool  is_normalmap ) [inline]

Whether an image represents a normal map.

Definition at line 142 of file Image.hpp.

const KeyValues* vl::Image::tags (  ) const [inline]

A set of key/value couples that can be used to attach extra information to an image like DICOM information etc.

Returns NULL by default.

Definition at line 146 of file Image.hpp.

Referenced by contrastHounsfieldAuto().

KeyValues* vl::Image::tags (  ) [inline]

A set of key/value couples that can be used to attach extra information to an image like DICOM information etc.

Returns NULL by default.

Definition at line 150 of file Image.hpp.

void vl::Image::setTags ( KeyValues tags ) [inline]

A set of key/value couples that can be used to attach extra information to an image like DICOM information etc.

Definition at line 153 of file Image.hpp.

void vl::Image::setImageBuffer ( Buffer buffer ) [inline]

The buffer used to store the image pixels.

Definition at line 156 of file Image.hpp.

Buffer* vl::Image::imageBuffer (  ) [inline]

The buffer used to store the image pixels.

Definition at line 159 of file Image.hpp.

Referenced by vl::readPixels().

const Buffer* vl::Image::imageBuffer (  ) const [inline]

The buffer used to store the image pixels.

Definition at line 162 of file Image.hpp.

const unsigned char* vl::Image::pixels (  ) const [inline]
unsigned char* vl::Image::pixels (  ) [inline]

Definition at line 166 of file Image.hpp.

References NULL.

bool vl::Image::empty (  ) [inline]

Definition at line 168 of file Image.hpp.

References NULL.

unsigned char * Image::pixelsZSlice ( int  slice )

Returns the pixels of the specified Z slice of a 3D image.

Definition at line 819 of file Image.cpp.

References depth(), height(), mIsCubemap, NULL, pitch(), pixels(), and VL_CHECK.

Referenced by flipVertically().

unsigned char * Image::pixelsXP (  )

Definition at line 719 of file Image.cpp.

References dimension(), NULL, pixels(), and VL_CHECK.

Referenced by flipVertically(), and vl::Texture::setMipLevel().

unsigned char * Image::pixelsXN (  )
unsigned char * Image::pixelsYP (  )
unsigned char * Image::pixelsYN (  )
unsigned char * Image::pixelsZP (  )
unsigned char * Image::pixelsZN (  )
const unsigned char * Image::pixelsXP (  ) const

Definition at line 710 of file Image.cpp.

References dimension(), NULL, pixels(), and VL_CHECK.

const unsigned char * Image::pixelsXN (  ) const
const unsigned char * Image::pixelsYP (  ) const
const unsigned char * Image::pixelsYN (  ) const
const unsigned char * Image::pixelsZP (  ) const
const unsigned char * Image::pixelsZN (  ) const
void vl::Image::setMipmaps ( const std::vector< ref< Image > > &  mipmaps ) [inline]

Definition at line 186 of file Image.hpp.

const std::vector< ref<Image> >& vl::Image::mipmaps (  ) const [inline]

Definition at line 188 of file Image.hpp.

std::vector< ref<Image> >& vl::Image::mipmaps (  ) [inline]

Definition at line 190 of file Image.hpp.

int vl::Image::width (  ) const [inline]
int vl::Image::height (  ) const [inline]
int vl::Image::depth (  ) const [inline]
int vl::Image::pitch (  ) const [inline]
EImageFormat vl::Image::format (  ) const [inline]
EImageType vl::Image::type (  ) const [inline]
int Image::isCompressedFormat ( EImageFormat  fmt )
void Image::flipVertically (  )
ref< Image > vl::Image::convertType ( EImageType  new_type ) const

Converts the type() of an image.

The source image type and the new type must be one of the following:

  • IT_UNSIGNED_BYTE
  • IT_BYTE
  • IT_UNSIGNED_SHORT
  • IT_SHORT
  • IT_UNSIGNED_INT
  • IT_INT
  • IT_FLOAT

The source image format must be one of the following:

  • IF_RGB
  • IF_RGBA
  • IF_BGR
  • IF_BGRA
  • IF_RED
  • IF_GREEN
  • IF_BLUE
  • IF_ALPHA
  • IF_LUMINANCE
  • IF_LUMINANCE_ALPHA
  • IF_DEPTH_COMPONENT

Definition at line 1269 of file Image.cpp.

References vl::Log::error(), vl::IF_ALPHA, vl::IF_BGR, vl::IF_BGRA, vl::IF_BLUE, vl::IF_DEPTH_COMPONENT, vl::IF_GREEN, vl::IF_LUMINANCE, vl::IF_LUMINANCE_ALPHA, vl::IF_RED, vl::IF_RGB, vl::IF_RGBA, vl::IT_BYTE, vl::IT_FLOAT, vl::IT_INT, vl::IT_SHORT, vl::IT_UNSIGNED_BYTE, vl::IT_UNSIGNED_INT, vl::IT_UNSIGNED_SHORT, and NULL.

Referenced by vl::saveJPG(), vl::savePNG(), vl::saveTGA(), and vl::saveTIFF().

ref< Image > vl::Image::convertFormat ( EImageFormat  new_format ) const

Converts the format() of an image.

The source image type must be one of the following:

  • IT_UNSIGNED_BYTE
  • IT_BYTE
  • IT_UNSIGNED_SHORT
  • IT_SHORT
  • IT_UNSIGNED_INT
  • IT_INT
  • IT_FLOAT

The source image format and the new format must be one of the following:

  • IF_RGB
  • IF_RGBA
  • IF_BGR
  • IF_BGRA
  • IF_RED
  • IF_GREEN
  • IF_BLUE
  • IF_ALPHA
  • IF_LUMINANCE
  • IF_LUMINANCE_ALPHA

Definition at line 1685 of file Image.cpp.

References vl::Log::error(), vl::IF_ALPHA, vl::IF_BGR, vl::IF_BGRA, vl::IF_BLUE, vl::IF_DEPTH_COMPONENT, vl::IF_GREEN, vl::IF_LUMINANCE, vl::IF_LUMINANCE_ALPHA, vl::IF_RED, vl::IF_RGB, vl::IF_RGBA, vl::IT_BYTE, vl::IT_FLOAT, vl::IT_INT, vl::IT_SHORT, vl::IT_UNSIGNED_BYTE, vl::IT_UNSIGNED_INT, vl::IT_UNSIGNED_SHORT, and NULL.

Referenced by vl::saveJPG(), vl::savePNG(), vl::saveTGA(), and vl::saveTIFF().

bool Image::equalize (  )

Equalizes the image. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps.

This function is mainly useful for images whose type() is IF_LUMINANCE, IF_RED, IF_GREEN, IF_BLUE, IF_ALPHA or IF_DEPTH_COMPONENT.

IF_RGB, IF_RGBA, IF_BGR, IF_BGRA and IF_LUMINANCE_ALPHA types are not optimally handled yet.

Definition at line 1461 of file Image.cpp.

References depth(), vl::Log::error(), format(), height(), vl::IF_ALPHA, vl::IF_BGR, vl::IF_BGRA, vl::IF_BLUE, vl::IF_DEPTH_COMPONENT, vl::IF_GREEN, vl::IF_LUMINANCE, vl::IF_LUMINANCE_ALPHA, vl::IF_RED, vl::IF_RGB, vl::IF_RGBA, isCubemap(), vl::IT_FLOAT, vl::IT_UNSIGNED_BYTE, vl::IT_UNSIGNED_INT, vl::IT_UNSIGNED_SHORT, pitch(), pixels(), type(), and width().

bool Image::contrast ( float  black,
float  white 
)

Adjusts the contrast of an image. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps.

This function supports only images whose type() is IF_LUMINANCE, IF_RED, IF_GREEN, IF_BLUE, IF_ALPHA or IF_DEPTH_COMPONENT.

The parameters black and white are in normalized units (0=black, 1=white) but are not required to be in the range between 0 and 1.

Definition at line 1580 of file Image.cpp.

References depth(), vl::Log::error(), format(), height(), vl::IF_ALPHA, vl::IF_BLUE, vl::IF_DEPTH_COMPONENT, vl::IF_GREEN, vl::IF_LUMINANCE, vl::IF_RED, isCubemap(), vl::IT_FLOAT, vl::IT_UNSIGNED_BYTE, vl::IT_UNSIGNED_INT, vl::IT_UNSIGNED_SHORT, pitch(), pixels(), type(), and width().

Referenced by contrastHounsfield(), and contrastHounsfieldAuto().

bool Image::contrastHounsfieldAuto (  )

Adjusts the contrast of an image using the window-center/window-with method used for CT images. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps.

The center and width parameters are in Hounsfield units.

Calls contrastHounsfield(float center, float width, float intercept, float range) with center, with, range and intercept parameters extracted from the image tags() "WindowCenter", "WindowWidth", "BitsStored" and "RescaleIntercept". This function is equivalent to the code below.

if ( !tags()->has("WindowCenter") || !tags()->has("WindowWidth") || !tags()->has("BitsStored") || !tags()->has("RescaleIntercept"))
  return false;

float center    = tags()->value("WindowCenter").toFloat();
float width     = tags()->value("WindowWidth").toFloat();
float range     = (1<<tags()->value("BitsStored").toInt()) - 1.0f;
float intercept = tags()->value("RescaleIntercept").toFloat();

// Hounsfield units: -1000 = air, +1000 = solid bone
// Transform from Hounsfield units to normalized 0..1 units
center = (center-intercept) / range;
width  = width / range;
return contrast( center-width/2.0f, center+width/2.0f );

Definition at line 1523 of file Image.cpp.

References contrast(), tags(), vl::String::toFloat(), vl::String::toInt(), and vl::KeyValues::value().

bool Image::contrastHounsfield ( float  center,
float  width,
float  intercept,
float  range 
)

Adjusts the contrast of an image using the window-center/window-with method used for CT images. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps.

The center and width parameters are in Hounsfield units.

This function is equivalent to the code below:

// Hounsfield units: -1000 = air, +1000 = solid bone
// Transform from Hounsfield units to normalized 0..1 units
center = (center-intercept) / range;
width  = width / range;
return contrast( center-width/2.0f, center+width/2.0f );

Definition at line 1551 of file Image.cpp.

References contrast().

fvec4 Image::sampleLinear ( double  x ) const

Performs a sampling on a 1d image using linear filtering.

Definition at line 1871 of file Image.cpp.

References vl::fract(), sample(), VL_CHECK, and width().

fvec4 Image::sampleLinear ( double  x,
double  y 
) const

Performs a sampling on a 2d image using bilinear filtering.

Definition at line 1892 of file Image.cpp.

References vl::fract(), height(), sample(), VL_CHECK, and width().

fvec4 Image::sampleLinear ( double  x,
double  y,
double  z 
) const

Performs a sampling on a 3d image using trilinear filtering.

Definition at line 1930 of file Image.cpp.

References depth(), height(), sample(), and width().

fvec4 Image::sample ( int  x,
int  y = 0,
int  z = 0 
) const

Returns the color associated to the specified pixel.

The rgb values are mapped to 0..1 for all image types but IT_FLOAT. The value returned for images of type IT_FLOAT is returned exactly as is stored in the image.

The image type() must be one of the following:

  • IT_UNSIGNED_BYTE
  • IT_BYTE
  • IT_UNSIGNED_SHORT
  • IT_SHORT
  • IT_UNSIGNED_INT
  • IT_INT
  • IT_FLOAT

The image format() must be one of the following:

  • IF_RGB
  • IF_RGBA
  • IF_BGR
  • IF_BGRA
  • IF_RED
  • IF_GREEN
  • IF_BLUE
  • IF_ALPHA
  • IF_LUMINANCE
  • IF_LUMINANCE_ALPHA
  • IF_DEPTH_COMPONENT

Definition at line 1964 of file Image.cpp.

References vl::Vector4< T_Scalar >::b(), depth(), format(), height(), vl::IF_ALPHA, vl::IF_BGR, vl::IF_BGRA, vl::IF_BLUE, vl::IF_DEPTH_COMPONENT, vl::IF_GREEN, vl::IF_LUMINANCE, vl::IF_LUMINANCE_ALPHA, vl::IF_RED, vl::IF_RGB, vl::IF_RGBA, vl::IT_BYTE, vl::IT_FLOAT, vl::IT_INT, vl::IT_SHORT, vl::IT_UNSIGNED_BYTE, vl::IT_UNSIGNED_INT, vl::IT_UNSIGNED_SHORT, pitch(), pixels(), vl::Vector4< T_Scalar >::r(), type(), VL_CHECK, and width().

Referenced by vl::genGradientNormals(), and sampleLinear().

ref< Image > Image::subImage ( int  xstart,
int  ystart,
int  width,
int  height 
)

Creates a new image containing the specified rectangular pixel area taken from the source image.

The returned image is of the same type() and format() of the original one.

Note:
  • This function supports only 2d images.
  • This function does not support compressed types and formats.

Definition at line 2052 of file Image.cpp.

References bitsPerPixel(), format(), height(), Image(), pitch(), pixels(), type(), VL_CHECK, and width().

void Image::copySubImage ( Image img_src,
RectI  src,
ivec2  dst 
)

Copies the rectangular area specified by src of img_src into an Image at position dst.

The source and destination image should be of the same type() and format() for maximum performances.

Definition at line 2069 of file Image.cpp.

References bitsPerPixel(), format(), height(), vl::Rect< T >::height(), pitch(), pixels(), vl::RectI::right(), vl::RectI::top(), type(), VL_CHECK, width(), vl::Rect< T >::width(), vl::Rect< T >::x(), vl::Vector2< T_Scalar >::x(), vl::Rect< T >::y(), and vl::Vector2< T_Scalar >::y().

void Image::substituteColorRGB_RGBA ( unsigned int  before,
unsigned int  after 
)

Substitutes the color 'before' with the new color 'after'.

Parameters:
beforeis an hexadecimal representation of an RGB triplet given in the form 0xRRGGBB.
afteris an hexadecimal representation of an RGBA quadruplet given in the form 0xRRGGBBAA. For example 0xFF0000FF is opaque red, 0x00FF0088 is half transparent green. This function can be very useful when you want to modify a specified color of an image or when you want to perform color-key transparency, i.e. when you want to set the transparency of the pixels that have a particular color.
Note:
  • This function can be used only if the image type() is IT_UNSIGNED_BYTE and format() is either IF_RGB or IF_RGBA.
  • If the image format() is set to IF_RGB then the alpha value specified in 'after' is ignored.
  • If you want to be sure to keep the alpha channel intact use the substituteColorRGB_RGB() function instead.

Definition at line 2095 of file Image.cpp.

References depth(), vl::Log::error(), format(), height(), vl::IF_RGB, vl::IF_RGBA, vl::IT_UNSIGNED_BYTE, pitch(), pixels(), type(), and width().

void Image::substituteColorRGB_RGB ( unsigned int  before,
unsigned int  after 
)

Substitutes the color 'before' with the new color 'after'.

Parameters:
beforeis an hexadecimal representation of an RGB triplet given in the form 0xRRGGBB.
afteris an hexadecimal representation of an RGB tripet given in the form 0xRRGGBB. For example 0xFF0000 is opaque red, 0x00FF00 is green. This function can be very useful when you want to modify a specified color of an image but you want to keep the alpha channel intact.
Note:
  • This function can be used only if the image type() is IT_UNSIGNED_BYTE and format() is either IF_RGB or IF_RGBA.
  • If you want to change the alpha channel of the modified pixels use the substituteColorRGB_RGBA() function instead.

Definition at line 2137 of file Image.cpp.

References depth(), vl::Log::error(), format(), height(), vl::IF_RGB, vl::IF_RGBA, vl::IT_UNSIGNED_BYTE, pitch(), pixels(), type(), and width().

void Image::substituteColorGreenKey ( unsigned int  col0,
unsigned int  col1 
)
const String& vl::Image::filePath (  ) const [inline]

The file from which the image was loaded.

Definition at line 356 of file Image.hpp.

Referenced by vl::VLXClassWrapper_Texture::exportTexture().

void vl::Image::setFilePath ( const String path ) [inline]

The file from which the image was loaded.

Definition at line 359 of file Image.hpp.

void Image::updatePitch (  ) [protected]

Definition at line 568 of file Image.cpp.

References bitsPerPixel(), mByteAlign, mPitch, and mWidth.

Referenced by setByteAlignment().


Member Data Documentation

Definition at line 366 of file Image.hpp.

Definition at line 367 of file Image.hpp.

Referenced by Image().

std::vector< ref<Image> > vl::Image::mMipmaps [protected]

Definition at line 368 of file Image.hpp.

Referenced by allocate(), Image(), operator=(), and reset().

int vl::Image::mWidth [protected]

Definition at line 369 of file Image.hpp.

Referenced by dimension(), Image(), isValid(), operator=(), reset(), and updatePitch().

int vl::Image::mHeight [protected]

Definition at line 370 of file Image.hpp.

Referenced by dimension(), Image(), isValid(), operator=(), and reset().

int vl::Image::mDepth [protected]

Definition at line 371 of file Image.hpp.

Referenced by dimension(), Image(), isValid(), operator=(), and reset().

int vl::Image::mPitch [protected]

Definition at line 372 of file Image.hpp.

Referenced by Image(), operator=(), reset(), and updatePitch().

int vl::Image::mByteAlign [protected]

Definition at line 373 of file Image.hpp.

Referenced by byteAlignment(), Image(), isValid(), operator=(), reset(), setByteAlignment(), and updatePitch().

Definition at line 374 of file Image.hpp.

Referenced by Image(), operator=(), and reset().

Definition at line 375 of file Image.hpp.

Referenced by Image(), operator=(), and reset().

bool vl::Image::mIsCubemap [protected]
bool vl::Image::mIsNormalMap [protected]

Definition at line 377 of file Image.hpp.

Referenced by Image(), operator=(), and reset().

bool vl::Image::mHasAlpha [protected]

Definition at line 378 of file Image.hpp.

Referenced by Image(), operator=(), and reset().


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

Visualization Library v1.0.3 Reference Documentation
Copyright Michele Bosi. All rights reserved.
Updated on Tue Feb 7 2017 00:55:06.
Permission is granted to use this page to write and publish articles regarding Visualization Library.