Support Forum       G3D Web Page     
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::Image4 Class Reference


RGBA image with 32-bit floating point storage for each channel. More...

Inherits G3D::Map2D< Color4, Color4 >.

Public Types

typedef Color4 ComputeType
 
typedef shared_ptr< class Image4Ref
 
typedef Color4 StorageType
 
typedef Image4 Type
 

Public Member Functions

Color4 average () const
 Returns the average value of all elements of the map. More...
 
Color4 bicubic (float x, float y, WrapMode wrap) const
 
Uses Catmull-Rom splines to interpolate between grid values. More...
 
Color4 bicubic (float x, float y) const
 
Color4 bicubic (const Vector2 &p, WrapMode wrap) const
 
Color4 bicubic (const Vector2 &p) const
 
Color4 bilinear (float x, float y, WrapMode wrap) const
 
Needs to access elements from (floor(x), floor(y)) to (floor(x) + 1, floor(y) + 1) and will use the wrap mode appropriately (possibly generating out of bounds errors). More...
 
Color4 bilinear (float x, float y) const
 
Color4 bilinear (const Vector2 &p) const
 
Color4 bilinear (const Vector2 &p, WrapMode wrap) const
 
bool changed ()
 
Returns true if this map has been written to since the last call to setChanged(false). More...
 
virtual void crop (int newX, int newY, int newW, int newH)
 
Crops this map so that it only contains pixels between (x, y) and (x + w - 1, y + h - 1) inclusive. More...
 
virtual void crop (const Rect2D &rect)
 iRounds to the nearest x0 and y0. More...
 
const Color4fastGet (int x, int y) const
 Unsafe access to the underlying data structure with no wrapping support; requires that (x, y) is in bounds. More...
 
void fastSet (int x, int y, const Color4 &v)
 Unsafe access to the underlying data structure with no wrapping support; requires that (x, y) is in bounds. More...
 
virtual void flipHorizontal ()
 
virtual void flipVertical ()
 
const class ImageFormatformat () const
 
const Color4get (int x, int y, WrapMode wrap) const
 Get the value at (x, y). More...
 
const Color4get (int x, int y) const
 
const Color4get (const Vector2int16 &p) const
 
const Color4get (const Vector2int16 &p, WrapMode wrap) const
 
Color4get (int x, int y, WrapMode wrap)
 
Color4get (int x, int y)
 
Color4get (const Vector2int16 &p)
 
Array< Color4 > & getArray ()
 Row-major array. More...
 
const Array< Color4 > & getArray () const
 
Color4getCArray ()
 Returns a pointer to the underlying row-major data. More...
 
const Color4getCArray () const
 
int32 height () const
 Pixel height. More...
 
bool inBounds (int x, int y) const
 is (x, y) strictly within the image bounds, or will it trigger some kind of wrap mode More...
 
bool inBounds (const Vector2int16 &v) const
 is (x, y) strictly within the image bounds, or will it trigger some kind of wrap mode More...
 
void load (const String &filename)
 Loads from any of the file formats supported by G3D::GImage. More...
 
void maybeFlipVertical (bool flip)
 flips if flip is true More...
 
Color4 nearest (float x, float y, WrapMode wrap) const
 Returns the nearest neighbor. More...
 
Color4 nearest (float x, float y) const
 
Color4 nearest (const Vector2 &p) const
 
Rect2D rect2DBounds () const
 Rectangle from (0, 0) to (w, h) More...
 
void resize (uint32 newW, uint32 newH, uint32 newD=1)
 Resizes without clearing, leaving garbage. More...
 
void save (const String &filename)
 Saves in any of the formats supported by G3D::GImage. More...
 
void set (const Vector2int16 &p, const Color4 &v)
 Sets the changed flag to true. More...
 
void set (int x, int y, const Color4 &v, WrapMode wrap)
 Sets the changed flag to true. More...
 
void set (int x, int y, const Color4 &v)
 
void set (const shared_ptr< Map2D< Color4, T > > &src)
 Copy values from src, which must have the same size. More...
 
void setAll (const Color4 &v)
 
void setChanged (bool c)
 Set/unset the changed flag. More...
 
void setWrapMode (WrapMode m)
 
Vector2int16 size () const
 Dimensions in pixels. More...
 
size_t sizeInMemory () const
 Number of bytes occupied by the image data and this structure. More...
 
int32 width () const
 Pixel width. More...
 
WrapMode wrapMode () const
 

Static Public Member Functions

static shared_ptr< Map2D< Color4, Color4 > > create (int w=0, int h=0, WrapMode wrap=WrapMode::ERROR, int d=1)
 
static Ref createEmpty (int width, int height, WrapMode wrap=WrapMode::ERROR, int depth=1)
 Creates an all-zero width x height image. More...
 
static Ref createEmpty (WrapMode wrap=WrapMode::ERROR)
 Creates a 0 x 0 image. More...
 
static Ref fromArray (const class Color1unorm8 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR, int d=1)
 
static Ref fromArray (const class Color3unorm8 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR, int d=1)
 
static Ref fromArray (const class Color4unorm8 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR, int d=1)
 
static Ref fromArray (const class Color1 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR, int d=1)
 
static Ref fromArray (const class Color3 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR, int d=1)
 
static Ref fromArray (const class Color4 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR, int d=1)
 
static Ref fromFile (const String &filename, WrapMode wrap=WrapMode::ERROR)
 
static Ref fromImage4unorm8 (const shared_ptr< class Image4unorm8 > &im)
 
static float R (float x)
 

Public Attributes

std::mutex mutex
 
Although Map2D is not threadsafe (except for the setChanged() method), you can use this mutex to create your own threadsafe access to a Map2D. More...
 

Protected Member Functions

 Image4 (int w, int h, WrapMode wrap, int d=1)
 
void copyArray (const Color1 *src, int w, int h, int d=1)
 
void copyArray (const Color3 *src, int w, int h, int d=1)
 
void copyArray (const Color4 *src, int w, int h, int d=1)
 
void copyArray (const Color1unorm8 *src, int w, int h, int d=1)
 
void copyArray (const Color3unorm8 *src, int w, int h, int d=1)
 
void copyArray (const Color4unorm8 *src, int w, int h, int d=1)
 
const Color4slowGet (int x, int y, WrapMode wrap)
 Handles the exceptional cases from get. More...
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

uint32 d
 Depth, in pixels, defaults to 1. More...
 
Array< Color4data
 
uint32 h
 Height, in pixels. More...
 
std::atomic_bool m_changed
 false if no mutating method has been invoked since the last call to setChanged(); More...
 
WrapMode m_wrapMode
 
uint32 w
 Width, in pixels. More...
 
Color4 ZERO
 

Detailed Description


RGBA image with 32-bit floating point storage for each channel.

Whenever a method needs to convert from RGB to RGBA, A=1 is assumed.

Bilinear interpolation on Image4 is about 8x faster than on Image4unorm8 due to the large cost of converting int->float on modern machines.

See also
G3D::Image4unorm8, G3D::Image.

Member Typedef Documentation

◆ ComputeType

typedef Color4 G3D::Map2D< Color4 , Color4 >::ComputeType
inherited

◆ Ref

typedef shared_ptr<class Image4> G3D::Image4::Ref

◆ StorageType

typedef Color4 G3D::Map2D< Color4 , Color4 >::StorageType
inherited

◆ Type

Constructor & Destructor Documentation

◆ Image4()

G3D::Image4::Image4 ( int  w,
int  h,
WrapMode  wrap,
int  d = 1 
)
protected

Member Function Documentation

◆ average()

Color4 G3D::Map2D< Color4 , Color4 >::average ( ) const
inlineinherited

Returns the average value of all elements of the map.

◆ bicubic() [1/4]

Color4 G3D::Map2D< Color4 , Color4 >::bicubic ( float  x,
float  y,
WrapMode  wrap 
) const
inlineinherited


Uses Catmull-Rom splines to interpolate between grid values.

◆ bicubic() [2/4]

Color4 G3D::Map2D< Color4 , Color4 >::bicubic ( float  x,
float  y 
) const
inlineinherited

◆ bicubic() [3/4]

Color4 G3D::Map2D< Color4 , Color4 >::bicubic ( const Vector2 p,
WrapMode  wrap 
) const
inlineinherited

◆ bicubic() [4/4]

Color4 G3D::Map2D< Color4 , Color4 >::bicubic ( const Vector2 p) const
inlineinherited

◆ bilinear() [1/4]

Color4 G3D::Map2D< Color4 , Color4 >::bilinear ( float  x,
float  y,
WrapMode  wrap 
) const
inlineinherited


Needs to access elements from (floor(x), floor(y)) to (floor(x) + 1, floor(y) + 1) and will use the wrap mode appropriately (possibly generating out of bounds errors).

Guaranteed to match nearest(x, y) at integers.

◆ bilinear() [2/4]

Color4 G3D::Map2D< Color4 , Color4 >::bilinear ( float  x,
float  y 
) const
inlineinherited

◆ bilinear() [3/4]

Color4 G3D::Map2D< Color4 , Color4 >::bilinear ( const Vector2 p) const
inlineinherited

◆ bilinear() [4/4]

Color4 G3D::Map2D< Color4 , Color4 >::bilinear ( const Vector2 p,
WrapMode  wrap 
) const
inlineinherited

◆ changed()

bool G3D::Map2D< Color4 , Color4 >::changed ( )
inlineinherited


Returns true if this map has been written to since the last call to setChanged(false).

This is useful if you are caching a texture map other value that must be recomputed whenever this changes.

◆ copyArray() [1/6]

void G3D::Image4::copyArray ( const Color1 src,
int  w,
int  h,
int  d = 1 
)
protected

◆ copyArray() [2/6]

void G3D::Image4::copyArray ( const Color3 src,
int  w,
int  h,
int  d = 1 
)
protected

◆ copyArray() [3/6]

void G3D::Image4::copyArray ( const Color4 src,
int  w,
int  h,
int  d = 1 
)
protected

◆ copyArray() [4/6]

void G3D::Image4::copyArray ( const Color1unorm8 src,
int  w,
int  h,
int  d = 1 
)
protected

◆ copyArray() [5/6]

void G3D::Image4::copyArray ( const Color3unorm8 src,
int  w,
int  h,
int  d = 1 
)
protected

◆ copyArray() [6/6]

void G3D::Image4::copyArray ( const Color4unorm8 src,
int  w,
int  h,
int  d = 1 
)
protected

◆ create()

static shared_ptr< Map2D<Color4 , Color4 > > G3D::Map2D< Color4 , Color4 >::create ( int  w = 0,
int  h = 0,
WrapMode  wrap = WrapMode::ERROR,
int  d = 1 
)
inlinestaticinherited

◆ createEmpty() [1/2]

static Ref G3D::Image4::createEmpty ( int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR,
int  depth = 1 
)
static

Creates an all-zero width x height image.

◆ createEmpty() [2/2]

static Ref G3D::Image4::createEmpty ( WrapMode  wrap = WrapMode::ERROR)
static

Creates a 0 x 0 image.

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ crop() [1/2]

virtual void G3D::Map2D< Color4 , Color4 >::crop ( int  newX,
int  newY,
int  newW,
int  newH 
)
inlinevirtualinherited


Crops this map so that it only contains pixels between (x, y) and (x + w - 1, y + h - 1) inclusive.

◆ crop() [2/2]

virtual void G3D::Map2D< Color4 , Color4 >::crop ( const Rect2D rect)
inlinevirtualinherited

iRounds to the nearest x0 and y0.

◆ fastGet()

const Color4 & G3D::Map2D< Color4 , Color4 >::fastGet ( int  x,
int  y 
) const
inlineinherited

Unsafe access to the underlying data structure with no wrapping support; requires that (x, y) is in bounds.

◆ fastSet()

void G3D::Map2D< Color4 , Color4 >::fastSet ( int  x,
int  y,
const Color4 v 
)
inlineinherited

Unsafe access to the underlying data structure with no wrapping support; requires that (x, y) is in bounds.

◆ flipHorizontal()

virtual void G3D::Map2D< Color4 , Color4 >::flipHorizontal ( )
inlinevirtualinherited

◆ flipVertical()

virtual void G3D::Map2D< Color4 , Color4 >::flipVertical ( )
inlinevirtualinherited

◆ format()

const class ImageFormat* G3D::Image4::format ( ) const

◆ fromArray() [1/6]

static Ref G3D::Image4::fromArray ( const class Color1unorm8 ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR,
int  d = 1 
)
static

◆ fromArray() [2/6]

static Ref G3D::Image4::fromArray ( const class Color3unorm8 ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR,
int  d = 1 
)
static

◆ fromArray() [3/6]

static Ref G3D::Image4::fromArray ( const class Color4unorm8 ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR,
int  d = 1 
)
static

◆ fromArray() [4/6]

static Ref G3D::Image4::fromArray ( const class Color1 ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR,
int  d = 1 
)
static

◆ fromArray() [5/6]

static Ref G3D::Image4::fromArray ( const class Color3 ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR,
int  d = 1 
)
static

◆ fromArray() [6/6]

static Ref G3D::Image4::fromArray ( const class Color4 ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR,
int  d = 1 
)
static

◆ fromFile()

static Ref G3D::Image4::fromFile ( const String filename,
WrapMode  wrap = WrapMode::ERROR 
)
static

◆ fromImage4unorm8()

static Ref G3D::Image4::fromImage4unorm8 ( const shared_ptr< class Image4unorm8 > &  im)
static

◆ get() [1/7]

const Color4 & G3D::Map2D< Color4 , Color4 >::get ( int  x,
int  y,
WrapMode  wrap 
) const
inlineinherited

Get the value at (x, y).

Note that the type of image->get(x, y) is the storage type, not the computation type. If the constructor promoting Storage to Compute rescales values (as, for example Color3(Color3uint8&) does), this will not match the value returned by Map2D::nearest.

◆ get() [2/7]

const Color4 & G3D::Map2D< Color4 , Color4 >::get ( int  x,
int  y 
) const
inlineinherited

◆ get() [3/7]

const Color4 & G3D::Map2D< Color4 , Color4 >::get ( const Vector2int16 p) const
inlineinherited

◆ get() [4/7]

const Color4 & G3D::Map2D< Color4 , Color4 >::get ( const Vector2int16 p,
WrapMode  wrap 
) const
inlineinherited

◆ get() [5/7]

Color4 & G3D::Map2D< Color4 , Color4 >::get ( int  x,
int  y,
WrapMode  wrap 
)
inlineinherited

◆ get() [6/7]

Color4 & G3D::Map2D< Color4 , Color4 >::get ( int  x,
int  y 
)
inlineinherited

◆ get() [7/7]

Color4 & G3D::Map2D< Color4 , Color4 >::get ( const Vector2int16 p)
inlineinherited

◆ getArray() [1/2]

Array<Color4 >& G3D::Map2D< Color4 , Color4 >::getArray ( )
inlineinherited

Row-major array.

You should call setChanged(true) if you mutate the array.

◆ getArray() [2/2]

const Array<Color4 >& G3D::Map2D< Color4 , Color4 >::getArray ( ) const
inlineinherited

◆ getCArray() [1/2]

Color4 * G3D::Map2D< Color4 , Color4 >::getCArray ( )
inlineinherited

Returns a pointer to the underlying row-major data.

There is no padding at the end of the row. Be careful–this will be reallocated during a resize. You should call setChanged(true) if you mutate the array.

◆ getCArray() [2/2]

const Color4 * G3D::Map2D< Color4 , Color4 >::getCArray ( ) const
inlineinherited

◆ height()

int32 G3D::Map2D< Color4 , Color4 >::height ( ) const
inlineinherited

Pixel height.

◆ inBounds() [1/2]

bool G3D::Map2D< Color4 , Color4 >::inBounds ( int  x,
int  y 
) const
inlineinherited

is (x, y) strictly within the image bounds, or will it trigger some kind of wrap mode

◆ inBounds() [2/2]

bool G3D::Map2D< Color4 , Color4 >::inBounds ( const Vector2int16 v) const
inlineinherited

is (x, y) strictly within the image bounds, or will it trigger some kind of wrap mode

◆ load()

void G3D::Image4::load ( const String filename)

Loads from any of the file formats supported by G3D::GImage.

◆ maybeFlipVertical()

void G3D::Map2D< Color4 , Color4 >::maybeFlipVertical ( bool  flip)
inlineinherited

flips if flip is true

◆ nearest() [1/3]

Color4 G3D::Map2D< Color4 , Color4 >::nearest ( float  x,
float  y,
WrapMode  wrap 
) const
inlineinherited

Returns the nearest neighbor.

Pixel values are considered to be at the upper left corner, so image->nearest(x, y) == image(x, y)

◆ nearest() [2/3]

Color4 G3D::Map2D< Color4 , Color4 >::nearest ( float  x,
float  y 
) const
inlineinherited

◆ nearest() [3/3]

Color4 G3D::Map2D< Color4 , Color4 >::nearest ( const Vector2 p) const
inlineinherited

◆ R()

static float G3D::Map2D< Color4 , Color4 >::R ( float  x)
inlinestaticinherited

◆ rect2DBounds()

Rect2D G3D::Map2D< Color4 , Color4 >::rect2DBounds ( ) const
inlineinherited

Rectangle from (0, 0) to (w, h)

◆ resize()

void G3D::Map2D< Color4 , Color4 >::resize ( uint32  newW,
uint32  newH,
uint32  newD = 1 
)
inlineinherited

Resizes without clearing, leaving garbage.

◆ save()

void G3D::Image4::save ( const String filename)

Saves in any of the formats supported by G3D::GImage.

◆ set() [1/4]

void G3D::Map2D< Color4 , Color4 >::set ( const Vector2int16 p,
const Color4 v 
)
inlineinherited

Sets the changed flag to true.

◆ set() [2/4]

void G3D::Map2D< Color4 , Color4 >::set ( int  x,
int  y,
const Color4 v,
WrapMode  wrap 
)
inlineinherited

Sets the changed flag to true.

◆ set() [3/4]

void G3D::Map2D< Color4 , Color4 >::set ( int  x,
int  y,
const Color4 v 
)
inlineinherited

◆ set() [4/4]

void G3D::Map2D< Color4 , Color4 >::set ( const shared_ptr< Map2D< Color4 , T > > &  src)
inlineinherited

Copy values from src, which must have the same size.

◆ setAll()

void G3D::Map2D< Color4 , Color4 >::setAll ( const Color4 v)
inlineinherited

◆ setChanged()

void G3D::Map2D< Color4 , Color4 >::setChanged ( bool  c)
inlineinherited

Set/unset the changed flag.

◆ setWrapMode()

void G3D::Map2D< Color4 , Color4 >::setWrapMode ( WrapMode  m)
inlineinherited

◆ size()

Vector2int16 G3D::Map2D< Color4 , Color4 >::size ( ) const
inlineinherited

Dimensions in pixels.

◆ sizeInMemory()

size_t G3D::Map2D< Color4 , Color4 >::sizeInMemory ( ) const
inlineinherited

Number of bytes occupied by the image data and this structure.

◆ slowGet()

const Color4 & G3D::Map2D< Color4 , Color4 >::slowGet ( int  x,
int  y,
WrapMode  wrap 
)
inlineprotectedinherited

Handles the exceptional cases from get.

◆ width()

int32 G3D::Map2D< Color4 , Color4 >::width ( ) const
inlineinherited

Pixel width.

◆ wrapMode()

WrapMode G3D::Map2D< Color4 , Color4 >::wrapMode ( ) const
inlineinherited

Member Data Documentation

◆ d

uint32 G3D::Map2D< Color4 , Color4 >::d
protectedinherited

Depth, in pixels, defaults to 1.

◆ data

Array<Color4 > G3D::Map2D< Color4 , Color4 >::data
protectedinherited

◆ h

uint32 G3D::Map2D< Color4 , Color4 >::h
protectedinherited

Height, in pixels.

◆ m_changed

std::atomic_bool G3D::Map2D< Color4 , Color4 >::m_changed
protectedinherited

false if no mutating method has been invoked since the last call to setChanged();

◆ m_wrapMode

WrapMode G3D::Map2D< Color4 , Color4 >::m_wrapMode
protectedinherited

◆ mutex

std::mutex G3D::Map2D< Color4 , Color4 >::mutex
inherited


Although Map2D is not threadsafe (except for the setChanged() method), you can use this mutex to create your own threadsafe access to a Map2D.

Not used by the default implementation.

◆ w

uint32 G3D::Map2D< Color4 , Color4 >::w
protectedinherited

Width, in pixels.

◆ ZERO

Color4 G3D::Map2D< Color4 , Color4 >::ZERO
protectedinherited

documentation generated on Wed Nov 24 2021 08:01:57 using doxygen 1.8.15