Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
image.h
Go to the documentation of this file.
1 
18 #ifndef ION_GFX_IMAGE_H_
19 #define ION_GFX_IMAGE_H_
20 
21 #include "base/integral_types.h"
22 #include "ion/base/datacontainer.h"
23 #include "ion/base/notifier.h"
24 
25 namespace ion {
26 namespace gfx {
27 
29 class Image;
31 
35 class ION_API Image : public base::Notifier {
36  public:
38  enum Format {
40  kAlpha, // Single-component alpha image, 8 bits per pixel.
41  kLuminance, // Single-component luminance image, 8 bits per pixel.
42  kLuminanceAlpha, // Two-component luminance+alpha image, 8 bits each.
43  kRgb888, // RGB color image, 8 bits each.
44  kRgba8888, // RGBA color image, 8 bits each.
45  kRgb565, // RGB color image, 5 bits red and blue, 6 bits green.
46  kRgba4444, // RGBA color+alpha image, 4 bits each.
47  kRgba5551, // RGBA color+alpha image, 5 bits per color, 1 bit
48  kRgbaFloat, // RGBA 32-bit floating point image (for OpenGL ES 2.0
51 
53  kR8, // Float image, 8-bits red.
54  kRSigned8, // Float image, 8-bits red, signed data.
55  kR8i, // Integer image, 8-bits red.
56  kR8ui, // Integer image, 8-bits red.
57  kR16fFloat, // Float image, 16-bits red, 32-bit float data.
58  kR16fHalf, // Float image, 16-bits red, 16-bit half float data.
59  kR16i, // Integer image, 16-bits red.
60  kR16ui, // Integer image, 16-bits red.
61  kR32f, // Float image, 32-bits red.
62  kR32i, // Integer image, 32-bits red.
63  kR32ui, // Integer image, 32-bits red.
64 
66  kRg8, // Float image, 8-bits each component.
67  kRgSigned8, // Float image, 8-bits each component, signed data.
68  kRg8i, // Integer image, 8-bits each component.
69  kRg8ui, // Integer image, 8-bits each component.
70  kRg16fFloat, // Float image, 16-bits each component, float data.
71  kRg16fHalf, // Float image, 16-bits each component, half float data.
72  kRg16i, // Integer image, 16-bits each component.
73  kRg16ui, // Integer image, 16-bits each component.
74  kRg32f, // Float image, 32-bits each component.
75  kRg32i, // Integer image, 32-bits each component.
76  kRg32ui, // Integer image, 32-bits each component.
77 
79  kRgb8, // Float image, 8-bits each component.
80  kRgbSigned8, // Float image, 8-bits each component, signed data.
81  kRgb8i, // Integer image, 8-bits each component, signed data.
82  kRgb8ui, // Integer image, 8-bits each component.
83  kRgb16fFloat, // Float image, 16-bits each component, float data.
84  kRgb16fHalf, // Float image, 16-bits each component, half float data.
85  kRgb16i, // Integer image, 16-bits each component, signed data.
86  kRgb16ui, // Integer image, 16-bits each component.
87  kRgb32f, // float image, 32-bits each component.
88  kRgb32i, // Integer image, 32-bits each component, signed data.
89  kRgb32ui, // Integer image, 32-bits each component.
90 
92  kRgba8, // Float image, 8-bits each component.
93  kRgbaSigned8, // Float image, 8-bits each component, signed data.
94  kRgba8i, // Integer image, 8-bits each component, signed data.
95  kRgba8ui, // Integer image, 8-bits each component.
96  kRgb10a2, // Float image, 10 bits per color, 2 bits alpha.
97  kRgb10a2ui, // Integer image, 10 bits per color, 2 bits alpha.
98  kRgba16fFloat, // Float image, 16-bits each component, float data.
99  kRgba16fHalf, // Float image, 16-bits each component, half float data.
100  kRgba16i, // Integer image, 16-bits each component, signed data.
101  kRgba16ui, // Integer image, 16-bits each component.
102  kRgba32f, // Float image, 32-bits each component.
103  kRgba32i, // Integer image, 32-bits each component, signed data.
104  kRgba32ui, // Integer image, 32-bits each component.
105 
107  kRenderbufferDepth16, // Depth rb, 16-bit depth.
108  kRenderbufferDepth24, // Depth rb, 24-bit depth.
109  kRenderbufferDepth32f, // Depth rb, 32-bit float depth.
110  kRenderbufferDepth24Stencil8, // Depth stencil rb, 24-bit depth, 8-bit
112  kRenderbufferDepth32fStencil8, // Depth stencil rb, 32-bit float depth,
113  8-bit stencil.
114 
116  kTextureDepth16Int, // Depth image, 16-bit depth, uint32 data.
117  kTextureDepth16Short, // Depth image, 16-bit depth, uint16 data.
118 
120  kStencil8, // Stencil image, 8-bits
121 
123  kDxt1, // DXT1-compressed image (no alpha).
124  kDxt1Rgba, // DXT1-compressed image (1 bit alpha).
125  kDxt5, // DXT5-compressed image (with alpha).
126  kEtc1, // ETC1-compressed image (no alpha).
127  kPvrtc1Rgb2, // PVRTC1-compressed image (2 bits per pixel, no alpha).
128  kPvrtc1Rgb4, // PVRTC1-compressed image (4 bits per pixel, no alpha).
129  kPvrtc1Rgba2, // PVRTC1-compressed image (2 bits per pixel, with
131  kPvrtc1Rgba4, // PVRTC1-compressed image (4 bits per pixel, with
133 
135  kSrgb8, // Float image, 8-bits each component.
136  kSrgba8, // Float image, 8-bits each component.
137 
139  kRgb11f_11f_10f_Rev, // RGB color image, 10 bits red and green, 11
141  kRgb11f_11f_10f_RevFloat, // RGB color image, 10 bits red and green, 11
143  kRgb11f_11f_10f_RevHalf, // RGB color image, 10 bits red and green, 11
145  kRgb565Byte, // RGB color image, 5 bits red and blue, 6 bits
147  kRgb565Short, // RGB color image, 5 bits red and blue, 6 bits
149  kRgb5a1Byte, // RGBA color+alpha image, 5 bits per color, 1
151  kRgb5a1Short, // RGBA color+alpha image, 5 bits per color, 1
153  kRgb5a1Int, // RGBA color+alpha image, 5 bits per color, 1
155  kRgb9e5Float, // RGB color+alpha image, 9 bits per color, 5
157  kRgb9e5Half, // RGB color+alpha image, 9 bits per color, 5
159  kRgb9e5RevInt, // RGB color+alpha image, 9 bits per color, 5
161  kRgba4Byte, // RGBA color+alpha image, 4 bits each, uint8
163  kRgba4Short, // RGBA color+alpha image, 4 bits each, packed
165 
166  kEglImage, // A texture backed by an EGLImage, which may
168 
169  kInvalid // An invalid format.
170  };
171 
177  enum Type {
182  };
183 
186  enum Dimensions {
188  k3d
189  };
190 
192  struct PixelFormat {
194  uint32 format;
195  uint32 type;
196  };
197 
198  static const uint32 kNumFormats;
199 
202  Image();
203 
206  void Set(Format format, uint32 width, uint32 height,
207  const base::DataContainerPtr& data);
209  void Set(Format format, uint32 width, uint32 height, uint32 depth,
210  const base::DataContainerPtr& data);
211 
213  void SetArray(Format format, uint32 width, uint32 num_planes,
214  const base::DataContainerPtr& data);
216  void SetArray(Format format, uint32 width, uint32 height, uint32 num_planes,
217  const base::DataContainerPtr& data);
218 
224  void SetEglImage(const base::DataContainerPtr& image);
225 
231  void SetExternalEglImage(const base::DataContainerPtr& external_image);
232 
233  Format GetFormat() const { return format_; }
234  Type GetType() const { return type_; }
235  Dimensions GetDimensions() const { return dims_; }
236  uint32 GetWidth() const { return width_; }
237  uint32 GetHeight() const { return height_; }
238  uint32 GetDepth() const { return depth_; }
239  size_t GetDataSize() const { return data_size_; }
240  const base::DataContainerPtr& GetData() const { return data_; }
241 
243  bool IsCompressed() const { return IsCompressedFormat(format_); }
244 
247  static const char* GetFormatString(Format format);
248 
250  static const PixelFormat& GetPixelFormat(Format format);
251 
254  static int GetNumComponentsForFormat(Format format);
255 
258  static bool IsCompressedFormat(Format format);
263  static bool Is8BitPerChannelFormat(Format format);
264 
267  static size_t ComputeDataSize(Format format, uint32 width, uint32 height);
268  static size_t ComputeDataSize(Format format, uint32 width, uint32 height,
269  uint32 depth);
270 
271  protected:
274  ~Image() override;
275 
276  private:
278  void OnNotify(const base::Notifier* notifier) override {
279  if (notifier == data_.Get())
280  Notify();
281  }
282 
284  void SetData(Type type, Dimensions dims, Format format, uint32 width,
285  uint32 height, uint32 depth, const base::DataContainerPtr& data);
286 
287  Format format_;
288  uint32 width_;
289  uint32 height_;
290  uint32 depth_;
291  size_t data_size_;
292  Type type_;
293  Dimensions dims_;
295 };
296 
298  return format == kDxt1 || format == kDxt1Rgba || format == kDxt5 ||
299  format == kEtc1 || format == kPvrtc1Rgb2 || format == kPvrtc1Rgb4 ||
300  format == kPvrtc1Rgba2 || format == kPvrtc1Rgba4;
301 }
302 
307  if (format == Image::kRgb5a1Int ||
308  format == Image::kRgb10a2 ||
309  format == Image::kRgb10a2ui ||
310  format == Image::kEglImage ||
311  format == Image::kInvalid) {
312  return false;
313  }
314  size_t bytes_per_pixel = Image::ComputeDataSize(format, 1, 1);
315  size_t channels = Image::GetNumComponentsForFormat(format);
316  return channels == bytes_per_pixel;
317 }
318 
319 } // namespace gfx
320 } // namespace ion
321 
322 #endif // ION_GFX_IMAGE_H_
uint32 GetWidth() const
Definition: image.h:236
"Unsized" formats.
Definition: image.h:40
Format
Supported image formats.
Definition: image.h:38
bits exponent, half float data.
Definition: image.h:159
base::ReferentPtr< Image >::Type ImagePtr
Definition: image.h:29
std::string type
Definition: printer.cc:353
Dimensions GetDimensions() const
Definition: image.h:235
Format GetFormat() const
Definition: image.h:233
Depth and depth/stencil renderbuffers.
Definition: image.h:107
A Notifier both sends notifications to and receives notifications from other Notifiers.
Definition: notifier.h:35
bit alpha, packed 5551 uint16 data.
Definition: image.h:153
bit alpha, packed 2,10,10,10 uint32 data.
Definition: image.h:155
Four channel RGBA images.
Definition: image.h:92
bool IsCompressed() const
Returns true if the image format is one of the compressed types.
Definition: image.h:243
Struct representing the GL types for a particular Format (see above).
Definition: image.h:192
Dimensions
The number of dimensions in the image.
Definition: image.h:186
bit alpha, uint8 data.
Definition: image.h:151
Three channel RGB images.
Definition: image.h:79
uint32 GetHeight() const
Definition: image.h:237
static size_t ComputeDataSize(Format format, uint32 width, uint32 height)
Convenience functions that return the correct data size in bytes of an image having the given format ...
Definition: image.cc:421
An Image represents 2D image data that can be used in a texture supplied to a shader.
Definition: image.h:35
Two-component red-green images.
Definition: image.h:66
bits exponent, packed 5999 uint32 data.
Definition: image.h:161
have arbitrary format.
Definition: image.h:169
bits blue, packed 10f,11f,11f uint32 data.
Definition: image.h:141
bits exponent, float data.
Definition: image.h:157
4444 uint16 data.
Definition: image.h:166
const Grid & image
The original monochrome image data, as doubles (0 - 1).
Definition: sdfutils.cc:90
Packed sized images.
Definition: image.h:139
Compressed images.
Definition: image.h:123
size_t GetDataSize() const
Definition: image.h:239
bits blue, packed float data.
Definition: image.h:143
bits blue, packed half float data.
Definition: image.h:145
int width
static int GetNumComponentsForFormat(Format format)
Convenience function that returns the number of components for a given format.
Definition: image.cc:315
uint32 GetDepth() const
Definition: image.h:238
Stencil images.
Definition: image.h:120
static bool IsCompressedFormat(Format format)
Convenience function that returns true if the given format represents compressed image data...
Definition: image.h:297
compatibility, where both format and internal_format are GL_RGBA).
Definition: image.h:53
Type
The kind of Image, either array or dense, or an EGL type.
Definition: image.h:177
green, uint8 data.
Definition: image.h:147
static bool Is8BitPerChannelFormat(Format format)
Returns whether the specified format has 8 bits per channel.
Definition: image.h:303
Type GetType() const
Definition: image.h:234
const base::DataContainerPtr & GetData() const
Definition: image.h:240
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
static const uint32 kNumFormats
Definition: image.h:198
green, packed 565 uint16 data.
Definition: image.h:149