00001 #ifndef STDENCODER_HEADER_
00002 #define STDENCODER_HEADER_
00003
00004 #include "../headers.h"
00005
00007
00022 class MStdEncoder: public ISquareEncoder {
00023 DECLARE_debugModule;
00024 public:
00025 static const float MaxLinCoeff_none= 0;
00026
00027 DECLARE_TypeInfo( MStdEncoder, "Standard encoder"
00028 , "Classic encoder supporting one-domain to one-range mappings"
00029 , {
00030 label: "Best-match predictor",
00031 desc: "Module that chooses which domain blocks\n"
00032 "should be tried for a range block",
00033 type: settingModule<IStdEncPredictor>()
00034 }, {
00035 label: "Rotations and symmetries",
00036 desc: "Can the projections include rotations and symmetries?",
00037 type: settingCombo("identity only\nclassic 8",1)
00038 }, {
00039 label: "Color value inversion",
00040 desc: "Can the projections have negative linear coefficients?",
00041 type: settingCombo("not allowed\nallowed",1)
00042 }, {
00043 label: "Coefficient of big-scale penalization",
00044 desc: "How much will big linear coefficients in color-value\n"
00045 "projections be penalized? (select zero to disable it)",
00046 type: settingFloat(0,0.25,4)
00047 }, {
00048 label: "Take quantization errors into account",
00049 desc: "Selecting yes will result in slower but more precise encoding",
00050 type: settingCombo("no\nyes",1)
00051 }, {
00052 label: "Maximum linear coefficient",
00053 desc: "The maximum absolute value of linear coefficients",
00054 type: settingFloat(MaxLinCoeff_none,MaxLinCoeff_none,5.0)
00055 }, {
00056 label: "Sufficient quotient of SE",
00057 desc: "After reaching this quotient of square error,\n"
00058 "no other domain blocks will be tried",
00059 type: settingFloat( 0, 0.05, 1 )
00060 }, {
00061 label: "Quantization steps for average",
00062 desc: "The number (a power of two) of possible range block\n"
00063 "average color values (real average will be rounded)",
00064 type: settingInt(2,7,10,IntLog2)
00065 }, {
00066 label: "Quantization steps for deviation",
00067 desc: "The number (a power of two) of possible range block\n"
00068 "standard color value deviations",
00069 type: settingInt(2,6,10,IntLog2)
00070 }, {
00071 label: "The codec for averages",
00072 desc: "The module that will code and decode\n"
00073 "average color values of range blocks",
00074 type: settingModule<IIntCodec>()
00075 }, {
00076 label: "The codec for deviations",
00077 desc: "The module that will code and decode standard\n"
00078 "deviations of color values of range blocks",
00079 type: settingModule<IIntCodec>()
00080 } )
00081
00082 protected:
00084 enum Settings { ModulePredictor, AllowedRotations, AllowedInversion, BigScaleCoeff
00085 , AllowedQuantError, MaxLinCoeff, SufficientSEq, QuantStepLog_avg, QuantStepLog_dev
00086 , ModuleCodecAvg, ModuleCodecDev };
00087
00088 float settingsFloat(Settings index)
00089 { return settings[index].val.f; }
00090 IStdEncPredictor* modulePredictor()
00091 { return debugCast<IStdEncPredictor*>(settings[ModulePredictor].m); }
00092 IIntCodec* moduleCodec(bool forAverage) {
00093 return debugCast<IIntCodec*>
00094 ( settings[ forAverage ? ModuleCodecAvg : ModuleCodecDev ].m );
00095 }
00096
00098 struct EncodingInfo;
00099
00100 public:
00101 typedef LevelPoolInfos ::value_type PoolInfos;
00102 typedef ISquareRanges ::RangeList RangeList;
00103 typedef ISquareDomains ::Pool Pool;
00104 typedef IStdEncPredictor::Prediction Prediction;
00105
00106 public:
00108 struct RangeInfo: public RangeNode::EncoderData, public Prediction {
00109 struct {
00110 Block domBlock;
00111 const Pool *pool;
00112 } decAccel;
00113
00114 Real qrAvg
00115 , qrDev2;
00116 bool inverted;
00117
00118 #ifndef NDEBUG
00119 struct {
00120 Real avg, dev2, constCoeff, linCoeff;
00121 } exact;
00122 #endif
00123
00125 static RangeInfo* get(RangeNode *range) {
00126 RangeInfo *result= static_cast<RangeInfo*>(range->encoderData);
00127 ASSERT(result);
00128 return result;
00129 }
00130 static const RangeInfo* get(const RangeNode *range)
00131 { return get(constCast(range)); }
00132 };
00133
00134 protected:
00135
00136 PlaneBlock *planeBlock;
00137 std::vector<float> stdRangeSEs;
00138 LevelPoolInfos levelPoolInfos;
00139
00140 protected:
00141
00143 MStdEncoder(): planeBlock(0) {}
00144
00145 public:
00148 void initialize( IRoot::Mode mode, PlaneBlock &planeBlock_ );
00149 float findBestSE(const RangeNode &range,bool allowHigherSE);
00150 void finishEncoding() {
00151 initRangeInfoAccelerators();
00152 modulePredictor()->cleanUp();
00153 }
00154 void decodeAct( DecodeAct action, int count=1 );
00155
00156 void writeSettings(std::ostream &file);
00157 void readSettings(std::istream &file);
00158
00159 int phaseCount() const
00160 { return 3; }
00161 void writeData(std::ostream &file,int phase);
00162 void readData(std::istream &file,int phase);
00164 protected:
00166 void buildPoolInfos4aLevel(int level);
00168 void initRangeInfoAccelerators();
00169
00172 static const Pool& getDomainData
00173 ( const RangeNode &rangeBlock, const ISquareDomains::PoolList &pools
00174 , const PoolInfos &poolInfos, int domIndex, int zoom, Block &block );
00175
00177 static PoolInfos::const_iterator getPoolFromDomID( int domID, const PoolInfos &poolInfos );
00178 };
00179
00180 #endif // STDENCODER_HEADER_