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
00036 QStringList functionList() { return QStringList(_functions.keys()); }
00037 QPixmap colorImage(FractalInfo * info, QString function = "" );
00038 void addFunction(QString name, ColorFunction * function);
00039 };
00040
00041
00042
00049 class BWColor : public ColorFunction {
00050 virtual QPixmap colorImage(FractalInfo * info) {
00051 QImage image(info->imageSize(),QImage::Format_RGB32);
00052
00053 for( int i = 0; i < info->imageSize().width(); i++ ) {
00054 for( int j = 0; j < info->imageSize().height(); j++ ) {
00055 if( info->pixel(i,j) == 0 )
00056 image.setPixel(i,j,QColor(255,255,255).rgb());
00057 else
00058 image.setPixel(i,j,QColor(0,0,0).rgb());
00059 }
00060 }
00061
00062 return QPixmap::fromImage(image);
00063 }
00064 };
00065
00072 class GrayColor : public ColorFunction {
00073 virtual QPixmap colorImage(FractalInfo * info) {
00074 QImage image(info->imageSize(),QImage::Format_RGB32);
00075
00076 for( int i = 0; i < info->imageSize().width(); i++ ) {
00077 for( int j = 0; j < info->imageSize().height(); j++ ) {
00078 if( info->pixel(i,j) == 0 )
00079 image.setPixel(i,j,QColor(255,255,255).rgb());
00080 else {
00081 double tmp = info->pixel(i,j)/(double)info->max();
00082 tmp = 1-tmp;
00083 image.setPixel(i,j,QColor::fromRgbF(tmp,tmp,tmp).rgb());
00084 }
00085 }
00086 }
00087
00088 return QPixmap::fromImage(image);
00089 }
00090 };
00091
00098 class GrayV2Color : public ColorFunction {
00099 virtual QPixmap colorImage(FractalInfo * info) {
00100 uint inColor = QColor(255,255,255).rgb();
00101 QColor black(0,0,0);
00102
00103 QList<uint> colors;
00104 for( int i = 0; i < 50; i++) {
00105 double tmp = i/50.0;
00106 colors << QColor::fromRgbF(tmp,tmp,tmp).rgb();
00107 }
00108
00109 QImage image(info->imageSize(),QImage::Format_RGB32);
00110
00111 for( int i = 0; i < info->imageSize().width(); i++ ) {
00112 for( int j = 0; j < info->imageSize().height(); j++ ) {
00113 if( info->pixel(i,j) == 0 )
00114 image.setPixel(i,j,inColor);
00115 else
00116 image.setPixel(i,j,colors[ (info->pixel(i,j)-1) % colors.size()]);
00117 }
00118 }
00119
00120 return QPixmap::fromImage(image);
00121 }
00122 };
00123
00130 class GrayV2RevertColor : public ColorFunction {
00131 virtual QPixmap colorImage(FractalInfo * info) {
00132 uint inColor = QColor(255,255,255).rgb();
00133 QColor black(0,0,0);
00134
00135 QList<uint> colors;
00136 for( int i = 0; i < 50; i++) {
00137 double tmp = 1.0 - i/50.0;
00138 colors << QColor::fromRgbF(tmp,tmp,tmp).rgb();
00139 }
00140
00141 QImage image(info->imageSize(),QImage::Format_RGB32);
00142
00143 for( int i = 0; i < info->imageSize().width(); i++ ) {
00144 for( int j = 0; j < info->imageSize().height(); j++ ) {
00145 if( info->pixel(i,j) == 0 )
00146 image.setPixel(i,j,inColor);
00147 else
00148 image.setPixel(i,j,colors[ (info->pixel(i,j)-1) % colors.size()]);
00149 }
00150 }
00151
00152 return QPixmap::fromImage(image);
00153 }
00154 };
00155
00162 class ManyColor : public ColorFunction {
00163 virtual QPixmap colorImage(FractalInfo * info) {
00164 QColor black(0,0,0);
00165
00166 QList<QColor> colors;
00167 colors << Qt::red << Qt::darkRed <<Qt::green <<Qt::darkGreen
00168 <<Qt::blue <<Qt::darkBlue <<Qt::cyan <<Qt::darkCyan
00169 <<Qt::magenta <<Qt::darkMagenta <<Qt::yellow <<Qt::darkYellow;
00170
00171 QImage image(info->imageSize(),QImage::Format_RGB32);
00172
00173 for( int i = 0; i < info->imageSize().width(); i++ ) {
00174 for( int j = 0; j < info->imageSize().height(); j++ ) {
00175 if( info->pixel(i,j) == 0 )
00176 image.setPixel(i,j,black.rgb());
00177 else
00178 image.setPixel(i,j,colors[ (info->pixel(i,j)-1) % colors.size()].rgb());
00179 }
00180 }
00181
00182 return QPixmap::fromImage(image);
00183 }
00184 };
00185
00192 class ManyV2Color : public ColorFunction {
00193 virtual QPixmap colorImage(FractalInfo * info) {
00194 QColor black(0,0,0);
00195
00196 QList<uint> red;
00197 QList<uint> green;
00198 QList<uint> blue;
00199 for( int i = 0; i < 50; i++) {
00200 double tmp = i/50.0;
00201 red << QColor::fromRgbF(tmp,0.,0.).rgb();
00202 green << QColor::fromRgbF(0.,tmp,0.).rgb();
00203 blue << QColor::fromRgbF(0.,0.,tmp).rgb();
00204 }
00205
00206 QList<uint> colors;
00207 colors << blue << green << red;
00208
00209 QImage image(info->imageSize(),QImage::Format_RGB32);
00210
00211 for( int i = 0; i < info->imageSize().width(); i++ ) {
00212 for( int j = 0; j < info->imageSize().height(); j++ ) {
00213 if( info->pixel(i,j) == 0 )
00214 image.setPixel(i,j,black.rgb());
00215 else
00216 image.setPixel(i,j,colors[ (info->pixel(i,j)-1) % colors.size()]);
00217 }
00218 }
00219
00220 return QPixmap::fromImage(image);
00221 }
00222 };
00223
00224 #endif // COLORATOR_H