TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Image4 Class Reference

#include <Image4.h>

Public Types

typedef Image4 Type
 
typedef shared_ptr< class Image4Ref
 
- Public Types inherited from G3D::Map2D< Color4, Color4 >
typedef Color4 StorageType
 
typedef Color4 ComputeType
 
typedef Map2D< Color4, Color4Type
 
typedef shared_ptr< Map2DRef
 

Public Member Functions

const class ImageFormatformat () const
 
void load (const std::string &filename)
 
void save (const std::string &filename)
 
- Public Member Functions inherited from G3D::Map2D< Color4, Color4 >
const Color4fastGet (int x, int y) const
 
void fastSet (int x, int y, const Color4 &v)
 
Color4 bicubic (float x, float y, WrapMode wrap) const
 
Color4 bicubic (float x, float y) const
 
Color4 bicubic (const Vector2 &p, WrapMode wrap) const
 
Color4 bicubic (const Vector2 &p) const
 
void resize (uint32 newW, uint32 newH)
 
bool changed ()
 
void setChanged (bool c)
 
Color4getCArray ()
 
const Color4getCArray () const
 
Array< Color4 > & getArray ()
 
const Array< Color4 > & getArray () const
 
bool inBounds (int x, int y) const
 
bool inBounds (const Vector2int16 &v) const
 
const Color4get (int x, int y, WrapMode wrap) const
 
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)
 
void set (const Vector2int16 &p, const Color4 &v)
 
void set (int x, int y, const Color4 &v, WrapMode wrap)
 
void set (int x, int y, const Color4 &v)
 
void set (const shared_ptr< Map2D< Color4, T > > &src)
 
void setAll (const Color4 &v)
 
void maybeFlipVertical (bool flip)
 
virtual void flipVertical ()
 
virtual void flipHorizontal ()
 
virtual void crop (int newX, int newY, int newW, int newH)
 
virtual void crop (const Rect2D &rect)
 
Color4 nearest (float x, float y, WrapMode wrap) const
 
Color4 nearest (float x, float y) const
 
Color4 nearest (const Vector2 &p) const
 
Color4 average () const
 
Color4 bilinear (float x, float y, WrapMode wrap) const
 
Color4 bilinear (float x, float y) const
 
Color4 bilinear (const Vector2 &p) const
 
Color4 bilinear (const Vector2 &p, WrapMode wrap) const
 
int32 width () const
 
int32 height () const
 
Vector2int16 size () const
 
Rect2D rect2DBounds () const
 
size_t sizeInMemory () const
 
WrapMode wrapMode () const
 
void setWrapMode (WrapMode m)
 
- Public Member Functions inherited from G3D::ReferenceCountedObject
virtual ~ReferenceCountedObject ()
 

Static Public Member Functions

static Ref createEmpty (int width, int height, WrapMode wrap=WrapMode::ERROR)
 
static Ref createEmpty (WrapMode wrap=WrapMode::ERROR)
 
static Ref fromFile (const std::string &filename, WrapMode wrap=WrapMode::ERROR)
 
static Ref fromArray (const class Color1unorm8 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR)
 
static Ref fromArray (const class Color3unorm8 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR)
 
static Ref fromArray (const class Color4unorm8 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR)
 
static Ref fromArray (const class Color1 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR)
 
static Ref fromArray (const class Color3 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR)
 
static Ref fromArray (const class Color4 *ptr, int width, int height, WrapMode wrap=WrapMode::ERROR)
 
static Ref fromImage4unorm8 (const shared_ptr< class Image4unorm8 > &im)
 
- Static Public Member Functions inherited from G3D::Map2D< Color4, Color4 >
static Ref create (int w=0, int h=0, WrapMode wrap=WrapMode::ERROR)
 

Protected Member Functions

 Image4 (int w, int h, WrapMode wrap)
 
void copyArray (const Color1 *src, int w, int h)
 
void copyArray (const Color3 *src, int w, int h)
 
void copyArray (const Color4 *src, int w, int h)
 
void copyArray (const Color1unorm8 *src, int w, int h)
 
void copyArray (const Color3unorm8 *src, int w, int h)
 
void copyArray (const Color4unorm8 *src, int w, int h)
 
- Protected Member Functions inherited from G3D::Map2D< Color4, Color4 >
const Color4slowGet (int x, int y, WrapMode wrap)
 
Color4 bicubic (const Color4 *ctrl, double s) const
 
 Map2D (int w, int h, WrapMode wrap)
 

Additional Inherited Members

- Public Attributes inherited from G3D::Map2D< Color4, Color4 >
GMutex mutex
 
- Protected Attributes inherited from G3D::Map2D< Color4, Color4 >
Color4 ZERO
 
uint32 w
 
uint32 h
 
WrapMode _wrapMode
 
AtomicInt32 m_changed
 
Array< Color4data
 

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::GImage.

Member Typedef Documentation

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

Constructor & Destructor Documentation

G3D::Image4::Image4 ( int  w,
int  h,
WrapMode  wrap 
)
protected
24  : Map2D<Color4, Color4>(w, h, wrap) {
26 }
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
void setAll(const Color4 &v)
Definition: Map2D.h:437
uint32 w
Definition: Map2D.h:191
static const Color4 & zero()
Definition: Color4.cpp:69

+ Here is the call graph for this function:

Member Function Documentation

void G3D::Image4::copyArray ( const Color1 src,
int  w,
int  h 
)
protected
193  {
194  resize(w, h);
195  int N = w * h;
196 
197  Color4* dst = getCArray();
198  for (int i = 0; i < N; ++i) {
199  dst[i].r = dst[i].g = dst[i].b = src[i].value;
200  dst[i].a = 1.0f;
201  }
202 }
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191
Color4 * getCArray()
Definition: Map2D.h:329
void resize(uint32 newW, uint32 newH)
Definition: Map2D.h:304

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::Image4::copyArray ( const Color3 src,
int  w,
int  h 
)
protected
168  {
169  resize(w, h);
170 
171  int N = w * h;
172  Color4* dst = data.getCArray();
173 
174  // Add alpha
175  for (int i = 0; i < N; ++i) {
176  dst[i] = Color4(src[i], 1.0f);
177  }
178 }
Array< Color4 > data
Definition: Map2D.h:202
T * getCArray()
Definition: Array.h:256
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191
void resize(uint32 newW, uint32 newH)
Definition: Map2D.h:304

+ Here is the call graph for this function:

void G3D::Image4::copyArray ( const Color4 src,
int  w,
int  h 
)
protected
162  {
163  resize(w, h);
164  System::memcpy(getCArray(), src, w * h * sizeof(Color4));
165 }
static void memcpy(void *dst, const void *src, size_t numBytes)
Definition: System.cpp:643
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191
Color4 * getCArray()
Definition: Map2D.h:329
void resize(uint32 newW, uint32 newH)
Definition: Map2D.h:304

+ Here is the call graph for this function:

void G3D::Image4::copyArray ( const Color1unorm8 *  src,
int  w,
int  h 
)
protected
181  {
182  resize(w, h);
183  int N = w * h;
184 
185  Color4* dst = getCArray();
186  for (int i = 0; i < N; ++i) {
187  dst[i].r = dst[i].g = dst[i].b = Color1(src[i]).value;
188  dst[i].a = 1.0f;
189  }
190 }
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191
Color4 * getCArray()
Definition: Map2D.h:329
void resize(uint32 newW, uint32 newH)
Definition: Map2D.h:304

+ Here is the call graph for this function:

void G3D::Image4::copyArray ( const Color3unorm8 *  src,
int  w,
int  h 
)
protected
149  {
150  resize(w, h);
151 
152  int N = w * h;
153  Color4* dst = data.getCArray();
154 
155  // Add alpha and convert
156  for (int i = 0; i < N; ++i) {
157  dst[i] = Color4(Color3(src[i]), 1.0f);
158  }
159 }
Array< Color4 > data
Definition: Map2D.h:202
T * getCArray()
Definition: Array.h:256
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191
void resize(uint32 newW, uint32 newH)
Definition: Map2D.h:304

+ Here is the call graph for this function:

void G3D::Image4::copyArray ( const Color4unorm8 *  src,
int  w,
int  h 
)
protected
137  {
138  resize(w, h);
139 
140  int N = w * h;
141  Color4* dst = data.getCArray();
142  // Convert int8 -> float
143  for (int i = 0; i < N; ++i) {
144  dst[i] = Color4(src[i]);
145  }
146 }
Array< Color4 > data
Definition: Map2D.h:202
T * getCArray()
Definition: Array.h:256
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191
void resize(uint32 newW, uint32 newH)
Definition: Map2D.h:304

+ Here is the call graph for this function:

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

Creates an all-zero width x height image.

43  {
44  return shared_ptr<Image4>(new Type(width, height, wrap));
45 }
int32 height() const
Definition: Map2D.h:645
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
int32 width() const
Definition: Map2D.h:639
Image4 Type
Definition: Image4.h:36

+ Here is the caller graph for this function:

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

Creates a 0 x 0 image.

48  {
49  return createEmpty(0, 0, wrap);
50 }
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image4.cpp:43
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495

+ Here is the call graph for this function:

const ImageFormat * G3D::Image4::format ( ) const
212  {
213  return ImageFormat::RGBA32F();
214 }
static const ImageFormat * RGBA32F()

+ Here is the call graph for this function:

Image4::Ref G3D::Image4::fromArray ( const class Color1unorm8 *  ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR 
)
static
109  {
110  Ref out = createEmpty(wrap);
111  out->copyArray(ptr, w, h);
112  return out;
113 }
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image4.cpp:43
shared_ptr< class Image4 > Ref
Definition: Image4.h:37
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191

+ Here is the call graph for this function:

Image4::Ref G3D::Image4::fromArray ( const class Color3unorm8 *  ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR 
)
static
95  {
96  Ref out = createEmpty(wrap);
97  out->copyArray(ptr, w, h);
98  return out;
99 }
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image4.cpp:43
shared_ptr< class Image4 > Ref
Definition: Image4.h:37
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191

+ Here is the call graph for this function:

Image4::Ref G3D::Image4::fromArray ( const class Color4unorm8 *  ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR 
)
static
123  {
124  Ref out = createEmpty(wrap);
125  out->copyArray(ptr, w, h);
126  return out;
127 }
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image4.cpp:43
shared_ptr< class Image4 > Ref
Definition: Image4.h:37
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191

+ Here is the call graph for this function:

Image4::Ref G3D::Image4::fromArray ( const class Color1 ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR 
)
static
102  {
103  Ref out = createEmpty(wrap);
104  out->copyArray(ptr, w, h);
105  return out;
106 }
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image4.cpp:43
shared_ptr< class Image4 > Ref
Definition: Image4.h:37
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191

+ Here is the call graph for this function:

Image4::Ref G3D::Image4::fromArray ( const class Color3 ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR 
)
static
116  {
117  Ref out = createEmpty(wrap);
118  out->copyArray(ptr, w, h);
119  return out;
120 }
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image4.cpp:43
shared_ptr< class Image4 > Ref
Definition: Image4.h:37
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191

+ Here is the call graph for this function:

Image4::Ref G3D::Image4::fromArray ( const class Color4 ptr,
int  width,
int  height,
WrapMode  wrap = WrapMode::ERROR 
)
static
130  {
131  Ref out = createEmpty(wrap);
132  out->copyArray(ptr, w, h);
133  return out;
134 }
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image4.cpp:43
shared_ptr< class Image4 > Ref
Definition: Image4.h:37
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191

+ Here is the call graph for this function:

Image4::Ref G3D::Image4::fromFile ( const std::string &  filename,
WrapMode  wrap = WrapMode::ERROR 
)
static
53  {
54  Ref out = createEmpty(wrap);
55  out->load(filename);
56  return out;
57 }
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image4.cpp:43
shared_ptr< class Image4 > Ref
Definition: Image4.h:37
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495

+ Here is the call graph for this function:

Image4::Ref G3D::Image4::fromImage4unorm8 ( const shared_ptr< class Image4unorm8 > &  im)
static
29  {
30  Ref out = createEmpty(static_cast<WrapMode>(im->wrapMode()));
31  out->resize(im->width(), im->height());
32 
33  int N = im->width() * im->height();
34  const Color4unorm8* src = reinterpret_cast<Color4unorm8*>(im->getCArray());
35  for (int i = 0; i < N; ++i) {
36  out->data[i] = Color4(src[i]);
37  }
38 
39  return out;
40 }
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image4.cpp:43
shared_ptr< class Image4 > Ref
Definition: Image4.h:37

+ Here is the call graph for this function:

void G3D::Image4::load ( const std::string &  filename)

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

60  {
61  shared_ptr<Image> image = Image::fromFile(filename);
62  if (image->format() != ImageFormat::RGBA32F()) {
63  image->convertToRGBA8();
64  }
65 
66  switch (image->format()->code)
67  {
69  copyArray(static_cast<const Color1unorm8*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
70  break;
72  copyArray(static_cast<const Color1*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
73  break;
75  copyArray(static_cast<const Color3unorm8*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
76  break;
78  copyArray(static_cast<const Color3*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
79  break;
81  copyArray(static_cast<const Color4unorm8*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
82  break;
84  copyArray(static_cast<const Color4*>(image->toPixelTransferBuffer()->buffer()), image->width(), image->height());
85  break;
86  default:
87  debugAssertM(false, "Trying to load unsupported image format");
88  break;
89  }
90 
91  setChanged(true);
92 }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
static const ImageFormat * RGBA32F()
Definition: ImageFormat.h:60
Definition: ImageFormat.h:55
Definition: ImageFormat.h:37
Definition: ImageFormat.h:110
void setChanged(bool c)
Definition: Map2D.h:323
Definition: ImageFormat.h:107
Definition: ImageFormat.h:40
void copyArray(const Color1 *src, int w, int h)
Definition: Image4.cpp:193

+ Here is the call graph for this function:

void G3D::Image4::save ( const std::string &  filename)

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

206  {
207  // To avoid saving as floating point image. FreeImage cannot convert floating point to RGBA8.
208  Image4unorm8::Ref unorm8 = Image4unorm8::fromImage4(dynamic_pointer_cast<Image4>(shared_from_this()));
209  unorm8->save(filename);
210 }
unorm8
Definition: unorm8.h:33

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