RgbaImage.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   RgbaImage.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @date   January 2008
00005    
00006    @brief
00007      Image class supporting a standard 32-bit Rgba pixel format
00008    <!-------------------------------------------------------------------->**/
00009 
00010 #include "RgbaImage.h"
00011 #include "HDRImage.h"
00012 #include <QImage>
00013 
00014 RgbaImage::RgbaImage(QImage &image)
00015    : Image(image.width(), image.height()), m_ownData(false)
00016 {
00017    if (image.format() != QImage::Format_RGB32)
00018       image = image.convertToFormat(QImage::Format_RGB32);
00019    
00020    m_data = (Rgba32 *)image.bits();
00021    
00022 #if 0
00023    QRgb *qrgb = (QRgb *)image.bits();
00024    m_data     = new Rgba32[m_size];
00025    
00026    // convert from ARGB to RGBA 
00027    for(unsigned i = m_size; i--;) {
00028       const QRgb &argb = qrgb[i];
00029       
00030       m_data[i] = Rgba32(qRed(argb), qGreen(argb), qBlue(argb));
00031    }
00032 #endif
00033 }
00034 
00035 RgbaImage::~RgbaImage() {
00036    if (m_ownData)
00037       safeDeleteArray(m_data);
00038 }
00039 
00040 bool RgbaImage::isHDR() const {
00041    return false;
00042 }
00043 
00044 real_t RgbaImage::getLuminance(unsigned row, unsigned col) const {
00045    ASSERT(row < m_height && col < m_width);
00046    
00047    return m_data[row * m_width + col].luminance();
00048 }
00049 
00050 Rgba32 RgbaImage::_getPixelRgba32 (unsigned row, unsigned col) const {
00051    return m_data[row * m_width + col];
00052 }
00053 
00054 RgbaHDR RgbaImage::_getPixelRgbaHDR(unsigned row, unsigned col) const {
00055    return static_cast<RgbaHDR>(m_data[row * m_width + col]);
00056 }
00057 
00058 void RgbaImage::_setPixel(unsigned row, unsigned col, const Rgba32  &val) {
00059    m_data[row * m_width + col] = val;
00060 }
00061 
00062 void RgbaImage::_setPixel(unsigned row, unsigned col, const RgbaHDR &val) {
00063    m_data[row * m_width + col] = static_cast<Rgba32>(val);
00064 }
00065 
00066 void RgbaImage::setSize(unsigned width, unsigned height) {
00067    if (m_width != width || m_height != height) {
00068       m_size   = width * height;
00069       m_width  = width;
00070       m_height = height;
00071       
00072       if (m_ownData) {
00073          Rgba32 *data = m_data;
00074          m_data = new Rgba32[m_size];
00075          
00076          safeDeleteArray(data);
00077       }
00078    }
00079 }
00080 
00081 void RgbaImage::_setData(const Rgba32 *data) {
00082    ASSERT(m_data);
00083    ASSERT(data);
00084    
00085    memcpy(m_data, data, sizeof(Rgba32) * m_size);
00086 }
00087 
00088 void RgbaImage::_setData(const RgbaHDR *data) {
00089    ASSERT(m_data);
00090    ASSERT(data);
00091    
00092    for(unsigned i = m_height; i--;)
00093       for(unsigned j = m_width; j--;)
00094          _setPixel(i, j, data[i * m_width + j]);
00095 }
00096 
00097 Image *RgbaImage::clone() const {
00098    RgbaImage *image = new RgbaImage(m_width, m_height);
00099    
00100    image->setData(m_data);
00101    return image;
00102 }
00103 
00104 void RgbaImage::copyData(const Image *image) {
00105    ASSERT(image);
00106    
00107    if (image->isHDR()) {
00108       const HDRImage  *in = (const HDRImage  *)image;
00109       
00110       _setData(in->getData());
00111    } else {
00112       const RgbaImage *in = (const RgbaImage *)image;
00113       
00114       _setData(in->getData());
00115    }
00116 }
00117 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6