00001 #ifndef COLORATOR_H
00002 #define COLORATOR_H
00003
00004 #include <QObject>
00005 #include <QImage>
00006 #include <QPixmap>
00007
00008 #include "fractalinfo.h"
00009
00014 class ColorFunction {
00015 public:
00016 virtual QPixmap colorImage(FractalInfo * info) = 0;
00017 };
00018
00027 class Colorator : public QObject
00028 {
00029 QHash<QString, ColorFunction*> _functions;
00030 QString _default;
00031
00032 public:
00033 explicit Colorator(QObject *parent = 0);
00034 virtual ~Colorator();
00035
00037 QStringList functionList() { return QStringList(_functions.keys()); }
00039 QPixmap colorImage(FractalInfo * info, QString function = "" );
00041 void addFunction(QString name, ColorFunction * function);
00042 };
00043
00044
00045
00052 class BWColor : public ColorFunction {
00053 virtual QPixmap colorImage(FractalInfo * info) {
00054 QImage image(info->imageSize(),QImage::Format_RGB32);
00055
00056 for( int i = 0; i < info->imageSize().width(); i++ ) {
00057 for( int j = 0; j < info->imageSize().height(); j++ ) {
00058 if( info->pixel(i,j) == 0 )
00059 image.setPixel(i,j,QColor(255,255,255).rgb());
00060 else
00061 image.setPixel(i,j,QColor(0,0,0).rgb());
00062 }
00063 }
00064
00065 return QPixmap::fromImage(image);
00066 }
00067 };
00068
00075 class GrayColor : public ColorFunction {
00076 virtual QPixmap colorImage(FractalInfo * info) {
00077 QImage image(info->imageSize(),QImage::Format_RGB32);
00078
00079 for( int i = 0; i < info->imageSize().width(); i++ ) {
00080 for( int j = 0; j < info->imageSize().height(); j++ ) {
00081 if( info->pixel(i,j) == 0 )
00082 image.setPixel(i,j,QColor(255,255,255).rgb());
00083 else {
00084 double tmp = info->pixel(i,j)/(double)info->max();
00085 tmp = 1-tmp;
00086 image.setPixel(i,j,QColor::fromRgbF(tmp,tmp,tmp).rgb());
00087 }
00088 }
00089 }
00090
00091 return QPixmap::fromImage(image);
00092 }
00093 };
00094
00101 class GrayV2Color : public ColorFunction {
00102 virtual QPixmap colorImage(FractalInfo * info) {
00103 uint inColor = QColor(255,255,255).rgb();
00104 QColor black(0,0,0);
00105
00106 QList<uint> colors;
00107 for( int i = 0; i < 50; i++) {
00108 double tmp = i/50.0;
00109 colors << QColor::fromRgbF(tmp,tmp,tmp).rgb();
00110 }
00111
00112 QImage image(info->imageSize(),QImage::Format_RGB32);
00113
00114 for( int i = 0; i < info->imageSize().width(); i++ ) {
00115 for( int j = 0; j < info->imageSize().height(); j++ ) {
00116 if( info->pixel(i,j) == 0 )
00117 image.setPixel(i,j,inColor);
00118 else
00119 image.setPixel(i,j,colors[ (info->pixel(i,j)-1) % colors.size()]);
00120 }
00121 }
00122
00123 return QPixmap::fromImage(image);
00124 }
00125 };
00126
00133 class GrayV2RevertColor : public ColorFunction {
00134 virtual QPixmap colorImage(FractalInfo * info) {
00135 uint inColor = QColor(255,255,255).rgb();
00136 QColor black(0,0,0);
00137
00138 QList<uint> colors;
00139 for( int i = 0; i < 50; i++) {
00140 double tmp = 1.0 - i/50.0;
00141 colors << QColor::fromRgbF(tmp,tmp,tmp).rgb();
00142 }
00143
00144 QImage image(info->imageSize(),QImage::Format_RGB32);
00145
00146 for( int i = 0; i < info->imageSize().width(); i++ ) {
00147 for( int j = 0; j < info->imageSize().height(); j++ ) {
00148 if( info->pixel(i,j) == 0 )
00149 image.setPixel(i,j,inColor);
00150 else
00151 image.setPixel(i,j,colors[ (info->pixel(i,j)-1) % colors.size()]);
00152 }
00153 }
00154
00155 return QPixmap::fromImage(image);
00156 }
00157 };
00158
00165 class ManyColor : public ColorFunction {
00166 virtual QPixmap colorImage(FractalInfo * info) {
00167 QColor black(0,0,0);
00168
00169 QList<QColor> colors;
00170 colors << Qt::red << Qt::darkRed <<Qt::green <<Qt::darkGreen
00171 <<Qt::blue <<Qt::darkBlue <<Qt::cyan <<Qt::darkCyan
00172 <<Qt::magenta <<Qt::darkMagenta <<Qt::yellow <<Qt::darkYellow;
00173
00174 QImage image(info->imageSize(),QImage::Format_RGB32);
00175
00176 for( int i = 0; i < info->imageSize().width(); i++ ) {
00177 for( int j = 0; j < info->imageSize().height(); j++ ) {
00178 if( info->pixel(i,j) == 0 )
00179 image.setPixel(i,j,black.rgb());
00180 else
00181 image.setPixel(i,j,colors[ (info->pixel(i,j)-1) % colors.size()].rgb());
00182 }
00183 }
00184
00185 return QPixmap::fromImage(image);
00186 }
00187 };
00188
00195 class ManyV2Color : public ColorFunction {
00196 virtual QPixmap colorImage(FractalInfo * info) {
00197 QColor black(0,0,0);
00198
00199 QList<uint> red;
00200 QList<uint> green;
00201 QList<uint> blue;
00202 for( int i = 0; i < 50; i++) {
00203 double tmp = i/50.0;
00204 red << QColor::fromRgbF(tmp,0.,0.).rgb();
00205 green << QColor::fromRgbF(0.,tmp,0.).rgb();
00206 blue << QColor::fromRgbF(0.,0.,tmp).rgb();
00207 }
00208
00209 QList<uint> colors;
00210 colors << blue << green << red;
00211
00212 QImage image(info->imageSize(),QImage::Format_RGB32);
00213
00214 for( int i = 0; i < info->imageSize().width(); i++ ) {
00215 for( int j = 0; j < info->imageSize().height(); j++ ) {
00216 if( info->pixel(i,j) == 0 )
00217 image.setPixel(i,j,black.rgb());
00218 else
00219 image.setPixel(i,j,colors[ (info->pixel(i,j)-1) % colors.size()]);
00220 }
00221 }
00222
00223 return QPixmap::fromImage(image);
00224 }
00225 };
00226
00227 #endif // COLORATOR_H