00001
00036 #ifndef INC_SPATMOD_IMAGESAMPLEITERATOR_H
00037 #define INC_SPATMOD_IMAGESAMPLEITERATOR_H
00038
00039 #ifndef INC_SPATMOD_DATATYPE_H
00040 #include <spatmod/datatype.h>
00041 #endif
00042
00043 #ifndef INC_MI32_DELEGATE_H
00044 #include <mi32/delegate.h>
00045 #endif
00046
00047 namespace SPATMOD {
00048 namespace IMAGE {
00049
00050 class SAMPLEITERATOR;
00051
00052
00053
00055 class SAMPLEITERATOR_CONST {
00056 public:
00057
00059 SAMPLEITERATOR_CONST ();
00060
00062 SAMPLEITERATOR_CONST (
00063 void *pSample,
00064 DATATYPE DataType
00065 );
00066
00068 ~SAMPLEITERATOR_CONST ();
00069
00071 SAMPLEITERATOR_CONST& operator++ (
00072 ) { m_pSample += m_SampleBytes; return (*this); }
00073
00075 SAMPLEITERATOR_CONST& operator-- (
00076 ) { m_pSample -= m_SampleBytes; return (*this); }
00077
00079 SAMPLEITERATOR_CONST& operator+= (
00080 int num
00081 ) { m_pSample += m_SampleBytes * num; return (*this); }
00082
00084 SAMPLEITERATOR_CONST& operator-= (
00085 int num
00086 ) { m_pSample -= m_SampleBytes * num; return (*this); }
00087
00090 ERRVALUE Attach (
00091 void *pSample,
00092 DATATYPE DataType
00093 );
00094
00097 void Attach (
00098 void *pSample
00099 ) { m_pSample = static_cast<UINT8*>(pSample); }
00100
00102 bool GetBool (
00103 ) const { return (m_DelegateGetBool(m_pSample)); }
00104
00107 bool GetBool (
00108 int offset
00109 ) const { return (m_DelegateGetBool(m_pSample+offset*m_SampleBytes)); }
00110
00112 double GetDouble (
00113 ) const { return (m_DelegateGetDouble(m_pSample)); }
00114
00117 double GetDouble (
00118 int offset
00119 ) const { return (m_DelegateGetDouble(m_pSample+offset*m_SampleBytes)); }
00120
00122 void GetDoubles (
00123 double *values,
00124 int count
00125 ) const { m_DelegateGetDoubles(m_pSample,values,count); }
00126
00128 void GetDoubles (
00129 double *values,
00130 int count,
00131 int offset
00132 ) const { m_DelegateGetDoubles(m_pSample+offset*m_SampleBytes,values,count); }
00133
00135 INT32 GetINT32_Floor (
00136 ) const { return (static_cast<INT32>(m_DelegateGetUINT32_Floor(m_pSample))); }
00137
00140 INT32 GetINT32_Floor (
00141 int offset
00142 ) const { return (static_cast<INT32>(m_DelegateGetUINT32_Floor(m_pSample+offset*m_SampleBytes))); }
00143
00145 UINT32 GetUINT32_Floor (
00146 ) const { return (m_DelegateGetUINT32_Floor(m_pSample)); }
00147
00150 UINT32 GetUINT32_Floor (
00151 int offset
00152 ) const { return (m_DelegateGetUINT32_Floor(m_pSample+offset*m_SampleBytes)); }
00153
00155 const void *GetPtr (
00156 ) const { return (m_pSample); }
00157
00159 const void *GetPtr (
00160 int offset
00161 ) const { return (m_pSample+offset*m_SampleBytes); }
00162
00164 int GetSampleBytes (
00165 ) const { return (m_SampleBytes); }
00166
00167 private:
00168 #ifndef GENERATING_DOXYGEN_OUTPUT
00169 typedef FastDelegate<bool(const void*)> DELEGATE_GETBOOL;
00170 typedef FastDelegate<double(const void*)> DELEGATE_GETDOUBLE;
00171 typedef FastDelegate<void(const void*, double*, int)> DELEGATE_GETDOUBLES;
00172 typedef FastDelegate<UINT32(const void*)> DELEGATE_GETUINT32;
00173 typedef FastDelegate<void(void*, bool)> DELEGATE_PUTBOOL;
00174 typedef FastDelegate<void(void*, double)> DELEGATE_PUTDOUBLE;
00175 UINT8 *m_pSample;
00176 int m_SampleBytes;
00177 DELEGATE_GETBOOL m_DelegateGetBool;
00178 DELEGATE_GETDOUBLE m_DelegateGetDouble;
00179 DELEGATE_GETDOUBLES m_DelegateGetDoubles;
00180 DELEGATE_GETUINT32 m_DelegateGetUINT32_Floor;
00181 DELEGATE_PUTBOOL m_DelegatePutBool;
00182 DELEGATE_PUTDOUBLE m_DelegatePutDoubleFastRound;
00183 DELEGATE_PUTDOUBLE m_DelegatePutDoubleFastFloor;
00184 DELEGATE_PUTDOUBLE m_DelegatePutDoubleLimitRound;
00185 DELEGATE_PUTDOUBLE m_DelegatePutDoubleLimitFloor;
00186 friend class SAMPLEITERATOR;
00187 #endif // GENERATING_DOXYGEN_OUTPUT
00188 };
00189
00190
00191
00193 class SAMPLEITERATOR : public SAMPLEITERATOR_CONST {
00194 public:
00195
00197 SAMPLEITERATOR (
00198 ) { }
00199
00201 SAMPLEITERATOR (
00202 void *pSample,
00203 DATATYPE DataType
00204 ): SAMPLEITERATOR_CONST(pSample,DataType) { }
00205
00207 SAMPLEITERATOR& operator++ (
00208 ) { m_pSample += m_SampleBytes; return (*this); }
00209
00211 SAMPLEITERATOR& operator-- (
00212 ) { m_pSample -= m_SampleBytes; return (*this); }
00213
00215 void *GetPtr (
00216 ) const { return (m_pSample); }
00217
00219 void *GetPtr (
00220 int offset
00221 ) const { return (m_pSample+offset*m_SampleBytes); }
00222
00224 void PutBool (
00225 bool value
00226 ) const { m_DelegatePutBool(m_pSample,value); }
00227
00229 void PutValueFast (
00230 const void *pValue
00231 ) const { if (m_SampleBytes == 1) *m_pSample = *static_cast<const UINT8*>(pValue); else memcpy(m_pSample,pValue,m_SampleBytes); }
00232
00234 void PutValueFastRound (
00235 double value
00236 ) const { m_DelegatePutDoubleFastRound(m_pSample,value); }
00237
00239 void PutValueFastFloor (
00240 double value
00241 ) const { m_DelegatePutDoubleFastFloor(m_pSample,value); }
00242
00244 void PutValueLimitRound (
00245 double value
00246 ) const { m_DelegatePutDoubleLimitRound(m_pSample,value); }
00247
00249 void PutValueLimitFloor (
00250 double value
00251 ) const { m_DelegatePutDoubleLimitFloor(m_pSample,value); }
00252
00253 };
00254
00255
00256
00257 }
00258 }
00259
00260 #endif // INC_SPATMOD_IMAGESAMPLEITERATOR_H