HDRImage.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   HDRImage.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @date   January 2008
00005    
00006    @brief
00007      HDR image class supporting a 128- or 256-bit RgbaHDR pixel format
00008    <!-------------------------------------------------------------------->**/
00009 
00010 #include "HDRImage.h"
00011 #include "RgbaImage.h"
00012 
00013 HDRImage::~HDRImage() {
00014    safeDeleteArray(m_data);
00015 }
00016 
00017 bool HDRImage::isHDR() const {
00018    return true;
00019 }
00020 
00021 real_t HDRImage::getLuminance(unsigned row, unsigned col) const {
00022    ASSERT(row < m_height && col < m_width);
00023    
00024    return m_data[row * m_width + col].luminance();
00025 }
00026 
00027 Rgba32 HDRImage::_getPixelRgba32 (unsigned row, unsigned col) const {
00028    return static_cast<Rgba32>(m_data[row * m_width + col]);
00029 }
00030 
00031 RgbaHDR HDRImage::_getPixelRgbaHDR(unsigned row, unsigned col) const {
00032    return m_data[row * m_width + col];
00033 }
00034 
00035 void HDRImage::_setPixel(unsigned row, unsigned col, const Rgba32  &val) {
00036    m_data[row * m_width + col] = static_cast<RgbaHDR>(val);
00037 }
00038 
00039 void HDRImage::_setPixel(unsigned row, unsigned col, const RgbaHDR &val) {
00040    m_data[row * m_width + col] = val;
00041 }
00042 
00043 void HDRImage::setSize(unsigned width, unsigned height) {
00044    if (m_width != width || m_height != height) {
00045       m_size   = width * height;
00046       m_width  = width;
00047       m_height = height;
00048       
00049       RgbaHDR *data = m_data;
00050       m_data = new RgbaHDR[m_size];
00051       
00052       safeDeleteArray(data);
00053    }
00054 }
00055 
00056 void HDRImage::_setData(const Rgba32 *data) {
00057    ASSERT(m_data);
00058    ASSERT(data);
00059    
00060    for(unsigned i = m_height; i--;)
00061       for(unsigned j = m_width; j--;)
00062          _setPixel(i, j, data[i * m_width + j]);
00063 }
00064 
00065 void HDRImage::_setData(const RgbaHDR *data) {
00066    ASSERT(m_data);
00067    ASSERT(data);
00068    
00069    memcpy(m_data, data, sizeof(Rgba32) * m_size);
00070 }
00071 
00072 Image *HDRImage::clone() const {
00073    HDRImage *image = new HDRImage(m_width, m_height);
00074    
00075    image->setData(m_data);
00076    return image;
00077 }
00078 
00079 void HDRImage::copyData(const Image *image) {
00080    ASSERT(image);
00081    
00082    if (image->isHDR()) {
00083       const HDRImage  *in = (const HDRImage  *)image;
00084       
00085       _setData(in->getData());
00086    } else {
00087       const RgbaImage *in = (const RgbaImage *)image;
00088       
00089       _setData(in->getData());
00090    }
00091 }
00092 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6