Graphite  Version 3
An experimental 3D geometry processing program
GEO::Image Class Reference

An image. More...

#include <geogram/image/image.h>

Inheritance diagram for GEO::Image:
GEO::Counted

Public Types

enum  ColorEncoding {
  GRAY , INDEXED , RGB , BGR ,
  RGBA , YUV
}
 Indicates how colors are encoded within the image.
 
enum  ComponentEncoding {
  BYTE , INT16 , INT32 , FLOAT32 ,
  FLOAT64
}
 Indicates the datatype used to encode each component of the colors.
 

Public Member Functions

 Image ()
 Image constructor. More...
 
 Image (ColorEncoding color_rep, ComponentEncoding component_rep, index_t width, index_t height=1, index_t depth=1)
 Image constructor. More...
 
 ~Image () override
 Image destructor.
 
virtual void acquire ()
 Some implementations get the image from some sources. Default implementation does nothing. More...
 
index_t dimension () const
 Gets the dimension of the image. More...
 
index_t size (index_t axis) const
 Gets the size of the image along one of the axes. More...
 
index_t width () const
 Gets the width of the image. More...
 
index_t height () const
 Gets the height of the image. More...
 
index_t depth () const
 Gets the depth of the image. More...
 
size_t bytes_per_pixel () const
 Gets the number of bytes per pixel. More...
 
size_t components_per_pixel () const
 Gets the number of components per pixel. More...
 
size_t nb_pixels () const
 Gets the number of pixels. More...
 
size_t bytes () const
 Gets the number of bytes. More...
 
ComponentEncoding component_encoding () const
 Gets the ComponentEncoding. More...
 
ColorEncoding color_encoding () const
 Gets the ColorEncoding. More...
 
const Colormapcolormap () const
 Gets the Colormap. More...
 
Colormapcolormap ()
 Gets the Colormap. More...
 
void set_colormap (Colormap *colormap)
 Sets the Colormap. More...
 
Memory::pointer base_mem () const
 Gets the base memory. More...
 
Memory::bytebase_mem_byte_ptr () const
 Gets the base memory as a byte pointer. More...
 
Numeric::int16base_mem_int16_ptr () const
 Gets the base memory as a 16 bits integer pointer. More...
 
Numeric::int32base_mem_int32_ptr () const
 Gets the base memory as a 32 bits integer pointer. More...
 
Numeric::float32base_mem_float32_ptr () const
 Gets the base memory as a 32 bits floating point pointer. More...
 
Numeric::float64base_mem_float64_ptr () const
 Gets the base memory as a 64 bits floating point pointer. More...
 
Memory::pointer pixel_base (index_t x)
 Gets the address of a pixel in a 1D image. More...
 
Memory::bytepixel_base_byte_ptr (index_t x)
 Gets the address of a pixel in a 1D image as a byte pointer. More...
 
Numeric::int16pixel_base_int16_ptr (index_t x)
 Gets the address of a pixel in a 1D image as a int16 pointer. More...
 
Numeric::int32pixel_base_int32_ptr (index_t x)
 Gets the address of a pixel in a 1D image as a int32 pointer. More...
 
Numeric::float32pixel_base_float32_ptr (index_t x)
 Gets the address of a pixel in a 1D image as a float32 pointer. More...
 
Numeric::float64pixel_base_float64_ptr (index_t x)
 Gets the address of a pixel in a 1D image as a float64 pointer. More...
 
Memory::pointer pixel_base (index_t x, index_t y)
 Gets the address of a pixel in a 2D image. More...
 
Memory::bytepixel_base_byte_ptr (index_t x, index_t y)
 Gets the address of a pixel in a 2D image as a byte pointer. More...
 
Numeric::int16pixel_base_int16_ptr (index_t x, index_t y)
 Gets the address of a pixel in a 2D image as an int16 pointer. More...
 
Numeric::int32pixel_base_int32_ptr (index_t x, index_t y)
 Gets the address of a pixel in a 2D image as an int32 pointer. More...
 
Numeric::float32pixel_base_float32_ptr (index_t x, index_t y)
 Gets the address of a pixel in a 2D image as a float32 pointer. More...
 
Numeric::float64pixel_base_float64_ptr (index_t x, index_t y)
 Gets the address of a pixel in a 2D image as a float64 pointer. More...
 
Memory::pointer pixel_base (index_t x, index_t y, index_t z)
 Gets the address of a pixel in a 3D image. More...
 
Memory::bytepixel_base_byte_ptr (index_t x, index_t y, index_t z)
 Gets the address of a pixel in a 3D image as a byte pointer. More...
 
Numeric::int16pixel_base_int16_ptr (index_t x, index_t y, index_t z)
 Gets the address of a pixel in a 3D image as an int16 pointer. More...
 
Numeric::int32pixel_base_int32_ptr (index_t x, index_t y, index_t z)
 Gets the address of a pixel in a 3D image as an int32 pointer. More...
 
Numeric::float32pixel_base_float32_ptr (index_t x, index_t y, index_t z)
 Gets the address of a pixel in a 3D image as a float32 pointer. More...
 
Numeric::float64pixel_base_float64_ptr (index_t x, index_t y, index_t z)
 Gets the address of a pixel in a 3D image as a float64 pointer. More...
 
Memory::bytebyte_ptr (Memory::pointer ptr) const
 Converts an untyped pointer into a byte pointer. More...
 
Numeric::int16int16_ptr (Memory::pointer ptr) const
 Converts an untyped pointer into a 16 bits integer pointer. More...
 
Numeric::int32int32_ptr (Memory::pointer ptr) const
 Converts an untyped pointer into a 32 bits integer pointer. More...
 
Numeric::float32float32_ptr (Memory::pointer ptr) const
 Converts an untyped pointer into a 32 bits floating point pointer. More...
 
Numeric::float64float64_ptr (Memory::pointer ptr) const
 Converts an untyped pointer into a 64 bits floating point pointer. More...
 
void flip_vertically ()
 Flips this image along the y axis.
 
void swap_components (index_t channel1, index_t channel2)
 Swaps two color components of this image. More...
 
void initialize (ColorEncoding color_rep, ComponentEncoding component_rep, index_t size_x, index_t size_y=1, index_t size_z=1)
 Creates storage for the specified encoding and image dimensions. More...
 
- Public Member Functions inherited from GEO::Counted
void ref () const
 Increments the reference count. More...
 
void unref () const
 Decrements the reference count. More...
 
bool is_shared () const
 Check if the object is shared. More...
 
int nb_refs () const
 Gets the number of references that point to this object. More...
 

Static Public Member Functions

static size_t nb_components (ColorEncoding color_rep)
 Gets the number of components associated with a ColorEncoding. More...
 
static size_t bytes_per_component (ComponentEncoding component_rep)
 Gets the number of bytes used by a ComponentEncoding. More...
 
- Static Public Member Functions inherited from GEO::Counted
static void ref (const Counted *counted)
 Increments the reference count. More...
 
static void unref (const Counted *counted)
 Decrements the reference count. More...
 

Protected Attributes

ColorEncoding color_encoding_
 
ComponentEncoding component_encoding_
 
Colormap_var colormap_
 
size_t factor_ [3]
 
Memory::pointer base_mem_
 
index_t dimension_
 
index_t size_ [3]
 
size_t bytes_per_pixel_
 

Additional Inherited Members

- Protected Member Functions inherited from GEO::Counted
 Counted ()
 Creates a reference counted object. More...
 
virtual ~Counted ()
 Destroys a reference counted object. More...
 

Detailed Description

An image.

Definition at line 59 of file image.h.

Constructor & Destructor Documentation

◆ Image() [1/2]

GEO::Image::Image ( )

Image constructor.

Constructs an uninitialized Image.

◆ Image() [2/2]

GEO::Image::Image ( ColorEncoding  color_rep,
ComponentEncoding  component_rep,
index_t  width,
index_t  height = 1,
index_t  depth = 1 
)
inline

Image constructor.

Parameters
[in]color_repthe ColorEncoding
[in]component_repthe ComponentEncoding
[in]widththe width of the image
[in]heightthe height of the image, or 1 for 1D images
[in]depththe depth of the image for 3D images, or 1 for 1D and 2D images

Definition at line 94 of file image.h.

Member Function Documentation

◆ acquire()

virtual void GEO::Image::acquire ( )
virtual

Some implementations get the image from some sources. Default implementation does nothing.

There is a derived class to access the webcam for instance.

◆ base_mem()

Memory::pointer GEO::Image::base_mem ( ) const
inline

Gets the base memory.

Returns
a pointer to the color data associated with this image.

Definition at line 240 of file image.h.

◆ base_mem_byte_ptr()

Memory::byte* GEO::Image::base_mem_byte_ptr ( ) const
inline

Gets the base memory as a byte pointer.

Returns
a byte pointer to the color data associated with this image.
Precondition
ComponentEncoding == BYTE

Definition at line 250 of file image.h.

◆ base_mem_float32_ptr()

Numeric::float32* GEO::Image::base_mem_float32_ptr ( ) const
inline

Gets the base memory as a 32 bits floating point pointer.

Returns
a 32 bits floating point pointer to the color data associated with this image.
Precondition
ComponentEncoding == FLOAT32

Definition at line 280 of file image.h.

◆ base_mem_float64_ptr()

Numeric::float64* GEO::Image::base_mem_float64_ptr ( ) const
inline

Gets the base memory as a 64 bits floating point pointer.

Returns
a 64 bits floating point pointer to the color data associated with this image.
Precondition
ComponentEncoding == FLOAT64

Definition at line 290 of file image.h.

◆ base_mem_int16_ptr()

Numeric::int16* GEO::Image::base_mem_int16_ptr ( ) const
inline

Gets the base memory as a 16 bits integer pointer.

Returns
a 16 bits integer pointer to the color data associated with this image.
Precondition
ComponentEncoding == INT16

Definition at line 260 of file image.h.

◆ base_mem_int32_ptr()

Numeric::int32* GEO::Image::base_mem_int32_ptr ( ) const
inline

Gets the base memory as a 32 bits integer pointer.

Returns
a 32 bits integer pointer to the color data associated with this image.
Precondition
ComponentEncoding == FLOAT32

Definition at line 270 of file image.h.

◆ byte_ptr()

Memory::byte* GEO::Image::byte_ptr ( Memory::pointer  ptr) const
inline

Converts an untyped pointer into a byte pointer.

Parameters
[in]ptrthe pointer to be converted
Returns
pointer ptr converted to a byte pointer
Precondition
component_encoding_ == BYTE
Note
This function does nothing else than casting the pointer. In addition, in debug mode, it tests that the color encoding is the right one (and throws an assertion failure if it is not the case).

Definition at line 523 of file image.h.

◆ bytes()

size_t GEO::Image::bytes ( ) const
inline

Gets the number of bytes.

Returns
the total number of bytes used to store the color data of this image

Definition at line 190 of file image.h.

◆ bytes_per_component()

static size_t GEO::Image::bytes_per_component ( ComponentEncoding  component_rep)
static

Gets the number of bytes used by a ComponentEncoding.

Parameters
[in]component_repthe ComponentEncoding
Returns
the number of bytes used to represent a color component encoded with component_rep

◆ bytes_per_pixel()

size_t GEO::Image::bytes_per_pixel ( ) const
inline

Gets the number of bytes per pixel.

Returns
the number of bytes used to store the color of one pixel.

Definition at line 165 of file image.h.

◆ color_encoding()

ColorEncoding GEO::Image::color_encoding ( ) const
inline

Gets the ColorEncoding.

Returns
the ColorEncoding

Definition at line 206 of file image.h.

◆ colormap() [1/2]

Colormap* GEO::Image::colormap ( )
inline

Gets the Colormap.

Returns
a pointer to the Colormap.

Definition at line 222 of file image.h.

◆ colormap() [2/2]

const Colormap* GEO::Image::colormap ( ) const
inline

Gets the Colormap.

Returns
a const pointer to the Colormap.

Definition at line 214 of file image.h.

◆ component_encoding()

ComponentEncoding GEO::Image::component_encoding ( ) const
inline

Gets the ComponentEncoding.

Returns
the ComponentEncoding

Definition at line 198 of file image.h.

◆ components_per_pixel()

size_t GEO::Image::components_per_pixel ( ) const
inline

Gets the number of components per pixel.

Returns
the number of color components in each pixel.

Definition at line 173 of file image.h.

◆ depth()

index_t GEO::Image::depth ( ) const
inline

Gets the depth of the image.

Returns
for 3D images, the depth of the image in pixels, or 1 for 1D and 2D images.

Definition at line 157 of file image.h.

◆ dimension()

index_t GEO::Image::dimension ( ) const
inline

Gets the dimension of the image.

Return values
1for 1D images
2for 2D images
3for 3D images

Definition at line 121 of file image.h.

◆ float32_ptr()

Numeric::float32* GEO::Image::float32_ptr ( Memory::pointer  ptr) const
inline

Converts an untyped pointer into a 32 bits floating point pointer.

Parameters
[in]ptrthe pointer to be converted
Returns
pointer ptr converted to a 32 bits floating point pointer
Precondition
component_encoding_ == FLOAT32
Note
This function does nothing else than casting the pointer. In addition, in debug mode, it tests that the color encoding is the right one (and throws an assertion failure if it is not the case).

Definition at line 566 of file image.h.

◆ float64_ptr()

Numeric::float64* GEO::Image::float64_ptr ( Memory::pointer  ptr) const
inline

Converts an untyped pointer into a 64 bits floating point pointer.

Parameters
[in]ptrthe pointer to be converted
Returns
pointer ptr converted to a 64 bits floating point pointer
Precondition
component_encoding_ == FLOAT64
Note
This function does nothing else than casting the pointer. In addition, in debug mode, it tests that the color encoding is the right one (and throws an assertion failure if it is not the case).

Definition at line 581 of file image.h.

◆ height()

index_t GEO::Image::height ( ) const
inline

Gets the height of the image.

Returns
the height of the image, in pixels, or 1 for 1D images

Definition at line 148 of file image.h.

◆ initialize()

void GEO::Image::initialize ( ColorEncoding  color_rep,
ComponentEncoding  component_rep,
index_t  size_x,
index_t  size_y = 1,
index_t  size_z = 1 
)

Creates storage for the specified encoding and image dimensions.

Parameters
[in]color_repthe ColorEncoding
[in]component_repthe ComponentEncoding
[in]size_xthe image width
[in]size_ythe image height, or 1 for 1D images
[in]size_zthe image depth for 3D images, or 1 for 1D and 2D images

◆ int16_ptr()

Numeric::int16* GEO::Image::int16_ptr ( Memory::pointer  ptr) const
inline

Converts an untyped pointer into a 16 bits integer pointer.

Parameters
[in]ptrthe pointer to be converted
Returns
pointer ptr converted to a 16 bits integer pointer
Precondition
component_encoding_ == INT16
Note
This function does nothing else than casting the pointer. In addition, in debug mode, it tests that the color encoding is the right one (and throws an assertion failure if it is not the case).

Definition at line 537 of file image.h.

◆ int32_ptr()

Numeric::int32* GEO::Image::int32_ptr ( Memory::pointer  ptr) const
inline

Converts an untyped pointer into a 32 bits integer pointer.

Parameters
[in]ptrthe pointer to be converted
Returns
pointer ptr converted to a 32 bits integer pointer
Precondition
component_encoding_ == INT32
Note
This function does nothing else than casting the pointer. In addition, in debug mode, it tests that the color encoding is the right one (and throws an assertion failure if it is not the case).

Definition at line 551 of file image.h.

◆ nb_components()

static size_t GEO::Image::nb_components ( ColorEncoding  color_rep)
static

Gets the number of components associated with a ColorEncoding.

Parameters
[in]color_repthe ColorEncoding
Returns
the number of components used by color_rep

◆ nb_pixels()

size_t GEO::Image::nb_pixels ( ) const
inline

Gets the number of pixels.

Returns
the total number of pixels in this image

Definition at line 181 of file image.h.

◆ pixel_base() [1/3]

Memory::pointer GEO::Image::pixel_base ( index_t  x)
inline

Gets the address of a pixel in a 1D image.

Parameters
[in]xthe x coordinate of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width()

Definition at line 300 of file image.h.

◆ pixel_base() [2/3]

Memory::pointer GEO::Image::pixel_base ( index_t  x,
index_t  y 
)
inline

Gets the address of a pixel in a 2D image.

Parameters
[in]x,ythe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height()

Definition at line 362 of file image.h.

◆ pixel_base() [3/3]

Memory::pointer GEO::Image::pixel_base ( index_t  x,
index_t  y,
index_t  z 
)
inline

Gets the address of a pixel in a 3D image.

Parameters
[in]x,y,zthe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && z < depth()

Definition at line 422 of file image.h.

◆ pixel_base_byte_ptr() [1/3]

Memory::byte* GEO::Image::pixel_base_byte_ptr ( index_t  x)
inline

Gets the address of a pixel in a 1D image as a byte pointer.

Parameters
[in]xthe x coordinate of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && COMPONENT_ENCODING == BYTE

Definition at line 311 of file image.h.

◆ pixel_base_byte_ptr() [2/3]

Memory::byte* GEO::Image::pixel_base_byte_ptr ( index_t  x,
index_t  y 
)
inline

Gets the address of a pixel in a 2D image as a byte pointer.

Parameters
[in]x,ythe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && component_encoding() && BYTE

Definition at line 372 of file image.h.

◆ pixel_base_byte_ptr() [3/3]

Memory::byte* GEO::Image::pixel_base_byte_ptr ( index_t  x,
index_t  y,
index_t  z 
)
inline

Gets the address of a pixel in a 3D image as a byte pointer.

Parameters
[in]x,y,zthe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && z < depth() && component_encoding() && BYTE

Definition at line 434 of file image.h.

◆ pixel_base_float32_ptr() [1/3]

Numeric::float32* GEO::Image::pixel_base_float32_ptr ( index_t  x)
inline

Gets the address of a pixel in a 1D image as a float32 pointer.

Parameters
[in]xthe x coordinate of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && COMPONENT_ENCODING == FLOAT32

Definition at line 341 of file image.h.

◆ pixel_base_float32_ptr() [2/3]

Numeric::float32* GEO::Image::pixel_base_float32_ptr ( index_t  x,
index_t  y 
)
inline

Gets the address of a pixel in a 2D image as a float32 pointer.

Parameters
[in]x,ythe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && component_encoding() && FLOAT32

Definition at line 402 of file image.h.

◆ pixel_base_float32_ptr() [3/3]

Numeric::float32* GEO::Image::pixel_base_float32_ptr ( index_t  x,
index_t  y,
index_t  z 
)
inline

Gets the address of a pixel in a 3D image as a float32 pointer.

Parameters
[in]x,y,zthe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && z < depth() && component_encoding() && FLOAT32

Definition at line 474 of file image.h.

◆ pixel_base_float64_ptr() [1/3]

Numeric::float64* GEO::Image::pixel_base_float64_ptr ( index_t  x)
inline

Gets the address of a pixel in a 1D image as a float64 pointer.

Parameters
[in]xthe x coordinate of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && COMPONENT_ENCODING == FLOAT64

Definition at line 351 of file image.h.

◆ pixel_base_float64_ptr() [2/3]

Numeric::float64* GEO::Image::pixel_base_float64_ptr ( index_t  x,
index_t  y 
)
inline

Gets the address of a pixel in a 2D image as a float64 pointer.

Parameters
[in]x,ythe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && component_encoding() && FLOAT64

Definition at line 412 of file image.h.

◆ pixel_base_float64_ptr() [3/3]

Numeric::float64* GEO::Image::pixel_base_float64_ptr ( index_t  x,
index_t  y,
index_t  z 
)
inline

Gets the address of a pixel in a 3D image as a float64 pointer.

Parameters
[in]x,y,zthe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && z < depth() && component_encoding() && FLOAT64

Definition at line 490 of file image.h.

◆ pixel_base_int16_ptr() [1/3]

Numeric::int16* GEO::Image::pixel_base_int16_ptr ( index_t  x)
inline

Gets the address of a pixel in a 1D image as a int16 pointer.

Parameters
[in]xthe x coordinate of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && COMPONENT_ENCODING == INT16

Definition at line 321 of file image.h.

◆ pixel_base_int16_ptr() [2/3]

Numeric::int16* GEO::Image::pixel_base_int16_ptr ( index_t  x,
index_t  y 
)
inline

Gets the address of a pixel in a 2D image as an int16 pointer.

Parameters
[in]x,ythe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && component_encoding() && INT16

Definition at line 382 of file image.h.

◆ pixel_base_int16_ptr() [3/3]

Numeric::int16* GEO::Image::pixel_base_int16_ptr ( index_t  x,
index_t  y,
index_t  z 
)
inline

Gets the address of a pixel in a 3D image as an int16 pointer.

Parameters
[in]x,y,zthe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && z < depth() && component_encoding() && INT16

Definition at line 447 of file image.h.

◆ pixel_base_int32_ptr() [1/3]

Numeric::int32* GEO::Image::pixel_base_int32_ptr ( index_t  x)
inline

Gets the address of a pixel in a 1D image as a int32 pointer.

Parameters
[in]xthe x coordinate of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && COMPONENT_ENCODING == INT32

Definition at line 331 of file image.h.

◆ pixel_base_int32_ptr() [2/3]

Numeric::int32* GEO::Image::pixel_base_int32_ptr ( index_t  x,
index_t  y 
)
inline

Gets the address of a pixel in a 2D image as an int32 pointer.

Parameters
[in]x,ythe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && component_encoding() && INT32

Definition at line 392 of file image.h.

◆ pixel_base_int32_ptr() [3/3]

Numeric::int32* GEO::Image::pixel_base_int32_ptr ( index_t  x,
index_t  y,
index_t  z 
)
inline

Gets the address of a pixel in a 3D image as an int32 pointer.

Parameters
[in]x,y,zthe coordinates of the pixel
Returns
a pointer to the color data associated with the pixel
Precondition
x < width() && y < height() && z < depth() && component_encoding() && INT32

Definition at line 460 of file image.h.

◆ set_colormap()

void GEO::Image::set_colormap ( Colormap colormap)
inline

Sets the Colormap.

Parameters
[in]colormapa pointer to the Colormap, ownership is transfered to this Image

Definition at line 231 of file image.h.

◆ size()

index_t GEO::Image::size ( index_t  axis) const
inline

Gets the size of the image along one of the axes.

Parameters
[in]axisthe axis, one of (0,1,2)
Returns
the number of pixels along axis

Definition at line 130 of file image.h.

◆ swap_components()

void GEO::Image::swap_components ( index_t  channel1,
index_t  channel2 
)

Swaps two color components of this image.

Parameters
[in]channel1,channel2the two channels to be swapped
Precondition
channel1 < nb_components(color_encoding()) && channel2 < nb_components(color_encoding())

◆ width()

index_t GEO::Image::width ( ) const
inline

Gets the width of the image.

Returns
the width of the image, in pixels

Definition at line 139 of file image.h.


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