TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ImageFormat.h
Go to the documentation of this file.
1 
10 #ifndef GLG3D_ImageFormat_h
11 #define GLG3D_ImageFormat_h
12 
13 #include "G3D/platform.h"
14 #include "G3D/Table.h"
15 #include "G3D/enumclass.h"
16 #include "G3D/Any.h"
17 
18 namespace G3D {
19 
30 class ImageFormat {
31 public:
32 
33  // Must update ImageFormat::name() when this enum changes.
34  enum Code {
35  CODE_AUTO = -2,
36  CODE_NONE = -1,
41 
46 
52 
63 
66 
69 
74 
78 
82 
86 
89 
93 
97 
100 
103 
106 
111 
114 
119 
128 
131 
135 
140 
143 
146 
151 
156 
161 
163 
165  };
166 
167  enum ColorSpace {
173  };
174 
181  };
182 
183 
184  enum NumberFormat {
188  OTHER // e.g. DXT
189  };
190 
194 
197 
199 
202 
205 
208 
210 
213 
215  int redBits;
216 
219 
221  int blueBits;
222 
225 
228 
231 
241 
244 
246  bool opaque;
247 
248 
251 
254 
256  const std::string& name() const;
257 
259  bool canInterpretAs(const ImageFormat* otherFormat) const;
260 
266  static const ImageFormat* getFormatWithAlpha(const ImageFormat* otherFormat);
267 
268  static const ImageFormat* getSRGBFormat(const ImageFormat* otherFormat);
269 
271  static const ImageFormat* fromString(const std::string& s);
272 
273 
274 private:
275 
277  (int numComponents,
278  bool compressed,
279  int glFormat,
280  int glBaseFormat,
281  int luminanceBits,
282  int alphaBits,
283  int redBits,
284  int greenBits,
285  int blueBits,
286  int depthBits,
287  int stencilBits,
288  int openGLBitsPerPixel,
289  int cpuBitsPerPixel,
290  int glDataFormat,
291  bool opaque,
292  NumberFormat numberFormat,
293  Code code,
294  ColorSpace colorSpace,
295  BayerPattern bayerPattern = BAYER_PATTERN_NONE);
296 
297 public:
298 
299  static const ImageFormat* L8();
300 
301  static const ImageFormat* L16();
302 
303  static const ImageFormat* L16F();
304 
305  static const ImageFormat* L32F();
306 
307  static const ImageFormat* A8();
308 
309  static const ImageFormat* A16();
310 
311  static const ImageFormat* A16F();
312 
313  static const ImageFormat* A32F();
314 
315  static const ImageFormat* LA4();
316 
317  static const ImageFormat* LA8();
318 
319  static const ImageFormat* LA16();
320 
321  static const ImageFormat* LA16F();
322 
323  static const ImageFormat* LA32F();
324 
325  static const ImageFormat* BGR8();
326 
327  static const ImageFormat* BGRA8();
328 
329  static const ImageFormat* R8();
330  static const ImageFormat* R8I();
331  static const ImageFormat* R8UI();
332 
333  static const ImageFormat* R16();
334  static const ImageFormat* R16I();
335  static const ImageFormat* R16UI();
336 
337  static const ImageFormat* R32I();
338  static const ImageFormat* R32UI();
339 
340  static const ImageFormat* RG8();
341  static const ImageFormat* RG8I();
342  static const ImageFormat* RG8UI();
343 
344  static const ImageFormat* RG16();
345  static const ImageFormat* RG16I();
346  static const ImageFormat* RG16UI();
347 
348  static const ImageFormat* R16F();
349  static const ImageFormat* RG16F();
350 
351  static const ImageFormat* RG32I();
352  static const ImageFormat* RG32UI();
353 
354  static const ImageFormat* R32F();
355  static const ImageFormat* RG32F();
356 
357  static const ImageFormat* RGB5();
358 
359  static const ImageFormat* RGB5A1();
360 
361  static const ImageFormat* RGB8();
362 
363  static const ImageFormat* RGB10();
364 
365  static const ImageFormat* RGB10A2();
366 
367  static const ImageFormat* RGB16();
368 
369  static const ImageFormat* RGB16F();
370 
371  static const ImageFormat* RGB32F();
372 
373  static const ImageFormat* RGBA8();
374 
375  static const ImageFormat* RGBA16();
376 
377  static const ImageFormat* RGBA16F();
378 
379  static const ImageFormat* RGBA32F();
380 
381  static const ImageFormat* RGBA16I();
382  static const ImageFormat* RGBA16UI();
383 
384  static const ImageFormat* RGB32UI();
385  static const ImageFormat* RGB32I();
386  static const ImageFormat* RGBA32I();
387  static const ImageFormat* RGBA32UI();
388 
389  static const ImageFormat* R11G11B10F();
390 
391  static const ImageFormat* RGB9E5F();
392 
393  static const ImageFormat* RGB8I();
394 
395  static const ImageFormat* RGB8UI();
396 
397  static const ImageFormat* RGBA8I();
398 
399  static const ImageFormat* RGBA8UI();
400 
401  static const ImageFormat* RGB8_SNORM();
402  static const ImageFormat* RGBA8_SNORM();
403  static const ImageFormat* RGB16_SNORM();
404  static const ImageFormat* RGBA16_SNORM();
405 
406  static const ImageFormat* RGB_DXT1();
407 
408  static const ImageFormat* RGBA_DXT1();
409 
410  static const ImageFormat* RGBA_DXT3();
411 
412  static const ImageFormat* RGBA_DXT5();
413 
414  static const ImageFormat* SRGB8();
415 
416  static const ImageFormat* SRGBA8();
417 
418  static const ImageFormat* SL8();
419 
420  static const ImageFormat* SLA8();
421 
422  static const ImageFormat* SRGB_DXT1();
423 
424  static const ImageFormat* SRGBA_DXT1();
425 
426  static const ImageFormat* SRGBA_DXT3();
427 
428  static const ImageFormat* SRGBA_DXT5();
429 
430  static const ImageFormat* DEPTH16();
431 
432  static const ImageFormat* DEPTH24();
433 
434  static const ImageFormat* DEPTH32();
435 
436  static const ImageFormat* DEPTH32F();
437 
438  static const ImageFormat* STENCIL1();
439 
440  static const ImageFormat* STENCIL4();
441 
442  static const ImageFormat* STENCIL8();
443 
444  static const ImageFormat* STENCIL16();
445 
446  static const ImageFormat* DEPTH24_STENCIL8();
447 
448  static const ImageFormat* YUV420_PLANAR();
449 
450  static const ImageFormat* YUV422();
451 
452  static const ImageFormat* YUV444();
453 
459  static const ImageFormat* AUTO() { return NULL; }
460 
464  static const ImageFormat* depth(int depthBits = 24);
465 
469  static const ImageFormat* stencil(int bits = 8);
470 
473  static const ImageFormat* fromCode(ImageFormat::Code code);
474 
475 
478  public:
479  enum Value {
484  };
485  private:
486  static const char* toString(int i, Value& v) {
487  static const char* str[] = {"NEAREST", "BILINEAR", "MHC", "BEST", NULL};
488  static const Value val[] = {NEAREST, BILINEAR, MHC, BEST};
489  const char* s = str[i];
490  if (s) {
491  v = val[i];
492  }
493  return s;
494  }
495 
497 
498  public:
499 
501  };
502 
516  static bool convert(const Array<const void*>& srcBytes, int srcWidth, int srcHeight, const ImageFormat* srcFormat, int srcRowPadBits,
517  const Array<void*>& dstBytes, const ImageFormat* dstFormat, int dstRowPadBits,
518  bool invertY = false, BayerAlgorithm bayerAlg = BayerAlgorithm::MHC);
519 
525  static bool conversionAvailable(const ImageFormat* srcFormat, int srcRowPadBits, const ImageFormat* dstFormat, int dstRowPadBits, bool invertY = false);
526 
528  bool representableAsColor1unorm8() const;
529 
531  bool representableAsColor2unorm8() const;
532 
534  bool representableAsColor3unorm8() const;
535 
537  bool representableAsColor4unorm8() const;
538 
544  Color4 channelMask() const;
545 
546  bool isIntegerFormat() const{
547  return (numberFormat == INTEGER_FORMAT);
548  }
549 
552  bool sameComponents(const ImageFormat* other) const;
553 
554 };
555 
557 
558 }
559 
560 template <>
561 struct HashTrait<const G3D::ImageFormat*> {
562  static size_t hashCode(const G3D::ImageFormat* key) { return reinterpret_cast<size_t>(key); }
563 };
564 
565 
566 
567 #endif
Definition: ImageFormat.h:147
Definition: ImageFormat.h:139
Definition: ImageFormat.h:171
Definition: ImageFormat.h:80
Definition: ImageFormat.h:159
static const ImageFormat * L16()
static const ImageFormat * R16I()
static const ImageFormat * L16F()
Definition: ImageFormat.h:90
static const ImageFormat * YUV444()
static const ImageFormat * depth(int depthBits=24)
Definition: ImageFormat.cpp:75
Definition: ImageFormat.h:98
static const ImageFormat * SLA8()
Definition: ImageFormat.h:105
Definition: ImageFormat.h:138
static const ImageFormat * LA16()
static const ImageFormat * RGBA8I()
static const ImageFormat * RGBA8_SNORM()
static const ImageFormat * getSRGBFormat(const ImageFormat *otherFormat)
Definition: ImageFormat.cpp:283
static const ImageFormat * RG8UI()
static const ImageFormat * LA32F()
static const ImageFormat * A32F()
static const ImageFormat * SRGB_DXT1()
bool representableAsColor4unorm8() const
Definition: ImageFormat.cpp:708
Definition: ImageFormat.h:95
static const ImageFormat * RGBA_DXT1()
int stencilBits
Definition: ImageFormat.h:224
int openGLFormat
Definition: ImageFormat.h:204
static const ImageFormat * SRGBA_DXT5()
static bool convert(const Array< const void * > &srcBytes, int srcWidth, int srcHeight, const ImageFormat *srcFormat, int srcRowPadBits, const Array< void * > &dstBytes, const ImageFormat *dstFormat, int dstRowPadBits, bool invertY=false, BayerAlgorithm bayerAlg=BayerAlgorithm::MHC)
Definition: ImageFormat_convert.cpp:163
Definition: ImageFormat.h:94
Definition: ImageFormat.h:137
static const ImageFormat * R16UI()
Definition: ImageFormat.h:72
NumberFormat
Definition: ImageFormat.h:184
Definition: ImageFormat.h:48
Definition: ImageFormat.h:62
Definition: ImageFormat.h:88
Definition: ImageFormat.h:117
Definition: ImageFormat.h:92
static const ImageFormat * RGB9E5F()
Definition: ImageFormat.h:483
bool representableAsColor2unorm8() const
Definition: ImageFormat.cpp:692
Value
Definition: ImageFormat.h:479
Definition: ImageFormat.h:125
Definition: ImageFormat.h:54
Definition: ImageFormat.h:87
Definition: ImageFormat.h:58
Definition: ImageFormat.h:142
Definition: ImageFormat.h:53
static const ImageFormat * DEPTH24_STENCIL8()
Definition: ImageFormat.h:99
ImageFormat(int numComponents, bool compressed, int glFormat, int glBaseFormat, int luminanceBits, int alphaBits, int redBits, int greenBits, int blueBits, int depthBits, int stencilBits, int openGLBitsPerPixel, int cpuBitsPerPixel, int glDataFormat, bool opaque, NumberFormat numberFormat, Code code, ColorSpace colorSpace, BayerPattern bayerPattern=BAYER_PATTERN_NONE)
Definition: ImageFormat.cpp:16
Definition: ImageFormat.h:75
Definition: ImageFormat.h:79
static const ImageFormat * YUV420_PLANAR()
static const ImageFormat * RG16F()
Definition: ImageFormat.h:186
static const char * toString(int i, Value &v)
Definition: ImageFormat.h:486
Definition: ImageFormat.h:149
int redBits
Definition: ImageFormat.h:215
static const ImageFormat * RGB5()
static const ImageFormat * R8UI()
Definition: ImageFormat.h:168
static const ImageFormat * STENCIL4()
bool opaque
Definition: ImageFormat.h:246
Definition: ImageFormat.h:109
Definition: HashTrait.h:105
static const ImageFormat * R16F()
int openGLDataFormat
Definition: ImageFormat.h:243
Definition: AABox.h:25
Definition: ImageFormat.h:188
int depthBits
Definition: ImageFormat.h:227
arena_t NULL
Definition: jemalloc_internal.h:624
const std::string & name() const
Definition: ImageFormat.cpp:245
Definition: ImageFormat.h:157
static const ImageFormat * R8I()
ColorSpace colorSpace
Definition: ImageFormat.h:198
Definition: ImageFormat.h:169
Definition: ImageFormat.h:122
static const ImageFormat * RGBA8UI()
Definition: ImageFormat.h:127
static const ImageFormat * RG32F()
static const ImageFormat * RGB16_SNORM()
Definition: ImageFormat.h:85
static const ImageFormat * RGB32I()
Definition: ImageFormat.h:91
static const ImageFormat * RGBA32UI()
static const ImageFormat * RGB5A1()
Definition: ImageFormat.h:164
Definition: ImageFormat.h:121
static const ImageFormat * RGB16F()
static const ImageFormat * RGB10()
static const ImageFormat * RGB8()
static const ImageFormat * RGBA16F()
static const ImageFormat * RGBA32F()
static const ImageFormat * LA4()
Definition: ImageFormat.h:130
Definition: ImageFormat.h:480
static const ImageFormat * RG8()
static const ImageFormat * LA16F()
Definition: ImageFormat.h:56
Definition: ImageFormat.h:482
Definition: ImageFormat.h:35
static const ImageFormat * getFormatWithAlpha(const ImageFormat *otherFormat)
Definition: ImageFormat.cpp:309
static const ImageFormat * RGBA16UI()
static const ImageFormat * fromCode(ImageFormat::Code code)
Definition: ImageFormat.cpp:399
static const ImageFormat * RGBA32I()
Definition: ImageFormat.h:68
Definition: ImageFormat.h:39
int blueBits
Definition: ImageFormat.h:221
Definition: ImageFormat.h:102
static const ImageFormat * RGB32UI()
static const ImageFormat * RGB8UI()
static const ImageFormat * R16()
Definition: ImageFormat.h:60
int greenBits
Definition: ImageFormat.h:218
Definition: ImageFormat.h:49
Definition: ImageFormat.h:81
Definition: ImageFormat.h:158
Definition: ImageFormat.h:55
NumberFormat numberFormat
Definition: ImageFormat.h:253
Definition: ImageFormat.h:118
Definition: ImageFormat.h:132
Definition: ImageFormat.h:126
Definition: ImageFormat.h:70
Definition: ImageFormat.h:148
static const ImageFormat * DEPTH24()
int alphaBits
Definition: ImageFormat.h:212
Definition: ImageFormat.h:141
static const ImageFormat * RG16UI()
static const ImageFormat * DEPTH16()
Code
Definition: ImageFormat.h:34
Definition: ImageFormat.h:65
bool representableAsColor3unorm8() const
Definition: ImageFormat.cpp:701
Definition: ImageFormat.h:61
bool canInterpretAs(const ImageFormat *otherFormat) const
Definition: ImageFormat.cpp:250
static const ImageFormat * RGB16()
Definition: ImageFormat.h:83
static const ImageFormat * R32UI()
Definition: ImageFormat.h:134
Definition: ImageFormat.h:101
Definition: ImageFormat.h:180
Definition: ImageFormat.h:176
BayerPattern bayerPattern
Definition: ImageFormat.h:201
static const ImageFormat * RG16()
Definition: ImageFormat.h:37
static const ImageFormat * BGR8()
static const ImageFormat * STENCIL8()
static const ImageFormat * RGB10A2()
int cpuBitsPerPixel
Definition: ImageFormat.h:230
Definition: ImageFormat.h:42
static const ImageFormat * RG32I()
static const ImageFormat * fromString(const std::string &s)
Definition: ImageFormat.cpp:386
static const ImageFormat * RGBA8()
static const ImageFormat * RGBA16I()
Definition: ImageFormat.h:116
Definition: ImageFormat.h:64
Definition: ImageFormat.h:162
static const ImageFormat * SRGBA_DXT3()
G3D_DECLARE_ENUM_CLASS_METHODS(BayerAlgorithm)
Definition: ImageFormat.h:112
Definition: ImageFormat.h:104
static const ImageFormat * A16()
Definition: ImageFormat.h:115
uint16 bits() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm16.h:89
Definition: ImageFormat.h:71
Definition: ImageFormat.h:120
Definition: ImageFormat.h:144
static const ImageFormat * AUTO()
Definition: ImageFormat.h:459
static const ImageFormat * RG16I()
Code code
Definition: ImageFormat.h:196
int luminanceBits
Definition: ImageFormat.h:209
Definition: ImageFormat.h:154
Definition: ImageFormat.h:96
Definition: ImageFormat.h:150
Definition: ImageFormat.h:38
bool isIntegerFormat() const
Definition: ImageFormat.h:546
Definition: ImageFormat.h:36
Definition: ImageFormat.h:110
Definition: ImageFormat.h:179
Definition: ImageFormat.h:185
Definition: ImageFormat.h:51
Definition: ImageFormat.h:136
static const ImageFormat * RG32UI()
Definition: ImageFormat.h:178
ColorSpace
Definition: ImageFormat.h:167
Definition: ImageFormat.h:108
static const ImageFormat * LA8()
static const ImageFormat * RGB8_SNORM()
Definition: ImageFormat.h:67
static const ImageFormat * RGBA_DXT5()
Definition: ImageFormat.h:129
Definition: ImageFormat.h:481
static const ImageFormat * YUV422()
static bool conversionAvailable(const ImageFormat *srcFormat, int srcRowPadBits, const ImageFormat *dstFormat, int dstRowPadBits, bool invertY=false)
static const ImageFormat * BGRA8()
Definition: ImageFormat.h:44
Definition: ImageFormat.h:43
Definition: ImageFormat.h:155
Definition: ImageFormat.h:177
int openGLBitsPerPixel
Definition: ImageFormat.h:240
bool compressed
Definition: ImageFormat.h:193
static const ImageFormat * RGB32F()
Definition: ImageFormat.h:50
Definition: ImageFormat.h:133
Definition: ImageFormat.h:145
Definition: ImageFormat.h:107
Color4 channelMask() const
Definition: ImageFormat.cpp:714
static const ImageFormat * R32I()
static const ImageFormat * stencil(int bits=8)
Definition: ImageFormat.cpp:94
Definition: ImageFormat.h:77
static const ImageFormat * RGBA_DXT3()
BayerPattern
Definition: ImageFormat.h:175
Definition: ImageFormat.h:47
static const ImageFormat * R32F()
int numComponents
Definition: ImageFormat.h:192
Definition: ImageFormat.h:152
Definition: ImageFormat.h:170
static const ImageFormat * R11G11B10F()
Definition: ImageFormat.h:153
Definition: ImageFormat.h:40
Definition: ImageFormat.h:123
bool sameComponents(const ImageFormat *other) const
Definition: ImageFormat.cpp:62
#define const
Definition: zconf.h:217
Definition: ImageFormat.h:73
static const ImageFormat * SRGB8()
static const ImageFormat * SRGBA_DXT1()
static const ImageFormat * L8()
static size_t hashCode(const G3D::ImageFormat *key)
Definition: ImageFormat.h:562
Definition: ImageFormat.h:172
static const ImageFormat * RGB8I()
static const ImageFormat * R8()
Definition: ImageFormat.h:124
static const ImageFormat * A16F()
static const ImageFormat * DEPTH32F()
static const ImageFormat * RG8I()
Value value
Definition: ImageFormat.h:496
Definition: ImageFormat.h:477
bool floatingPoint
Definition: ImageFormat.h:250
ImageFormat TextureFormat
Definition: ImageFormat.h:556
Definition: ImageFormat.h:30
static const ImageFormat * SL8()
static const ImageFormat * RGB_DXT1()
bool representableAsColor1unorm8() const
Definition: ImageFormat.cpp:683
static const ImageFormat * STENCIL1()
static const ImageFormat * RGBA16_SNORM()
Definition: ImageFormat.h:59
static const ImageFormat * L32F()
Definition: Color4.h:33
Definition: ImageFormat.h:76
Definition: ImageFormat.h:113
Definition: ImageFormat.h:45
static const ImageFormat * SRGBA8()
Definition: ImageFormat.h:160
static const ImageFormat * A8()
Definition: ImageFormat.h:84
int openGLBaseFormat
Definition: ImageFormat.h:207
static const ImageFormat * DEPTH32()
Definition: ImageFormat.h:57
static const ImageFormat * STENCIL16()
static const ImageFormat * RGBA16()