00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <LdrFormatsLoader.h>
00022
00023 #define tr(s) QObject::tr(s)
00024
00025 Q_EXPORT_PLUGIN2(TT_OpenExrLoader, LdrFormatsLoaderFactory)
00026
00027
00037 QString LdrFormatsLoader::name() const
00038 {
00039 return tr("LDR Formats Loader");
00040 }
00041
00045 void LdrFormatsLoader::setFileName(const QString& f)
00046 {
00047 fileName = f;
00048 }
00049
00053 bool LdrFormatsLoader::openFile()
00054 {
00055 return image.load(fileName);
00056 }
00057
00061 QSize LdrFormatsLoader::getSize()
00062 {
00063 return image.size();
00064 }
00065
00069 Color* LdrFormatsLoader::getData()
00070 {
00071 QSize size = image.size();
00072 int width = size.width();
00073 int height = size.height();
00074
00075 float rgbToXyzMatrix [3][3] = {{0.5141364, 0.3238786, 0.16036376},
00076 {0.265068, 0.67023428, 0.06409157},
00077 {0.0241188, 0.1228178, 0.84442666}};
00078
00079 Color* data = new Color[width*height];
00080 float w;
00081 int ii, jj;
00082 for (int i=0; i<height; ++i)
00083 for (int j=0; j<width; ++j)
00084 {
00085 QRgb pixel = image.pixel(j,i);
00086 float rgb[3] = {float(qRed(pixel))/255.0,
00087 float(qGreen(pixel))/255.0,
00088 float(qBlue(pixel))/255.0};
00089 float xyz[3] = {0.0, 0.0, 0.0};
00090
00091 for (ii = 0; ii < 3; ++ii)
00092 for (jj = 0; jj < 3; ++jj)
00093 xyz[ii] += rgbToXyzMatrix[ii][jj] * rgb[jj];
00094
00095 if((w = xyz[0] + xyz[1] + xyz[2]) > 0.0)
00096 data[i*width + j] = Color(xyz[1],
00097 xyz[0]/w,
00098 xyz[1]/w);
00099 else
00100 data[i*width + j] = Color(0.0,0.0,0.0);
00101
00102 }
00103
00104 return data;
00105 }
00106
00110 HdrImage::ColorSpace LdrFormatsLoader::getColorSpace()
00111 {
00112 return HdrImage::Yxy;
00113 }
00114
00115
00116
00117
00118
00130 QStringList LdrFormatsLoaderFactory::extensions() const
00131 {
00132 return QStringList() << "bmp" << "gif" << "jpg" << "jpeg" << "png" << "tiff";
00133 }
00134
00138 ImageLoaderPtr LdrFormatsLoaderFactory::createLoader(const QString& fileName) const
00139 {
00140 ImageLoaderPtr loader(new LdrFormatsLoader);
00141 loader->setFileName(fileName);
00142 return loader;
00143 }
00144
00145