00001 #ifndef SQUAREPIXELS_HEADER_
00002 #define SQUAREPIXELS_HEADER_
00003
00004 #include "../headers.h"
00005 #include "../fileUtil.h"
00006
00008
00011 class MSquarePixels: public IShapeTransformer {
00012 DECLARE_debugModule;
00013
00014 DECLARE_TypeInfo( MSquarePixels, "Square-pixel"
00015 , "Continues to work with square-shaped pixels, can divide the image"
00016 , {
00017 label: "Max. part size",
00018 desc: "The maximum number of pixels that can be in one part\n"
00019 "(parts are encoded separately, possibly in different threads)",
00020 type: settingInt(12,20,24,IntLog2)
00021 }, {
00022 label: "Range divider",
00023 desc: "The module that decides the way a single color-plane part"
00024 " is split into into Range blocks",
00025 type: settingModule<ISquareRanges>()
00026 }, {
00027 label: "Domain pool creator",
00028 desc: "The module that decides which block will be used for Domains",
00029 type: settingModule<ISquareDomains>()
00030 }, {
00031 label: "Encoder",
00032 desc: "The module that will find the best Domain-Range mappings",
00033 type: settingModule<ISquareEncoder>()
00034 } )
00035
00036 protected:
00038 enum Settings { MaxPartSize, ModuleRanges, ModuleDomains, ModuleEncoder };
00039
00040 int& maxPartSize()
00041 { return settingsInt(MaxPartSize); }
00042 ISquareRanges* moduleRanges()
00043 { return debugCast<ISquareRanges*>(settings[ModuleRanges].m); }
00044 ISquareDomains* moduleDomains()
00045 { return debugCast<ISquareDomains*>(settings[ModuleDomains].m); }
00046 ISquareEncoder* moduleEncoder()
00047 { return debugCast<ISquareEncoder*>(settings[ModuleEncoder].m); }
00048
00049 typedef IColorTransformer::Plane Plane;
00050 typedef MTypes::PlaneBlock PlaneBlock;
00051
00052 typedef std::vector<PlaneBlock>::iterator JobIterator;
00053
00054 protected:
00055
00056 std::vector<PlaneBlock> jobs;
00057 DEBUG_ONLY( PlaneList planeList; )
00058
00059 protected:
00060
00062 ~MSquarePixels() {
00063
00064 for (JobIterator it=jobs.begin(); it!=jobs.end(); ++it) {
00065 it->free(false);
00066 delete it->ranges;
00067 delete it->domains;
00068 delete it->encoder;
00069 }
00070 }
00071 public:
00074 int createJobs(const PlaneList &planes);
00075
00076 int jobCount() {
00077 return jobs.size();
00078 }
00079
00080 void jobEncode(int jobIndex) {
00081 ASSERT( jobIndex>=0 && jobIndex<jobCount() );
00082 PlaneBlock &job= jobs[jobIndex];
00083 job.encoder->initialize( IRoot::Encode, job );
00084 job.ranges->encode(job);
00085 }
00086 void jobDecodeAct( int jobIndex, DecodeAct action, int count=1 ) {
00087 ASSERT( jobIndex>=0 && jobIndex<jobCount() );
00088 jobs[jobIndex].encoder->decodeAct(action,count);
00089 }
00090
00091 void writeSettings(std::ostream &file);
00092 void readSettings(std::istream &file);
00093
00094 int phaseCount() {
00095 ASSERT( moduleRanges() && moduleDomains() && moduleEncoder() );
00096 return moduleEncoder()->phaseCount();
00097 }
00098 void writeJobs(std::ostream &file,int phaseBegin,int phaseEnd);
00099 void readJobs(std::istream &file,int phaseBegin,int phaseEnd);
00101 };
00102
00103 #endif // SQUAREPIXELS_HEADER_