nux-1.16.0
|
Image Surface class. More...
#include <NuxImage/ImageSurface.h>
Public Member Functions | |
ImageSurface (BitmapFormat format, t_u32 width, t_u32 height) | |
ImageSurface (const ImageSurface &) | |
ImageSurface & | operator= (const ImageSurface &) |
bool | IsNull () const |
t_s32 | GetWidth () const |
t_s32 | GetHeight () const |
void | Allocate (BitmapFormat format, t_s32 width, t_s32 height) |
void | Write32b (t_s32 i, t_s32 j, t_u32 value) |
void | Write24b (t_s32 i, t_s32 j, t_u32 value) |
void | Write16b (t_s32 i, t_s32 j, t_u16 value) |
void | Write8b (t_s32 i, t_s32 j, t_u8 value) |
void | Write (t_s32 i, t_s32 j, t_u8 r, t_u8 g, t_u8 b, t_u8 a) |
t_u32 | Read (t_s32 i, t_s32 j) |
Read an element of the surface. | |
void | Clear () |
Set all surface elements to 0. | |
void | FlipHorizontal () |
Flip the surface horizontally. | |
void | FlipVertical () |
Flip the surface vertically. | |
t_s32 | GetPitch () const |
Returns the surface pitch. | |
t_s32 | GetBlockHeight () const |
t_s32 | GetAlignment () const |
t_s32 | GetSize () const |
BitmapFormat | GetFormat () const |
const t_u8 * | GetPtrRawData () const |
t_u8 * | GetPtrRawData () |
struct Color | AverageColor () |
Compute the average color of the image surface. | |
Static Public Member Functions | |
static t_s32 | GetLevelPitch (BitmapFormat format, t_s32 width, t_s32 height, t_s32 miplevel) |
static t_s32 | GetLevelPitchNoMemAlignment (BitmapFormat format, t_s32 width, t_s32 height, t_s32 miplevel) |
static t_s32 | GetLevelSize (BitmapFormat format, t_s32 width, t_s32 height, t_s32 miplevel) |
static t_s32 | GetLevelSize (BitmapFormat format, t_s32 width, t_s32 height, t_s32 depth, t_s32 miplevel) |
static t_s32 | GetLevelWidth (BitmapFormat format, t_s32 width, t_s32 miplevel) |
static t_s32 | GetLevelHeight (BitmapFormat format, t_s32 height, t_s32 miplevel) |
static t_s32 | GetLevelDim (BitmapFormat format, t_s32 length, t_s32 miplevel) |
static t_s32 | GetNumMipLevel (BitmapFormat format, t_s32 width, t_s32 height) |
static t_s32 | GetMemAlignment (BitmapFormat format) |
static t_s32 | GetLevelBlockWidth (BitmapFormat format, t_s32 width, t_s32 miplevel) |
static t_s32 | GetLevelBlockHeight (BitmapFormat format, t_s32 height, t_s32 miplevel) |
Image Surface class.
Represent and image surface inside a complex data structure such as a 2D texture, Volume texture or Cube map.
Definition at line 87 of file ImageSurface.h.
Color nux::ImageSurface::AverageColor | ( | ) | [read] |
Compute the average color of the image surface.
Sum up all the image elements and divide by the number of elements.
Definition at line 862 of file ImageSurface.cpp.
{ if (width_ == 0 || height_ == 0) return Color (0.f, 0.f, 0.f, 0.f); t_float r, g, b, a; r = g = b = a = 0; if (bpe_ == 8) { for (int j = 0; j < height_; j++) { for (int i = 0; i < width_; i++) { t_u32 v = Read (i, j); r += (v & 0x000000FF); g += (v & 0x0000FF00) >> 1; b += (v & 0x00FF0000) >> 2; a += (v & 0xFF000000) >> 3; } } } t_u32 num_pixels = width_ * height_; return Color (r / num_pixels, g / num_pixels, b / num_pixels, a / num_pixels); }
t_u32 nux::ImageSurface::Read | ( | t_s32 | i, |
t_s32 | j | ||
) |
Read an element of the surface.
Return a 32 bits value representing the image element at coordinates (i, j). For the RGBA format, the LSB of the returned value represent the read value, and the MSB represents the alpha value. | LSB: Red | Green | Blue | MSB: Alpha|
Definition at line 502 of file ImageSurface.cpp.
{ nuxAssert (i < width_); nuxAssert (j < height_); nuxAssert (bpe_); if ( (format_ == BITFMT_DXT1) || (format_ == BITFMT_DXT2) || (format_ == BITFMT_DXT3) || (format_ == BITFMT_DXT4) || (format_ == BITFMT_DXT5) ) return 0x00000000; if (bpe_ == 4) { return ( (t_u32) RawData_[j * m_Pitch + i * bpe_ + 3] << 24) | ( (t_u32) RawData_[j * m_Pitch + i * bpe_ + 2] << 16) | ( (t_u32) RawData_[j * m_Pitch + i * bpe_ + 1] << 8) | ( (t_u32) RawData_[j * m_Pitch + i * bpe_ + 0] << 0); } if (bpe_ == 3) { return ( (t_u32) RawData_[j * m_Pitch + i * bpe_ + 2] << 16) | ( (t_u32) RawData_[j * m_Pitch + i * bpe_ + 1] << 8) | ( (t_u32) RawData_[j * m_Pitch + i * bpe_ + 0] << 0); } if (bpe_ == 2) { return ( (t_u32) RawData_[j * m_Pitch + i * bpe_ + 1] << 8) | ( (t_u32) RawData_[j * m_Pitch + i * bpe_ + 0] << 0); } if (bpe_ == 1) { return (t_u32) RawData_[j * m_Pitch + i * bpe_ + 0]; } return 0x0000000; }