![]() |
Mixxx
|
00001 /*************************************************************************** 00002 imgsource.h - description 00003 ------------------- 00004 begin : 14 April 2007 00005 copyright : (C) 2007 by Adam Davison 00006 email : adamdavison@gmail.com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef IMGSOURCE_H 00019 #define IMGSOURCE_H 00020 00021 #include <qimage.h> 00022 #include <qcolor.h> 00023 #include <QDebug> 00024 00025 class ImgSource { 00026 public: 00027 virtual ~ImgSource() {}; 00028 virtual QImage* getImage(QString img) = 0; 00029 virtual inline QColor getCorrectColor(QColor c) { return c; } 00030 }; 00031 00032 class ImgProcessor : public ImgSource { 00033 00034 public: 00035 virtual ~ImgProcessor() {}; 00036 inline ImgProcessor(ImgSource* parent) : m_parent(parent) {} 00037 virtual QColor doColorCorrection(QColor c) = 0; 00038 inline QColor getCorrectColor(QColor c) { 00039 return doColorCorrection(m_parent->getCorrectColor(c)); 00040 } 00041 00042 protected: 00043 ImgSource* m_parent; 00044 }; 00045 00046 class ImgColorProcessor : public ImgProcessor { 00047 00048 public: 00049 virtual ~ImgColorProcessor() {}; 00050 00051 inline ImgColorProcessor(ImgSource* parent) : ImgProcessor(parent) {} 00052 inline virtual QImage* getImage(QString img) { 00053 QImage* i = m_parent->getImage(img); 00054 00055 if (i == NULL || i->isNull()) { 00056 return i; 00057 } 00058 00059 QColor col; 00060 00061 int bytesPerPixel = 4; 00062 00063 switch(i->format()) { 00064 case QImage::Format_Invalid: 00065 bytesPerPixel = 0; 00066 break; 00067 case QImage::Format_Mono: 00068 case QImage::Format_MonoLSB: 00069 case QImage::Format_Indexed8: 00070 bytesPerPixel = 1; 00071 break; 00072 00073 case QImage::Format_RGB16: 00074 case QImage::Format_RGB555: 00075 case QImage::Format_RGB444: 00076 case QImage::Format_ARGB4444_Premultiplied: 00077 bytesPerPixel = 2; 00078 break; 00079 00080 case QImage::Format_ARGB8565_Premultiplied: 00081 case QImage::Format_RGB666: 00082 case QImage::Format_ARGB6666_Premultiplied: 00083 case QImage::Format_ARGB8555_Premultiplied: 00084 case QImage::Format_RGB888: 00085 bytesPerPixel = 3; 00086 break; 00087 00088 case QImage::Format_ARGB32: 00089 case QImage::Format_ARGB32_Premultiplied: 00090 case QImage::Format_RGB32: 00091 default: 00092 bytesPerPixel = 4; 00093 break; 00094 } 00095 00096 //qDebug() << "ImgColorProcessor working on " 00097 // << img << " bpp: " 00098 // << bytesPerPixel << " format: " << i->format(); 00099 00100 if(bytesPerPixel < 4) { 00101 // Handling Indexed color or mono colors requires different logic 00102 qDebug() << "ImgColorProcessor aborting on unsupported color format:" 00103 << i->format(); 00104 return i; 00105 } 00106 00107 for(int y = 0; y < i->height(); y++) { 00108 QRgb *line = (QRgb*)i->scanLine(y); 00109 00110 if(line == NULL) { 00111 // Image is invalid. 00112 continue; 00113 } 00114 00115 for(int x = 0; x < i->width(); x++) { 00116 col.setRgb(*line); 00117 col = doColorCorrection(col); 00118 *line = col.rgb(); 00119 line++; 00120 } 00121 00122 } 00123 00124 return i; 00125 } 00126 }; 00127 00128 #endif 00129