Back to index

nux  3.0.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
nux::ImageSurface Class Reference

Image Surface class. More...

#include <ImageSurface.h>

List of all members.

Public Member Functions

 ImageSurface ()
 ~ImageSurface ()
 ImageSurface (BitmapFormat format, unsigned int width, unsigned int height)
 ImageSurface (const ImageSurface &)
ImageSurfaceoperator= (const ImageSurface &)
bool IsNull () const
int GetWidth () const
int GetHeight () const
void Allocate (BitmapFormat format, int width, int height)
void Write32b (int i, int j, unsigned int value)
void Write24b (int i, int j, unsigned int value)
void Write16b (int i, int j, unsigned short value)
void Write8b (int i, int j, unsigned char value)
void Write (int i, int j, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
unsigned int Read (int i, int 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.
int GetPitch () const
 Returns the surface pitch.
int GetBlockHeight () const
int GetAlignment () const
int GetSize () const
BitmapFormat GetFormat () const
const unsigned char * GetPtrRawData () const
unsigned char * GetPtrRawData ()
Color AverageColor ()
 Compute the average color of the image surface.

Static Public Member Functions

static int GetLevelPitch (BitmapFormat format, int width, int height, int miplevel)
static int GetLevelPitchNoMemAlignment (BitmapFormat format, int width, int height, int miplevel)
static int GetLevelSize (BitmapFormat format, int width, int height, int miplevel)
static int GetLevelSize (BitmapFormat format, int width, int height, int depth, int miplevel)
static int GetLevelWidth (BitmapFormat format, int width, int miplevel)
static int GetLevelHeight (BitmapFormat format, int height, int miplevel)
static int GetLevelDim (BitmapFormat format, int length, int miplevel)
static int GetNumMipLevel (BitmapFormat format, int width, int height)
static int GetMemAlignment (BitmapFormat format)
static int GetLevelBlockWidth (BitmapFormat format, int width, int miplevel)
static int GetLevelBlockHeight (BitmapFormat format, int height, int miplevel)

Private Member Functions

void FlipDXTVertical ()
void SwapBlocks (void *byte1, void *byte2, int size)
void FlipBlocksDXT1 (DXTColBlock *line, int numBlocks)
void FlipBlocksDXT3 (DXTColBlock *line, int numBlocks)
void FlipBlocksDXT5 (DXTColBlock *line, int numBlocks)
void FlipDXT5Alpha (DXT5AlphaBlock *block)

Private Attributes

int width_
 Image width.
int height_
 Image height.
BitmapFormat format_
 Image format.
int m_Pitch
 Image pitch.
int bpe_
 Number of byte per element.
int Alignment_
 Data alignment.
unsigned char * RawData_

Detailed Description

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.


Constructor & Destructor Documentation

Definition at line 160 of file ImageSurface.cpp.

Here is the call graph for this function:

Definition at line 172 of file ImageSurface.cpp.

  {
    delete [] RawData_;
  }
nux::ImageSurface::ImageSurface ( BitmapFormat  format,
unsigned int  width,
unsigned int  height 
)

Definition at line 177 of file ImageSurface.cpp.

    :   width_(0)
    ,   height_(0)
    ,   format_(BITFMT_UNKNOWN)
    ,   m_Pitch(0)
    ,   bpe_(0)
    ,   Alignment_(4)
    ,   RawData_(0)
  {
    Allocate(format, width, height);
  }

Here is the call graph for this function:

Definition at line 189 of file ImageSurface.cpp.

  {
    width_ = surface.width_;
    height_ = surface.height_;
    bpe_ = surface.bpe_;
    format_ = surface.format_;
    m_Pitch = surface.m_Pitch;
    Alignment_ = surface.Alignment_;

    RawData_ = new unsigned char[surface.GetSize()];
    Memcpy(RawData_, surface.RawData_, surface.GetSize());
  }

Here is the call graph for this function:


Member Function Documentation

void nux::ImageSurface::Allocate ( BitmapFormat  format,
int  width,
int  height 
)

Definition at line 243 of file ImageSurface.cpp.

  {
    nuxAssert(format < BITFMT_END_GFX_FORMATS);
    nuxAssert(width >= 0);
    nuxAssert(height >= 0);

    if (width < 0)
      width = 0;

    if (height < 0)
      height = 0;

    if ((format_ == format) &&
         (width_ == width) &&
         (height_ == height))
    {
      // no need to recreate
      Clear();
      return;
    }

    delete [] RawData_;

    if ((width == 0) || (height == 0))
    {
      width_ = 0;
      height_ = 0;
      Alignment_ = 1;
      bpe_ = 0;
      format_ = BITFMT_UNKNOWN;
      m_Pitch = 0;
      return;
    }

    width_ = width;
    height_ = height;


    Alignment_ = GPixelFormats[format].RowMemoryAlignment;

    bpe_ = GPixelFormats[format].BlockBytes;
    format_ = format;

    if ((format_ == BITFMT_DXT1) ||
         (format_ == BITFMT_DXT2) ||
         (format_ == BITFMT_DXT3) ||
         (format_ == BITFMT_DXT4) ||
         (format_ == BITFMT_DXT5))
    {
      // For DXT, width and height are rounded up to a multiple of 4 in order
      // to create 4x4 blocks of pixels; And in this context, byte alignment
      // is 1 ie. data is densely packed.
      unsigned int block = GPixelFormats[format].BlockSizeX;
      unsigned int shift = Log2(GPixelFormats[format].BlockSizeX);
      m_Pitch = Align((bpe_ * ((width_ + (block - 1)) >> shift)), Alignment_);

      block = GPixelFormats[format].BlockSizeY;
      shift = Log2(GPixelFormats[format].BlockSizeY);
      RawData_ = new unsigned char[m_Pitch * Align((height + (block-1)) >> shift, block) ];
    }
    else
    {
      unsigned int block = GPixelFormats[format].BlockSizeX;
      unsigned int shift = Log2(GPixelFormats[format].BlockSizeX);
      m_Pitch = Align((bpe_ * ((width_ + (block - 1)) >> shift)),  Alignment_);

      block = GPixelFormats[format].BlockSizeY;
      shift = Log2(GPixelFormats[format].BlockSizeY);
      RawData_ = new unsigned char[m_Pitch * Align((height + (block-1)) >> shift, block) ];
    }

    Clear();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Compute the average color of the image surface.

Sum up all the image elements and divide by the number of elements.

Returns:
The average color of the image.

Definition at line 860 of file ImageSurface.cpp.

  {
    if (width_ == 0 || height_ == 0)
      return Color(0.f, 0.f, 0.f, 0.f);

    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++)
        {
          unsigned int v = Read(i, j);
          r += (v & 0x000000FF);
          g += (v & 0x0000FF00) >> 1;
          b += (v & 0x00FF0000) >> 2;
          a += (v & 0xFF000000) >> 3;
        }
      }
    }

    unsigned int num_pixels = width_ * height_;
    return Color(r / num_pixels, g / num_pixels, b / num_pixels, a / num_pixels);
  }

Here is the call graph for this function:

Set all surface elements to 0.

Definition at line 540 of file ImageSurface.cpp.

  {
    if (RawData_ == 0)
      return;

    if ((width_ == 0) || (height_ == 0))
      return;

    auto size = GetSize();
    memset(RawData_, 0, size);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::ImageSurface::FlipBlocksDXT1 ( DXTColBlock line,
int  numBlocks 
) [private]

Definition at line 706 of file ImageSurface.cpp.

  {
    DXTColBlock *curblock = line;

    for (int i = 0; i < numBlocks; i++)
    {
      SwapBlocks(&curblock->row[0], &curblock->row[3], sizeof(unsigned char));
      SwapBlocks(&curblock->row[1], &curblock->row[2], sizeof(unsigned char));

      curblock++;
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::ImageSurface::FlipBlocksDXT3 ( DXTColBlock line,
int  numBlocks 
) [private]

Definition at line 719 of file ImageSurface.cpp.

  {
    DXTColBlock *curblock = line;
    DXT3AlphaBlock *alphablock;

    for (int i = 0; i < numBlocks; i++)
    {
      alphablock = (DXT3AlphaBlock *) curblock;

      SwapBlocks(&alphablock->row[0], &alphablock->row[3], sizeof(unsigned short));
      SwapBlocks(&alphablock->row[1], &alphablock->row[2], sizeof(unsigned short));

      curblock++;

      SwapBlocks(&curblock->row[0], &curblock->row[3], sizeof(unsigned char));
      SwapBlocks(&curblock->row[1], &curblock->row[2], sizeof(unsigned char));

      curblock++;
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::ImageSurface::FlipBlocksDXT5 ( DXTColBlock line,
int  numBlocks 
) [private]

Definition at line 740 of file ImageSurface.cpp.

  {
    DXTColBlock *curblock = line;
    DXT5AlphaBlock *alphablock;

    for (int i = 0; i < numBlocks; i++)
    {
      alphablock = (DXT5AlphaBlock *) curblock;

      FlipDXT5Alpha(alphablock);

      curblock++;

      SwapBlocks(&curblock->row[0], &curblock->row[3], sizeof(unsigned char));
      SwapBlocks(&curblock->row[1], &curblock->row[2], sizeof(unsigned char));

      curblock++;
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::ImageSurface::FlipDXT5Alpha ( DXT5AlphaBlock block) [private]

Definition at line 760 of file ImageSurface.cpp.

  {
    unsigned char gBits[4][4];

    const unsigned long mask = 0x00000007;          // bits = 00 00 01 11
    unsigned long bits = 0;
    memcpy(&bits, &block->row[0], sizeof(unsigned char) * 3);

    gBits[0][0] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[0][1] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[0][2] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[0][3] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[1][0] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[1][1] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[1][2] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[1][3] = (unsigned char) (bits & mask);

    bits = 0;
    memcpy(&bits, &block->row[3], sizeof(unsigned char) * 3);

    gBits[2][0] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[2][1] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[2][2] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[2][3] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[3][0] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[3][1] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[3][2] = (unsigned char) (bits & mask);
    bits >>= 3;
    gBits[3][3] = (unsigned char) (bits & mask);

    unsigned long *pBits = ((unsigned long *) & (block->row[0]));

    *pBits = *pBits | (gBits[3][0] << 0);
    *pBits = *pBits | (gBits[3][1] << 3);
    *pBits = *pBits | (gBits[3][2] << 6);
    *pBits = *pBits | (gBits[3][3] << 9);

    *pBits = *pBits | (gBits[2][0] << 12);
    *pBits = *pBits | (gBits[2][1] << 15);
    *pBits = *pBits | (gBits[2][2] << 18);
    *pBits = *pBits | (gBits[2][3] << 21);

    pBits = ((unsigned long *) & (block->row[3]));

#ifdef __APPLE__
    *pBits &= 0x000000ff;
#else
    *pBits &= 0xff000000;
#endif

    *pBits = *pBits | (gBits[1][0] << 0);
    *pBits = *pBits | (gBits[1][1] << 3);
    *pBits = *pBits | (gBits[1][2] << 6);
    *pBits = *pBits | (gBits[1][3] << 9);

    *pBits = *pBits | (gBits[0][0] << 12);
    *pBits = *pBits | (gBits[0][1] << 15);
    *pBits = *pBits | (gBits[0][2] << 18);
    *pBits = *pBits | (gBits[0][3] << 21);
  }

Here is the caller graph for this function:

Definition at line 620 of file ImageSurface.cpp.

  {
    //void(CDDSImage::*flipblocks)(DXTColBlock*, unsigned int);
    int xblocks = (width_ + 3) / 4;
    int yblocks = (height_ + 3) / 4;
    int blocksize;
    int linesize;

    switch(format_)
    {
      case BITFMT_DXT1:
        blocksize = 8;
        //flipblocks = &CDDSImage::flip_blocks_dxtc1;
        break;
      case BITFMT_DXT2:
        blocksize = 16;
        //flipblocks = &CDDSImage::flip_blocks_dxtc2;
        break;
      case BITFMT_DXT3:
        blocksize = 16;
        //flipblocks = &CDDSImage::flip_blocks_dxtc3;
        break;
      case BITFMT_DXT4:
        blocksize = 16;
        //flipblocks = &CDDSImage::flip_blocks_dxtc4;
        break;
      case BITFMT_DXT5:
        blocksize = 16;
        //flipblocks = &CDDSImage::flip_blocks_dxtc5;
        break;
      default:
        return;
    }

    linesize = xblocks * blocksize;

    DXTColBlock *top;
    DXTColBlock *bottom;

    for (int j = 0; j < (yblocks >> 1); j++)
    {
      top = (DXTColBlock *) ((unsigned char *) RawData_ + j * linesize);
      bottom = (DXTColBlock *) ((unsigned char *) RawData_ + (((yblocks - j) - 1) * linesize));

      switch(format_)
      {
        case BITFMT_DXT1:
          FlipBlocksDXT1(top, xblocks);
          FlipBlocksDXT1(bottom, xblocks);
          break;
        case BITFMT_DXT2:
          FlipBlocksDXT3(top, xblocks);
          FlipBlocksDXT3(bottom, xblocks);
          break;
        case BITFMT_DXT3:
          FlipBlocksDXT3(top, xblocks);
          FlipBlocksDXT3(bottom, xblocks);
          break;
        case BITFMT_DXT4:
          FlipBlocksDXT5(top, xblocks);
          FlipBlocksDXT5(bottom, xblocks);
          break;
        case BITFMT_DXT5:
          FlipBlocksDXT5(top, xblocks);
          FlipBlocksDXT5(bottom, xblocks);
          break;
        default:
          nuxAssert("[ImageSurface::FlipDXTVertical] Invalid Switch option.");
          break;
      }

      SwapBlocks(bottom, top, linesize);
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Flip the surface horizontally.

Definition at line 552 of file ImageSurface.cpp.

  {
    if ((format_ == BITFMT_DXT1) || (format_ == BITFMT_DXT2)  || (format_ == BITFMT_DXT3)  || (format_ == BITFMT_DXT4) || (format_ == BITFMT_DXT5))
      return;

    int i, j, k;
    unsigned char *flip_data;

    if (RawData_ == 0)
      return;

    if (width_ == 0 || height_ == 0)
      return;

    flip_data =  new unsigned char[m_Pitch*height_];

    for (j = 0; j < height_; j++)
    {
      for (i = 0; i < width_; i++)
      {
        for (k = 0; k < bpe_; k++)
        {
          flip_data[ (j*m_Pitch) + i *bpe_ + k] = RawData_[ (j*m_Pitch) + (width_-i-1) * bpe_ + k];
        }
      }
    }

    delete [] RawData_;
    RawData_ = flip_data;
  }

Flip the surface vertically.

Definition at line 583 of file ImageSurface.cpp.

  {

    int i, j, k;
    unsigned char *flip_data;

    if (RawData_ == 0)
      return;

    if (width_ == 0 || height_ == 0)
      return;

    if ((format_ == BITFMT_DXT1) || (format_ == BITFMT_DXT2) || (format_ == BITFMT_DXT3) || (format_ == BITFMT_DXT4) || (format_ == BITFMT_DXT5))
    {
      FlipDXTVertical();
    }
    else
    {
      flip_data =  new unsigned char[m_Pitch*height_];

      for (j = 0; j < height_; j++)
      {
        for (i = 0; i < width_; i++)
        {
          for (k = 0; k < bpe_; k++)
          {
            flip_data[ (j*m_Pitch) + i *bpe_ + k] = RawData_[ (height_-j-1) *m_Pitch + i * bpe_ + k];
          }
        }
      }

      delete [] RawData_;
      RawData_ = flip_data;
    }

  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 238 of file ImageSurface.cpp.

  {
    return Alignment_;
  }

Definition at line 226 of file ImageSurface.cpp.

  {
    unsigned int block = GPixelFormats[format_].BlockSizeY;
    unsigned int HeightInBlocks = Align(GetHeight(), block) / block;
    return HeightInBlocks;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 233 of file ImageSurface.cpp.

  {
    return format_;
  }

Here is the caller graph for this function:

int nux::ImageSurface::GetHeight ( ) const [inline]

Definition at line 101 of file ImageSurface.h.

    {
      return height_;
    }

Here is the caller graph for this function:

int nux::ImageSurface::GetLevelBlockHeight ( BitmapFormat  format,
int  height,
int  miplevel 
) [static]

Definition at line 409 of file ImageSurface.cpp.

  {
    int block = GPixelFormats[format].BlockSizeY;
    int HeightInBlocks = Align(GetLevelDim(format, height, miplevel), block) / block;
    return HeightInBlocks;
  }

Here is the call graph for this function:

int nux::ImageSurface::GetLevelBlockWidth ( BitmapFormat  format,
int  width,
int  miplevel 
) [static]

Definition at line 402 of file ImageSurface.cpp.

  {
    int block = GPixelFormats[format].BlockSizeX;
    int WidthInBlocks = Align(GetLevelDim(format, width, miplevel), block) / block;
    return WidthInBlocks;
  }

Here is the call graph for this function:

int nux::ImageSurface::GetLevelDim ( BitmapFormat  format,
int  length,
int  miplevel 
) [static]

Definition at line 385 of file ImageSurface.cpp.

  {
    // return 1 if the mip level does not exist.
    return Max<int> (1, length >> miplevel);
  }

Here is the caller graph for this function:

int nux::ImageSurface::GetLevelHeight ( BitmapFormat  format,
int  height,
int  miplevel 
) [static]

Definition at line 379 of file ImageSurface.cpp.

  {
    // return 1 if the mip level does not exist.
    return Max<int> (1, height >> miplevel);
  }

Here is the caller graph for this function:

int nux::ImageSurface::GetLevelPitch ( BitmapFormat  format,
int  width,
int  height,
int  miplevel 
) [static]

Definition at line 322 of file ImageSurface.cpp.

  {
    int levelwidth = ImageSurface::GetLevelDim(format, width, miplevel);

    int bpe = GPixelFormats[format].BlockBytes;
    int memalignment = GPixelFormats[format].RowMemoryAlignment;
    int block = GPixelFormats[format].BlockSizeX;
    int shift = Log2(GPixelFormats[format].BlockSizeX);
    int pitch = Align((bpe * ((levelwidth + (block - 1)) >> shift)), memalignment);

    return pitch;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

int nux::ImageSurface::GetLevelPitchNoMemAlignment ( BitmapFormat  format,
int  width,
int  height,
int  miplevel 
) [static]

Definition at line 336 of file ImageSurface.cpp.

  {
    int levelwidth = ImageSurface::GetLevelDim(format, width, miplevel);

    int bpe = GPixelFormats[format].BlockBytes;
    int block = GPixelFormats[format].BlockSizeX;
    int shift = Log2(GPixelFormats[format].BlockSizeX);
    int pitch = Align((bpe * ((levelwidth + (block - 1)) >> shift)), 1);

    return pitch;
  }

Here is the call graph for this function:

int nux::ImageSurface::GetLevelSize ( BitmapFormat  format,
int  width,
int  height,
int  miplevel 
) [static]

Definition at line 348 of file ImageSurface.cpp.

  {
    int pitch = ImageSurface::GetLevelPitch(format, width, height, miplevel);
    int levelheight = ImageSurface::GetLevelDim(format, height, miplevel);

    int block = GPixelFormats[format].BlockSizeY;
    int HeightInBlocks = Align(levelheight, block) / block;

    int size = pitch * HeightInBlocks;
    return size;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

int nux::ImageSurface::GetLevelSize ( BitmapFormat  format,
int  width,
int  height,
int  depth,
int  miplevel 
) [static]

Definition at line 360 of file ImageSurface.cpp.

  {
    int pitch = ImageSurface::GetLevelPitch(format, width, height, miplevel);
    int levelheight = ImageSurface::GetLevelDim(format, height, miplevel);
    int leveldepth = ImageSurface::GetLevelDim(format, depth, miplevel);

    int block = GPixelFormats[format].BlockSizeY;
    int HeightInBlocks = Align(levelheight, block) / block;

    int size = pitch * HeightInBlocks;
    return leveldepth * size;
  }

Here is the call graph for this function:

int nux::ImageSurface::GetLevelWidth ( BitmapFormat  format,
int  width,
int  miplevel 
) [static]

Definition at line 373 of file ImageSurface.cpp.

  {
    // return 1 if the mip level does not exist.
    return Max<int> (1, width >> miplevel);
  }

Here is the caller graph for this function:

Definition at line 397 of file ImageSurface.cpp.

  {
    return GPixelFormats[format].RowMemoryAlignment;
  }

Here is the caller graph for this function:

int nux::ImageSurface::GetNumMipLevel ( BitmapFormat  format,
int  width,
int  height 
) [static]

Definition at line 391 of file ImageSurface.cpp.

  {
    int NumTotalMipLevel    = 1 + floorf(Log2(Max(width, height)));
    return NumTotalMipLevel;
  }

Here is the call graph for this function:

Returns the surface pitch.

Definition at line 221 of file ImageSurface.cpp.

  {
    return m_Pitch;
  }

Here is the caller graph for this function:

const unsigned char * nux::ImageSurface::GetPtrRawData ( ) const

Definition at line 834 of file ImageSurface.cpp.

  {
    return RawData_;
  }

Here is the caller graph for this function:

unsigned char * nux::ImageSurface::GetPtrRawData ( )

Definition at line 839 of file ImageSurface.cpp.

  {
    return RawData_;
  }

Definition at line 844 of file ImageSurface.cpp.

  {
    if ((format_ == BITFMT_DXT1) ||
         (format_ == BITFMT_DXT2) ||
         (format_ == BITFMT_DXT3) ||
         (format_ == BITFMT_DXT4) ||
         (format_ == BITFMT_DXT5))
    {
      return m_Pitch * ((height_ + 3) >> 2);
    }
    else
    {
      return m_Pitch * height_;
    }
  }

Here is the caller graph for this function:

int nux::ImageSurface::GetWidth ( ) const [inline]

Definition at line 97 of file ImageSurface.h.

    {
      return width_;
    }

Here is the caller graph for this function:

bool nux::ImageSurface::IsNull ( ) const

Definition at line 416 of file ImageSurface.cpp.

  {
    if ((width_ == 0) || (height_ == 0) || (format_ == BITFMT_UNKNOWN))
      return true;

    return false;
  }
ImageSurface & nux::ImageSurface::operator= ( const ImageSurface surface)

Definition at line 202 of file ImageSurface.cpp.

  {
    if (this == &surface)
      return *this;   // Handle self assignment

    width_ = surface.width_;
    height_ = surface.height_;
    bpe_ = surface.bpe_;
    format_ = surface.format_;
    m_Pitch = surface.m_Pitch;
    Alignment_ = surface.Alignment_;

    delete [] RawData_;

    RawData_ = new unsigned char[surface.GetSize() ];
    Memcpy(RawData_, surface.RawData_, surface.GetSize());
    return *this;
  }

Here is the call graph for this function:

unsigned int nux::ImageSurface::Read ( int  i,
int  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|

Returns:
The image element at coordinates(i, j).

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  ((unsigned int) RawData_[j * m_Pitch + i * bpe_ + 3] << 24)   |
              ((unsigned int) RawData_[j * m_Pitch + i * bpe_ + 2] << 16)   |
              ((unsigned int) RawData_[j * m_Pitch + i * bpe_ + 1] << 8)    |
              ((unsigned int) RawData_[j * m_Pitch + i * bpe_ + 0] << 0);
    }

    if (bpe_ == 3)
    {
      return  ((unsigned int) RawData_[j * m_Pitch + i * bpe_ + 2] << 16)   |
              ((unsigned int) RawData_[j * m_Pitch + i * bpe_ + 1] << 8)    |
              ((unsigned int) RawData_[j * m_Pitch + i * bpe_ + 0] << 0);
    }

    if (bpe_ == 2)
    {
      return  ((unsigned int) RawData_[j * m_Pitch + i * bpe_ + 1] << 8)    |
              ((unsigned int) RawData_[j * m_Pitch + i * bpe_ + 0] << 0);
    }

    if (bpe_ == 1)
    {
      return  (unsigned int) RawData_[j * m_Pitch + i * bpe_ + 0];
    }

    return 0x0000000;
  }

Here is the caller graph for this function:

void nux::ImageSurface::SwapBlocks ( void *  byte1,
void *  byte2,
int  size 
) [private]

Definition at line 695 of file ImageSurface.cpp.

  {
    unsigned char *tmp = new unsigned char[size];

    memcpy(tmp, byte1, size);
    memcpy(byte1, byte2, size);
    memcpy(byte2, tmp, size);

    delete [] tmp;
  }

Here is the caller graph for this function:

void nux::ImageSurface::Write ( int  i,
int  j,
unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)

Definition at line 478 of file ImageSurface.cpp.

  {
    nuxAssert(i < width_);
    nuxAssert(j < height_);
    nuxAssert(bpe_ == 4);

    if ((format_ == BITFMT_DXT1) || (format_ == BITFMT_DXT2)  || (format_ == BITFMT_DXT3)  || (format_ == BITFMT_DXT4) || (format_ == BITFMT_DXT5))
      return;

    if ((i < 0) || (i > width_))
      return;

    if ((j < 0) || (j > height_))
      return;

    if (bpe_ != 4)
      return;

    RawData_[j *m_Pitch + i *bpe_ + 0] = r;
    RawData_[j *m_Pitch + i *bpe_ + 1] = g;
    RawData_[j *m_Pitch + i *bpe_ + 2] = b;
    RawData_[j *m_Pitch + i *bpe_ + 3] = a;
  }

Here is the caller graph for this function:

void nux::ImageSurface::Write16b ( int  i,
int  j,
unsigned short  value 
)

Definition at line 453 of file ImageSurface.cpp.

  {
    nuxAssert(i < width_);
    nuxAssert(j < height_);
    nuxAssert(bpe_ >= 2);

    if ((format_ == BITFMT_DXT1) || (format_ == BITFMT_DXT2)  || (format_ == BITFMT_DXT3)  || (format_ == BITFMT_DXT4) || (format_ == BITFMT_DXT5))
      return;

    RawData_[j *m_Pitch + i *bpe_ + 0] = (unsigned char) (value & 0xff);
    RawData_[j *m_Pitch + i *bpe_ + 1] = (unsigned char) ((value & 0xff00) >> 8);
  }
void nux::ImageSurface::Write24b ( int  i,
int  j,
unsigned int  value 
)

Definition at line 439 of file ImageSurface.cpp.

  {
    nuxAssert(i < width_);
    nuxAssert(j < height_);
    nuxAssert(bpe_ >= 3);

    if ((format_ == BITFMT_DXT1) || (format_ == BITFMT_DXT2)  || (format_ == BITFMT_DXT3)  || (format_ == BITFMT_DXT4) || (format_ == BITFMT_DXT5))
      return;

    RawData_[j *m_Pitch + i *bpe_ + 0] = (unsigned char) (value & 0xff);
    RawData_[j *m_Pitch + i *bpe_ + 1] = (unsigned char) ((value & 0xff00) >> 8);
    RawData_[j *m_Pitch + i *bpe_ + 2] = (unsigned char) ((value & 0xff0000) >> 16);
  }
void nux::ImageSurface::Write32b ( int  i,
int  j,
unsigned int  value 
)

Definition at line 424 of file ImageSurface.cpp.

  {
    nuxAssert(i < width_);
    nuxAssert(j < height_);
    nuxAssert(bpe_ >= 4);

    if ((format_ == BITFMT_DXT1) || (format_ == BITFMT_DXT2)  || (format_ == BITFMT_DXT3)  || (format_ == BITFMT_DXT4) || (format_ == BITFMT_DXT5))
      return;

    RawData_[j *m_Pitch + i *bpe_ + 0] = (unsigned char) (value & 0xff);
    RawData_[j *m_Pitch + i *bpe_ + 1] = (unsigned char) ((value & 0xff00) >> 8);
    RawData_[j *m_Pitch + i *bpe_ + 2] = (unsigned char) ((value & 0xff0000) >> 16);
    RawData_[j *m_Pitch + i *bpe_ + 3] = (unsigned char) ((value & 0xff000000) >> 24);
  }

Here is the caller graph for this function:

void nux::ImageSurface::Write8b ( int  i,
int  j,
unsigned char  value 
)

Definition at line 466 of file ImageSurface.cpp.

  {
    nuxAssert(i < width_);
    nuxAssert(j < height_);
    nuxAssert(bpe_ >= 1);

    if ((format_ == BITFMT_DXT1) || (format_ == BITFMT_DXT2)  || (format_ == BITFMT_DXT3)  || (format_ == BITFMT_DXT4) || (format_ == BITFMT_DXT5))
      return;

    RawData_[j *m_Pitch + i *bpe_ + 0] = (unsigned char) (value & 0xff);
  }

Member Data Documentation

Data alignment.

Definition at line 168 of file ImageSurface.h.

int nux::ImageSurface::bpe_ [private]

Number of byte per element.

Definition at line 167 of file ImageSurface.h.

Image format.

Definition at line 165 of file ImageSurface.h.

Image height.

Definition at line 164 of file ImageSurface.h.

Image pitch.

Definition at line 166 of file ImageSurface.h.

unsigned char* nux::ImageSurface::RawData_ [private]

Definition at line 169 of file ImageSurface.h.

Image width.

Definition at line 163 of file ImageSurface.h.


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