00001 #include "colorModel.h"
00002 #include "../imageUtil.h"
00003
00004 #include <QImage>
00005
00006 using namespace std;
00007 using namespace Color;
00008
00009 MColorModel::PlaneList MColorModel
00010 ::image2planes( const QImage &image, const PlaneSettings &prototype ) {
00011 ASSERT( !image.isNull() && ownedPlanes.empty() );
00012
00013 int width= image.width(), height= image.height();
00014 ownedPlanes= createPlanes(IRoot::Encode,prototype);
00015
00016 const Real (*coeffs)[4]= ( settingsInt(ColorModel) ? YCbCrCoeffs : RGBCoeffs);
00017 int planeCount= ownedPlanes.size();
00018
00019 for (int i=0; i<planeCount; ++i) {
00020 SMatrix pixels= ownedPlanes[i].pixels;
00021
00022 for (int y=0; y<height; ++y) {
00023
00024 const QRgb *line= (QRgb*)image.scanLine(y);
00025 for (int x=0; x<width; ++x)
00026 pixels[x][y]= getColor(line[x],coeffs[i]);
00027 }
00028 }
00029 return ownedPlanes;
00030 }
00031
00032 QImage MColorModel::planes2image() {
00033 ASSERT( settingsInt(ColorModel)>=0 && settingsInt(ColorModel)<numOfModels()
00034 && ownedPlanes.size()==3 );
00035
00036 const Real (*coeffs)[4]= 3 + (settingsInt(ColorModel) ? YCbCrCoeffs : RGBCoeffs);
00037
00038 const PlaneSettings &firstSet= *ownedPlanes.front().settings;
00039 QImage result( firstSet.width, firstSet.height, QImage::Format_RGB32 );
00040
00041 for (int y=0; y<firstSet.height; ++y) {
00042 QRgb *line= (QRgb*)result.scanLine(y);
00043 for (int x=0; x<firstSet.width; ++x) {
00044 Real vals[3]= {
00045 ownedPlanes[0].pixels[x][y],
00046 ownedPlanes[1].pixels[x][y],
00047 ownedPlanes[2].pixels[x][y]
00048 };
00049 line[x]= getColor( coeffs, vals );
00050 }
00051 }
00052 return result;
00053 }
00054
00055 MColorModel::PlaneList MColorModel
00056 ::readData( istream &file, const PlaneSettings &prototype ) {
00057 ASSERT( ownedPlanes.empty() );
00058
00059 settingsInt(ColorModel)= get<Uchar>(file);
00060 checkThrow( 0<=settingsInt(ColorModel) && settingsInt(ColorModel)<numOfModels() );
00061 return ownedPlanes= createPlanes( IRoot::Decode, prototype );
00062 }
00063
00064 MColorModel::PlaneList MColorModel
00065 ::createPlanes( IRoot::Mode DEBUG_ONLY(mode), const PlaneSettings &prototype ) {
00066 ASSERT( 0<=settingsInt(ColorModel) && settingsInt(ColorModel)<numOfModels()
00067 && mode!=IRoot::Clear );
00068
00069 int planeCount= 3;
00070 (*prototype.updateInfo.incMaxProgress)( planeCount*prototype.width*prototype.height );
00071
00072 PlaneList result(planeCount);
00073 for (int i=0; i<planeCount; ++i) {
00074 result[i].pixels.allocate( prototype.width, prototype.height );
00075 PlaneSettings *newSet= new PlaneSettings(prototype);
00076 newSet->quality*= qualityMul(i);
00077 result[i].settings= newSet;
00078 }
00079 return result;
00080 }