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

#include <Image3.h>

Public Types

typedef Image3 Type
 
typedef shared_ptr< class Image3Ref
 
- Public Types inherited from G3D::Map2D< Color3, Color3 >
typedef Color3 StorageType
 
typedef Color3 ComputeType
 
typedef Map2D< Color3, Color3Type
 
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< Color3, Color3 >
const Color3fastGet (int x, int y) const
 
void fastSet (int x, int y, const Color3 &v)
 
Color3 bicubic (float x, float y, WrapMode wrap) const
 
Color3 bicubic (float x, float y) const
 
Color3 bicubic (const Vector2 &p, WrapMode wrap) const
 
Color3 bicubic (const Vector2 &p) const
 
void resize (uint32 newW, uint32 newH)
 
bool changed ()
 
void setChanged (bool c)
 
Color3getCArray ()
 
const Color3getCArray () const
 
Array< Color3 > & getArray ()
 
const Array< Color3 > & getArray () const
 
bool inBounds (int x, int y) const
 
bool inBounds (const Vector2int16 &v) const
 
const Color3get (int x, int y, WrapMode wrap) const
 
const Color3get (int x, int y) const
 
const Color3get (const Vector2int16 &p) const
 
const Color3get (const Vector2int16 &p, WrapMode wrap) const
 
Color3get (int x, int y, WrapMode wrap)
 
Color3get (int x, int y)
 
Color3get (const Vector2int16 &p)
 
void set (const Vector2int16 &p, const Color3 &v)
 
void set (int x, int y, const Color3 &v, WrapMode wrap)
 
void set (int x, int y, const Color3 &v)
 
void set (const shared_ptr< Map2D< Color3, T > > &src)
 
void setAll (const Color3 &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)
 
Color3 nearest (float x, float y, WrapMode wrap) const
 
Color3 nearest (float x, float y) const
 
Color3 nearest (const Vector2 &p) const
 
Color3 average () const
 
Color3 bilinear (float x, float y, WrapMode wrap) const
 
Color3 bilinear (float x, float y) const
 
Color3 bilinear (const Vector2 &p) const
 
Color3 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 fromImage3unorm8 (const shared_ptr< class Image3unorm8 > &im)
 
- Static Public Member Functions inherited from G3D::Map2D< Color3, Color3 >
static Ref create (int w=0, int h=0, WrapMode wrap=WrapMode::ERROR)
 

Protected Member Functions

 Image3 (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< Color3, Color3 >
const Color3slowGet (int x, int y, WrapMode wrap)
 
Color3 bicubic (const Color3 *ctrl, double s) const
 
 Map2D (int w, int h, WrapMode wrap)
 

Additional Inherited Members

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

Detailed Description

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

See also G3D::Image3unorm8, G3D::GImage.

Member Typedef Documentation

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

Constructor & Destructor Documentation

G3D::Image3::Image3 ( int  w,
int  h,
WrapMode  wrap 
)
protected
24  : Map2D<Color3, Color3>(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 Color3 &v)
Definition: Map2D.h:437
uint32 w
Definition: Map2D.h:191
static const Color3 & black()
Definition: Color3.cpp:169

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Function Documentation

void G3D::Image3::copyArray ( const Color1 src,
int  w,
int  h 
)
protected
192  {
193  resize(w, h);
194  int N = w * h;
195 
196  Color3* dst = getCArray();
197  for (int i = 0; i < N; ++i) {
198  dst[i].r = dst[i].g = dst[i].b = src[i].value;
199  }
200 }
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191
Color3 * 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::Image3::copyArray ( const Color3 src,
int  w,
int  h 
)
protected
162  {
163  resize(w, h);
164  System::memcpy(getCArray(), src, w * h * sizeof(Color3));
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
Color3 * 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::Image3::copyArray ( const Color4 src,
int  w,
int  h 
)
protected
168  {
169  resize(w, h);
170 
171  int N = w * h;
172  Color3* dst = data.getCArray();
173 
174  // Strip alpha
175  for (int i = 0; i < N; ++i) {
176  dst[i] = src[i].rgb();
177  }
178 }
Array< Color3 > data
Definition: Map2D.h:202
T * getCArray()
Definition: Array.h:256
const Color3 & rgb() const
Definition: Color3.h:84
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::Image3::copyArray ( const Color1unorm8 *  src,
int  w,
int  h 
)
protected
181  {
182  resize(w, h);
183  int N = w * h;
184 
185  Color3* 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  }
189 }
uint32 h
Definition: Map2D.h:194
uint32 w
Definition: Map2D.h:191
Color3 * 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::Image3::copyArray ( const Color3unorm8 *  src,
int  w,
int  h 
)
protected
137  {
138  resize(w, h);
139 
140  int N = w * h;
141  Color3* dst = data.getCArray();
142  // Convert int8 -> float
143  for (int i = 0; i < N; ++i) {
144  dst[i] = Color3(src[i]);
145  }
146 }
Array< Color3 > 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::Image3::copyArray ( const Color4unorm8 *  src,
int  w,
int  h 
)
protected
149  {
150  resize(w, h);
151 
152  int N = w * h;
153  Color3* dst = data.getCArray();
154 
155  // Strip alpha and convert
156  for (int i = 0; i < N; ++i) {
157  dst[i] = Color3(src[i].rgb());
158  }
159 }
Array< Color3 > 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:

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

Creates an all-zero width x height image.

43  {
44  return shared_ptr<Image3>(new Image3(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
Image3(int w, int h, WrapMode wrap)
Definition: Image3.cpp:24

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Creates a 0 x 0 image.

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

+ Here is the call graph for this function:

const ImageFormat * G3D::Image3::format ( ) const
211  {
212  return ImageFormat::RGB32F();
213 }
static const ImageFormat * RGB32F()

+ Here is the call graph for this function:

Image3::Ref G3D::Image3::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 }
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
shared_ptr< class Image3 > Ref
Definition: Image3.h:31
uint32 w
Definition: Map2D.h:191
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image3.cpp:43

+ Here is the call graph for this function:

Image3::Ref G3D::Image3::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 }
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
shared_ptr< class Image3 > Ref
Definition: Image3.h:31
uint32 w
Definition: Map2D.h:191
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image3.cpp:43

+ Here is the call graph for this function:

Image3::Ref G3D::Image3::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 }
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
shared_ptr< class Image3 > Ref
Definition: Image3.h:31
uint32 w
Definition: Map2D.h:191
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image3.cpp:43

+ Here is the call graph for this function:

Image3::Ref G3D::Image3::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 }
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
shared_ptr< class Image3 > Ref
Definition: Image3.h:31
uint32 w
Definition: Map2D.h:191
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image3.cpp:43

+ Here is the call graph for this function:

Image3::Ref G3D::Image3::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 }
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
shared_ptr< class Image3 > Ref
Definition: Image3.h:31
uint32 w
Definition: Map2D.h:191
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image3.cpp:43

+ Here is the call graph for this function:

Image3::Ref G3D::Image3::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 }
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
uint32 h
Definition: Map2D.h:194
shared_ptr< class Image3 > Ref
Definition: Image3.h:31
uint32 w
Definition: Map2D.h:191
static Ref createEmpty(int width, int height, WrapMode wrap=WrapMode::ERROR)
Definition: Image3.cpp:43

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

Loads from any of the file formats supported by G3D::GImage. If there is an alpha channel on the input, it is stripped. Converts 8-bit formats to the range (0, 1)

60  {
61  shared_ptr<Image> image = Image::fromFile(filename);
62  if (image->format() != ImageFormat::RGB32F()) {
63  image->convertToRGB8();
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
Definition: ImageFormat.h:60
Definition: ImageFormat.h:55
Definition: ImageFormat.h:37
Definition: ImageFormat.h:110
void setChanged(bool c)
Definition: Map2D.h:323
static const ImageFormat * RGB32F()
Definition: ImageFormat.h:107
void copyArray(const Color1 *src, int w, int h)
Definition: Image3.cpp:192
Definition: ImageFormat.h:40

+ Here is the call graph for this function:

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

Saves in any of the formats supported by G3D::GImage. Assumes the data is on the range (0, 1) if saving to an 8-bit format.

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

204  {
205  // To avoid saving as floating point image. FreeImage cannot convert floating point to RGB8.
206  Image3unorm8::Ref unorm8 = Image3unorm8::fromImage3(dynamic_pointer_cast<Image3>(shared_from_this()));
207  unorm8->save(filename);
208 }
unorm8
Definition: unorm8.h:33

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