Visualization Library 2.0.0

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 | List of all members
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:

Public Member Functions

virtual ~Image ()
 
 Image ()
 Constructor. More...
 
 Image (void *buffer_ptr, int buffer_bytes)
 Initializes the image to use vl::Buffer::UserAllocatedBuffer mode and the given buffer instead of allocating its own buffer. More...
 
 Image (const String &file_path)
 Initializes the image reading from the give file path. More...
 
 Image (int x, int y, int z, int bytealign, EImageFormat format, EImageType type)
 Initializes a 1D, 2D or 3D image. For 2D images y and z must be set to 0. For 3D images z must be set to 0. More...
 
 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. More...
 
EImageDimension dimension () const
 
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. More...
 
void reset ()
 Disposes all the pixel data and resets the image settings to its defaults. More...
 
int byteAlignment () const
 Returns the byte-alignment of the row of the image. More...
 
void setByteAlignment (int bytealign)
 Modifies the byte-alignment of the rows of the image, thus changing its pitch. More...
 
int bitsPerPixel () const
 
int requiredMemory () const
 Returns the number of bytes requested to store the image. More...
 
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. More...
 
void setHasAlpha (bool has_alpha)
 Whether an image contains relevant alpha information. More...
 
int alphaBits () const
 The number of bits dedicated to the alpha channel. More...
 
bool isNormalMap () const
 Whether an image represents a normal map. More...
 
void setIsNormalMap (bool is_normalmap)
 Whether an image represents a normal map. More...
 
const KeyValuestags () const
 A set of key/value couples that can be used to attach extra information to an image like DICOM information etc. More...
 
KeyValuestags ()
 A set of key/value couples that can be used to attach extra information to an image like DICOM information etc. More...
 
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. More...
 
void setImageBuffer (Buffer *buffer)
 The buffer used to store the image pixels. More...
 
BufferimageBuffer ()
 The buffer used to store the image pixels. More...
 
const BufferimageBuffer () const
 The buffer used to store the image pixels. More...
 
const unsigned char * pixels () const
 Raw pointer to pixels. More...
 
unsigned char * pixels ()
 Raw pointer to pixels. More...
 
bool empty ()
 True if image is empty. More...
 
unsigned char * pixelsZSlice (int zth_slice)
 Zth slice of 3D image. More...
 
unsigned char * pixelsXP ()
 X-positive cubemap face. More...
 
unsigned char * pixelsXN ()
 X-negative cubemap face. More...
 
unsigned char * pixelsYP ()
 Y-positive cubemap face. More...
 
unsigned char * pixelsYN ()
 Y-negative cubemap face. More...
 
unsigned char * pixelsZP ()
 Z-positive cubemap face. More...
 
unsigned char * pixelsZN ()
 Z-negative cubemap face. More...
 
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. More...
 
ref< ImageconvertFormat (EImageFormat new_format) const
 Converts the format() of an image. More...
 
bool equalize ()
 Equalizes the image. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps. More...
 
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. More...
 
bool contrastHounsfieldAuto ()
 Adjusts the contrast of an image using the window-center/window-width method used for CT images. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps. More...
 
bool contrastHounsfield (float center, float width, float intercept, float range)
 Adjusts the contrast of an image using the window-center/window-width method used for CT images. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps. More...
 
fvec4 sampleLinear (double x) const
 Performs a sampling on a 1d image using linear filtering. More...
 
fvec4 sampleLinear (double x, double y) const
 Performs a sampling on a 2d image using bilinear filtering. More...
 
fvec4 sampleLinear (double x, double y, double z) const
 Performs a sampling on a 3d image using trilinear filtering. More...
 
fvec4 sample (int x, int y=0, int z=0) const
 Returns the color associated to the specified pixel. More...
 
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. More...
 
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. More...
 
void substituteColorRGB_RGBA (unsigned int before, unsigned int after)
 Substitutes the color 'before' with the new color 'after'. More...
 
void substituteColorRGB_RGB (unsigned int before, unsigned int after)
 Substitutes the color 'before' with the new color 'after'. More...
 
void substituteColorGreenKey (unsigned int col0, unsigned int col1)
 
const StringfilePath () const
 The file from which the image was loaded. More...
 
void setFilePath (const String &path)
 The file from which the image was loaded. More...
 
- Public Member Functions inherited from vl::Object
 Object ()
 Constructor. More...
 
 Object (const Object &other)
 Copy constructor: copies the name, ref count mutex and user data. More...
 
Objectoperator= (const Object &other)
 Copy operator: copies the object's name, ref count mutex and user data. More...
 
const std::string & objectName () const
 The name of the object, by default set to the object's class name. More...
 
void setObjectName (const char *name)
 The name of the object, by default set to the object's class name in debug builds. More...
 
void setObjectName (const std::string &name)
 The name of the object, by default set to the object's class name in debug builds. More...
 
void setRefCountMutex (IMutex *mutex)
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
IMutexrefCountMutex ()
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
const IMutexrefCountMutex () const
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
int referenceCount () const
 Returns the number of references of an object. More...
 
void incReference () const
 Increments the reference count of an object. More...
 
void decReference ()
 Decrements the reference count of an object and deletes it if both automaticDelete() is true the count reaches 0. More...
 
void setAutomaticDelete (bool autodel_on)
 If set to true the Object is deleted when its reference count reaches 0. More...
 
bool automaticDelete () const
 If set to true the Object is deleted when its reference count reaches 0. More...
 
template<class T >
T * as ()
 Casts an Object to the specified class. More...
 
template<class T >
const T * as () const
 Casts an Object to the specified class. More...
 

Static Public Member Functions

static int bitsPerPixel (EImageType type, EImageFormat format)
 Returns the number of bits used to represents one pixel. More...
 
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 ()
 
void allocate ()
 
- Protected Member Functions inherited from vl::Object
virtual ~Object ()
 

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
 
- Protected Attributes inherited from vl::Object
std::string mObjectName
 
IMutexmRefCountMutex
 
int mReferenceCount
 
bool mAutomaticDelete
 

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::~Image ( )
virtual

Definition at line 51 of file Image.cpp.

References reset().

◆ Image() [1/5]

Image::Image ( )

◆ Image() [2/5]

Image::Image ( void *  buffer_ptr,
int  buffer_bytes 
)

Initializes the image to use vl::Buffer::UserAllocatedBuffer mode and the given buffer instead of allocating its own buffer.

Call allocate1D/2D/3D/Cubemap() to further initialize the image. See also: Image::imageBuffer() and Buffer::setUserAllocatedBuffer().

Definition at line 63 of file Image.cpp.

References mPixels, and reset().

◆ Image() [3/5]

Image::Image ( const String file_path)

Initializes the image reading from the give file path.

Definition at line 79 of file Image.cpp.

References vl::loadImage(), mByteAlign, mDepth, mFilePath, mFormat, mHasAlpha, mHeight, mIsCubemap, mIsNormalMap, mMipmaps, mPitch, mPixels, mType, mWidth, reset(), vl::Object::setObjectName(), and vl::String::toStdString().

◆ Image() [4/5]

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

Initializes a 1D, 2D or 3D image. For 2D images y and z must be set to 0. For 3D images z must be set to 0.

Note that the image is not allocated.

Definition at line 109 of file Image.cpp.

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

◆ Image() [5/5]

Image::Image ( const Image other)

Definition at line 71 of file Image.cpp.

References mPixels, and reset().

Member Function Documentation

◆ allocate()

void Image::allocate ( )
protected

Definition at line 580 of file Image.cpp.

References mMipmaps, mPixels, and requiredMemory().

Referenced by convertFormat(), and convertType().

◆ allocate1D()

void Image::allocate1D ( int  x,
EImageFormat  format,
EImageType  type 
)

◆ allocate2D()

void Image::allocate2D ( int  x,
int  y,
int  bytealign,
EImageFormat  format,
EImageType  type 
)

◆ allocate3D()

void Image::allocate3D ( int  x,
int  y,
int  z,
int  bytealign,
EImageFormat  format,
EImageType  type 
)

◆ allocateCubemap()

void Image::allocateCubemap ( int  x,
int  y,
int  bytealign,
EImageFormat  format,
EImageType  type 
)

◆ alphaBits()

int Image::alphaBits ( ) const

◆ bitsPerPixel() [1/2]

int Image::bitsPerPixel ( EImageType  type,
EImageFormat  format 
)
static

◆ bitsPerPixel() [2/2]

int vl::Image::bitsPerPixel ( ) const
inline

◆ byteAlignment()

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 540 of file Image.cpp.

References mByteAlign.

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

◆ contrast()

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 1614 of file Image.cpp.

References depth(), vl::dot(), 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().

◆ contrastHounsfield()

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

Adjusts the contrast of an image using the window-center/window-width 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 1585 of file Image.cpp.

References vl::clamp(), contrast(), and pitch().

◆ contrastHounsfieldAuto()

bool Image::contrastHounsfieldAuto ( )

Adjusts the contrast of an image using the window-center/window-width 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 1557 of file Image.cpp.

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

◆ convertFormat()

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 1719 of file Image.cpp.

References allocate(), 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, Image(), isCubemap(), vl::IT_BYTE, vl::IT_FLOAT, vl::IT_INT, vl::IT_SHORT, vl::IT_UNSIGNED_BYTE, vl::IT_UNSIGNED_INT, vl::IT_UNSIGNED_SHORT, mHasAlpha, mIsCubemap, mIsNormalMap, NULL, vl::Object::objectName(), pitch(), pixels(), setByteAlignment(), setDepth(), setFormat(), setHeight(), vl::Object::setObjectName(), setType(), setWidth(), type(), and width().

Referenced by copySubImage(), vl::genGradientNormals(), vl::loadBMP(), vl::ObjLoader::loadOBJ(), vl::saveDICOM(), vl::saveJPG(), vl::savePNG(), vl::saveTGA(), and vl::saveTIFF().

◆ convertType()

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 1303 of file Image.cpp.

References allocate(), 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, Image(), isCubemap(), vl::IT_BYTE, vl::IT_FLOAT, vl::IT_INT, vl::IT_SHORT, vl::IT_UNSIGNED_BYTE, vl::IT_UNSIGNED_INT, vl::IT_UNSIGNED_SHORT, mHasAlpha, mIsCubemap, mIsNormalMap, NULL, vl::Object::objectName(), pitch(), pixels(), setByteAlignment(), setDepth(), setFormat(), setHeight(), vl::Object::setObjectName(), setType(), setWidth(), type(), and width().

Referenced by copySubImage(), vl::genGradientNormals(), vl::ObjLoader::loadOBJ(), vl::saveJPG(), vl::savePNG(), vl::saveTGA(), and vl::saveTIFF().

◆ copySubImage()

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 2103 of file Image.cpp.

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

◆ depth()

int vl::Image::depth ( ) const
inline

◆ dimension()

EImageDimension Image::dimension ( ) const

◆ empty()

bool vl::Image::empty ( )
inline

True if image is empty.

Definition at line 176 of file Image.hpp.

References NULL.

◆ equalize()

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 1495 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().

◆ filePath()

const String& vl::Image::filePath ( ) const
inline

The file from which the image was loaded.

Definition at line 371 of file Image.hpp.

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

◆ flipVertically()

void Image::flipVertically ( )

◆ format()

EImageFormat vl::Image::format ( ) const
inline

◆ hasAlpha()

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

Whether an image contains relevant alpha information.

Definition at line 135 of file Image.hpp.

◆ height()

int vl::Image::height ( ) const
inline

◆ imageBuffer() [1/2]

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

The buffer used to store the image pixels.

Definition at line 164 of file Image.hpp.

Referenced by vl::DrawPixels::Pixels::generatePixelBufferObject(), and vl::readPixels().

◆ imageBuffer() [2/2]

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

The buffer used to store the image pixels.

Definition at line 167 of file Image.hpp.

◆ isCompressedFormat()

int Image::isCompressedFormat ( EImageFormat  fmt)

◆ isCubemap()

bool vl::Image::isCubemap ( ) const
inline

◆ isNormalMap()

bool vl::Image::isNormalMap ( ) const
inline

Whether an image represents a normal map.

Definition at line 144 of file Image.hpp.

◆ isValid()

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 135 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::createCubemap(), vl::DrawPixels::render_Implementation(), requiredMemory(), and vl::Texture::Texture().

◆ mipmaps() [1/2]

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

Definition at line 203 of file Image.hpp.

◆ mipmaps() [2/2]

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

Definition at line 205 of file Image.hpp.

◆ operator=()

Image & Image::operator= ( const Image other)

◆ pitch()

int vl::Image::pitch ( ) const
inline

◆ pixels() [1/2]

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

◆ pixels() [2/2]

unsigned char* vl::Image::pixels ( )
inline

Raw pointer to pixels.

Definition at line 173 of file Image.hpp.

References NULL.

◆ pixelsXN() [1/2]

unsigned char * Image::pixelsXN ( )

X-negative cubemap face.

Definition at line 764 of file Image.cpp.

References byteAlignment(), dimension(), format(), height(), NULL, pixels(), requiredMemory2D(), type(), VL_CHECK, and width().

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

◆ pixelsXN() [2/2]

const unsigned char * Image::pixelsXN ( ) const

◆ pixelsXP() [1/2]

unsigned char * Image::pixelsXP ( )

X-positive cubemap face.

Definition at line 746 of file Image.cpp.

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

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

◆ pixelsXP() [2/2]

const unsigned char * Image::pixelsXP ( ) const

Definition at line 737 of file Image.cpp.

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

◆ pixelsYN() [1/2]

unsigned char * Image::pixelsYN ( )

Y-negative cubemap face.

Definition at line 800 of file Image.cpp.

References byteAlignment(), dimension(), format(), height(), NULL, pixels(), requiredMemory2D(), type(), VL_CHECK, and width().

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

◆ pixelsYN() [2/2]

const unsigned char * Image::pixelsYN ( ) const

◆ pixelsYP() [1/2]

unsigned char * Image::pixelsYP ( )

Y-positive cubemap face.

Definition at line 782 of file Image.cpp.

References byteAlignment(), dimension(), format(), height(), NULL, pixels(), requiredMemory2D(), type(), VL_CHECK, and width().

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

◆ pixelsYP() [2/2]

const unsigned char * Image::pixelsYP ( ) const

◆ pixelsZN() [1/2]

unsigned char * Image::pixelsZN ( )

Z-negative cubemap face.

Definition at line 836 of file Image.cpp.

References byteAlignment(), dimension(), format(), height(), NULL, pixels(), requiredMemory2D(), type(), VL_CHECK, and width().

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

◆ pixelsZN() [2/2]

const unsigned char * Image::pixelsZN ( ) const

◆ pixelsZP() [1/2]

unsigned char * Image::pixelsZP ( )

Z-positive cubemap face.

Definition at line 818 of file Image.cpp.

References byteAlignment(), dimension(), format(), height(), NULL, pixels(), requiredMemory2D(), type(), VL_CHECK, and width().

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

◆ pixelsZP() [2/2]

const unsigned char * Image::pixelsZP ( ) const

◆ pixelsZSlice()

unsigned char * Image::pixelsZSlice ( int  zth_slice)

Zth slice of 3D image.

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

Definition at line 846 of file Image.cpp.

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

Referenced by vl::assemble3DImage(), and flipVertically().

◆ print()

String Image::print ( ) const

Definition at line 350 of file Image.cpp.

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

Referenced by isValid().

◆ printFormat()

String Image::printFormat ( ) const

◆ printType()

String Image::printType ( ) const

◆ requiredMemory() [1/2]

int Image::requiredMemory ( ) const

◆ requiredMemory() [2/2]

int Image::requiredMemory ( int  x,
int  y,
int  z,
int  bytealign,
EImageFormat  format,
EImageType  type,
bool  is_cubemap 
)
static

◆ requiredMemory1D()

static int vl::Image::requiredMemory1D ( int  x,
EImageFormat  format,
EImageType  type 
)
inlinestatic

Definition at line 110 of file Image.hpp.

◆ requiredMemory2D()

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

Definition at line 112 of file Image.hpp.

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

◆ requiredMemory3D()

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

Definition at line 114 of file Image.hpp.

◆ requiredMemoryCubemap()

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

Definition at line 116 of file Image.hpp.

◆ reset() [1/2]

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 676 of file Image.cpp.

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

Referenced by vl::readPixels().

◆ reset() [2/2]

void Image::reset ( )

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

Definition at line 689 of file Image.cpp.

References vl::Buffer::AutoAllocatedBuffer, 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().

◆ sample()

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 1998 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(), vl::Terrain::init(), and sampleLinear().

◆ sampleLinear() [1/3]

fvec4 Image::sampleLinear ( double  x) const

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

Definition at line 1905 of file Image.cpp.

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

◆ sampleLinear() [2/3]

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

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

Definition at line 1926 of file Image.cpp.

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

◆ sampleLinear() [3/3]

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

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

Definition at line 1964 of file Image.cpp.

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

◆ setByteAlignment()

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 550 of file Image.cpp.

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

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

◆ setDepth()

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

◆ setFilePath()

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

The file from which the image was loaded.

Definition at line 374 of file Image.hpp.

Referenced by vl::loadImage().

◆ setFormat()

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

◆ setHasAlpha()

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

Whether an image contains relevant alpha information.

Definition at line 138 of file Image.hpp.

◆ setHeight()

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

◆ setImageBuffer()

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

The buffer used to store the image pixels.

Definition at line 161 of file Image.hpp.

◆ setIsNormalMap()

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

Whether an image represents a normal map.

Definition at line 147 of file Image.hpp.

◆ setMipmaps()

void vl::Image::setMipmaps ( const std::vector< ref< Image > > &  mipmaps)
inline

Definition at line 201 of file Image.hpp.

◆ setTags()

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 158 of file Image.hpp.

Referenced by vl::loadMHD().

◆ setType()

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

◆ setWidth()

void vl::Image::setWidth ( int  x)
inline

◆ subImage()

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 2086 of file Image.cpp.

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

Referenced by vl::Terrain::init().

◆ substituteColorGreenKey()

void Image::substituteColorGreenKey ( unsigned int  col0,
unsigned int  col1 
)

◆ substituteColorRGB_RGB()

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 2171 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().

◆ substituteColorRGB_RGBA()

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 2129 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().

◆ tags() [1/2]

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 151 of file Image.hpp.

Referenced by contrastHounsfieldAuto().

◆ tags() [2/2]

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 155 of file Image.hpp.

◆ type()

EImageType vl::Image::type ( ) const
inline

◆ updatePitch()

void Image::updatePitch ( )
protected

Definition at line 573 of file Image.cpp.

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

Referenced by setByteAlignment().

◆ width()

int vl::Image::width ( ) const
inline

Member Data Documentation

◆ mByteAlign

int vl::Image::mByteAlign
protected

Definition at line 389 of file Image.hpp.

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

◆ mDepth

int vl::Image::mDepth
protected

Definition at line 387 of file Image.hpp.

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

◆ mFilePath

String vl::Image::mFilePath
protected

Definition at line 383 of file Image.hpp.

Referenced by Image().

◆ mFormat

EImageFormat vl::Image::mFormat
protected

Definition at line 390 of file Image.hpp.

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

◆ mHasAlpha

bool vl::Image::mHasAlpha
protected

Definition at line 394 of file Image.hpp.

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

◆ mHeight

int vl::Image::mHeight
protected

Definition at line 386 of file Image.hpp.

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

◆ mIsCubemap

bool vl::Image::mIsCubemap
protected

◆ mIsNormalMap

bool vl::Image::mIsNormalMap
protected

Definition at line 393 of file Image.hpp.

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

◆ mMipmaps

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

Definition at line 384 of file Image.hpp.

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

◆ mPitch

int vl::Image::mPitch
protected

Definition at line 388 of file Image.hpp.

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

◆ mPixels

ref<Buffer> vl::Image::mPixels
protected

◆ mTags

ref<KeyValues> vl::Image::mTags
protected

Definition at line 382 of file Image.hpp.

◆ mType

EImageType vl::Image::mType
protected

Definition at line 391 of file Image.hpp.

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

◆ mWidth

int vl::Image::mWidth
protected

Definition at line 385 of file Image.hpp.

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


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