00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef _CBMAGINFO_H_
00044 #define _CBMAGINFO_H_
00045
00046 #include <stdio.h>
00047
00048
00049
00050
00051 #define CBRGBTOGREY(r,g,b) ((CATUInt8)( 0.3f*(r) + 0.59f*(g) + 0.11f*(b)))
00052
00053 const int kCBMagMaxNameLength = 127;
00054 const int kCBMagNameBufferSize = kCBMagMaxNameLength + 1;
00055
00056
00057 const int kCBMagVersion = 1;
00058
00059 enum CBMAGRESULT
00060 {
00061
00062 CBMAG_SUCCESS = 0,
00063
00064
00065 CBMAG_STAT_NEW_VERSION,
00066 CBMAG_STAT_ENDIAN_FLIPPED,
00067
00068
00069 CBMAG_ERROR = 0x80000000,
00070 CBMAG_ERR_INVALID_PARAMETER,
00071 CBMAG_ERR_PARAMETER_OUT_OF_RANGE,
00072 CBMAG_ERR_FILE_CREATE,
00073 CBMAG_ERR_FILE_OPEN,
00074 CBMAG_ERR_FILE_READ_FAIL,
00075 CBMAG_ERR_FILE_WRITE_FAIL,
00076 CBMAG_ERR_FILE_CORRUPT,
00077 CBMAG_ERR_OUT_OF_MEMORY,
00078 CBMAG_ERR_BUF_TOO_SMALL,
00079 };
00080
00081
00082
00083
00084
00085
00086
00087 #define CBMAGSUCCESS(x) ( ( (x) & 0x80000000 ) == 0 )
00088 #define CBMAGFAILED(x) ( ( (x) & 0x80000000 ) != 0 )
00089
00090
00091 #ifndef CBMAX
00092 #define CBMAX(a,b) (((a) > (b)) ? (a) : (b))
00093 #endif
00094
00095 #ifndef CBMIN
00096 #define CBMIN(a,b) (((a) < (b)) ? (a) : (b))
00097 #endif
00098
00099
00100
00101
00102
00103
00104
00105 #pragma pack(push)
00106 #pragma pack(1)
00107
00108 struct CBMAGINFOSTRUCT
00109 {
00110 union
00111 {
00112 char fCBMagSig[4];
00113 int fCBMagSigInt;
00114 };
00115
00116 int fVersion;
00117 char fInfoName[kCBMagNameBufferSize];
00118
00119
00120
00121
00122 int fAllowFeedback;
00123
00124 int fRefresh;
00125 int fOnTop;
00126 float fMagnificationLevel;
00127 float fFilterMouse;
00128
00129 int fNegative;
00130
00131
00132
00133
00134
00135
00136 float fGamma;
00137
00138 float fBright_Red;
00139 float fBright_Green;
00140 float fBright_Blue;
00141
00142
00143 float fGreyRed;
00144 float fGreyGreen;
00145 float fGreyBlue;
00146 float fGreyYellow;
00147 float fGreyCyan;
00148 float fGreyMagenta;
00149
00150 float fHue;
00151 float fHueCompress;
00152
00153 int fSwapType;
00154 int fMergeType;
00155
00156 float fSeverity;
00157 int fReserved [31];
00158 int fThirdParty[32];
00159 };
00160
00161 #pragma pack(pop)
00162
00163
00164
00165
00166 class CBMagInfo
00167 {
00168
00169 public:
00170
00171 enum SWAPTYPE
00172 {
00173 SWAP_NONE,
00174 SWAP_GREEN_BLUE,
00175 SWAP_RED_BLUE,
00176 SWAP_RED_GREEN,
00177 SWAP_LAST_TYPE = SWAP_RED_GREEN,
00178 };
00179
00180 enum MERGETYPE
00181 {
00182 MERGE_NONE,
00183 MERGE_Red,
00184 MERGE_Blue,
00185 MERGE_ALL,
00186 MERGE_Green,
00187 MERGE_LAST_TYPE = MERGE_Green
00188 };
00189
00190
00191 public:
00192
00193
00194
00195
00196
00197
00198
00199 CBMagInfo();
00200 CBMagInfo( const CBMAGINFOSTRUCT& copyStruct);
00201 CBMagInfo( const CBMagInfo& copyInfo );
00202
00203
00204 virtual ~CBMagInfo();
00205
00206
00207 CBMagInfo& operator= (const CBMAGINFOSTRUCT& copyStruct);
00208 CBMagInfo& operator= (const CBMagInfo& copyInfo);
00209
00210
00211 CBMAGRESULT LoadFromFile (const char* filename);
00212 CBMAGRESULT LoadFromHandle (FILE* fp);
00213
00214
00215 CBMAGRESULT SaveToFile (const char* filename);
00216 CBMAGRESULT SaveToHandle (FILE* fp);
00217
00218 void Reset();
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 void ProcessImage ( unsigned char* rgbBuffer,
00238 int imgWidth,
00239 int imgHeight,
00240 int xOff,
00241 int yOff,
00242 int procWidth,
00243 int procHeight);
00244
00245
00246
00247
00248 CBMAGRESULT SetName (const char* name );
00249 CBMAGRESULT SetFeedback (bool allow );
00250 CBMAGRESULT SetRefresh (int refresh );
00251 CBMAGRESULT SetOnTop (bool onTop );
00252 CBMAGRESULT SetMagLevel (float magLvl );
00253 CBMAGRESULT SetFilterMouse (float coefficient );
00254 CBMAGRESULT SetNegative (bool negative );
00255 CBMAGRESULT SetGamma (float gamma );
00256 CBMAGRESULT SetBrightRed (float brightRed );
00257 CBMAGRESULT SetBrightGreen (float brightGreen );
00258 CBMAGRESULT SetBrightBlue (float brightBlue );
00259 CBMAGRESULT SetHue (float hue );
00260 CBMAGRESULT SetSeverity (float severity );
00261 CBMAGRESULT SetGreyRed (float greyRed );
00262 CBMAGRESULT SetGreyGreen (float greyGreen );
00263 CBMAGRESULT SetGreyBlue (float greyBlue );
00264 CBMAGRESULT SetGreyYellow (float greyYellow );
00265 CBMAGRESULT SetGreyCyan (float greyCyan );
00266 CBMAGRESULT SetGreyMagenta (float greyMagenta );
00267 CBMAGRESULT SetCompress (float compress );
00268 CBMAGRESULT SetSwapType (SWAPTYPE swapType );
00269 CBMAGRESULT SetMergeType (MERGETYPE mergeType );
00270
00271
00272
00273
00274 CBMAGRESULT GetName (char* nameBuffer,
00275 int& bufLen) const;
00276
00277 int GetRefresh () const;
00278 bool GetFeedback () const;
00279 bool GetOnTop () const;
00280 bool GetNegative () const;
00281 float GetMagLevel () const;
00282 float GetFilterMouse () const;
00283 float GetGamma () const;
00284 float GetBrightRed () const;
00285 float GetBrightGreen () const;
00286 float GetBrightBlue () const;
00287 float GetHue () const;
00288 float GetSeverity () const;
00289 float GetGreyRed () const;
00290 float GetGreyGreen () const;
00291 float GetGreyBlue () const;
00292 float GetGreyYellow () const;
00293 float GetGreyCyan () const;
00294 float GetGreyMagenta () const;
00295 float GetCompress () const;
00296 SWAPTYPE GetSwapType () const;
00297 MERGETYPE GetMergeType () const;
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 void BuildLookupTables();
00309
00310 void BuildGamma(bool buildRed,
00311 bool buildGreen,
00312 bool buildBlue);
00313
00314 void BuildGreys(bool buildRed,
00315 bool buildYellow,
00316 bool buildGreen,
00317 bool buildCyan,
00318 bool buildBlue,
00319 bool buildMag);
00320
00321 void BuildHue();
00322 void BuildSeverity();
00323
00324
00325
00326
00327
00328 static CBMAGRESULT SetupDefaults ( CBMAGINFOSTRUCT* magInfo );
00329
00330
00331 static void FlipEndian ( int& value);
00332 static void FlipEndian ( float& value);
00333 static void FlipEndian ( CBMAGINFOSTRUCT& infoStruct);
00334
00335
00336 static _inline void RGBtoHSI( unsigned char& rh, unsigned char& gs, unsigned char& bi);
00337 static _inline void HSItoRGB( unsigned char& rh, unsigned char& gs, unsigned char& bi);
00338
00339
00340 static CBMAGRESULT CorrectEndian ( CBMAGINFOSTRUCT& infoStruct);
00341
00342 protected:
00343 void InitLUTs();
00344 void FreeLUTs();
00345
00346
00347 protected:
00348 CBMAGINFOSTRUCT fInfo;
00349 bool fFileDirty;
00350 bool fStructDirty;
00351
00352
00353 unsigned char* fRedLUT;
00354 unsigned char* fGreenLUT;
00355 unsigned char* fBlueLUT;
00356 unsigned char* fIntLUTRed;
00357 unsigned char* fIntLUTGreen;
00358 unsigned char* fIntLUTBlue;
00359 unsigned char* fIntLUTYellow;
00360 unsigned char* fIntLUTCyan;
00361 unsigned char* fIntLUTMagenta;
00362 unsigned char* fSatLUTRed;
00363 unsigned char* fSatLUTGreen;
00364 unsigned char* fSatLUTBlue;
00365 unsigned char* fSatLUTYellow;
00366 unsigned char* fSatLUTCyan;
00367 unsigned char* fSatLUTMagenta;
00368 unsigned char* fHueLUT;
00369 unsigned char* fMergeGreenLUT;
00370 unsigned char* fMergeRedLUT;
00371 unsigned char* fMergeBlueLUT;
00372 unsigned char* fSevLUT;
00373
00374 unsigned char* fGreyRedLUT;
00375 unsigned char* fGreyGreenLUT;
00376 unsigned char* fGreyBlueLUT;
00377 };
00378
00379
00380
00381
00382
00383
00384 _inline void CBMagInfo::RGBtoHSI (unsigned char &rh, unsigned char &gs, unsigned char &bi)
00385 {
00386 int maxVal,midVal,minVal;
00387
00388
00389
00390 if (rh>=gs)
00391 {
00392 if (rh>=bi)
00393 {
00394 if (gs>=bi)
00395 {
00396 maxVal = rh;
00397 midVal = gs;
00398 minVal = bi;
00399 rh = 0;
00400 }
00401 else
00402 {
00403 maxVal = rh;
00404 midVal = bi;
00405 minVal = gs;
00406 rh = 5;
00407 }
00408 }
00409 else
00410 {
00411 maxVal = bi;
00412 midVal = rh;
00413 minVal = gs;
00414 rh = 4;
00415 }
00416 }
00417 else
00418 {
00419 if (gs>=bi)
00420 {
00421 if (rh>=bi)
00422 {
00423 maxVal = gs;
00424 midVal = rh;
00425 minVal = bi;
00426 rh = 1;
00427 }
00428 else
00429 {
00430 maxVal = gs;
00431 midVal = bi;
00432 minVal = rh;
00433 rh = 2;
00434 }
00435 }
00436 else
00437 {
00438 maxVal = bi;
00439 midVal = gs;
00440 minVal = rh;
00441 rh = 3;
00442 }
00443 }
00444
00445
00446
00447
00448 if (minVal == maxVal)
00449 {
00450 rh=0;
00451 gs=0;
00452 return;
00453 }
00454
00455
00456 gs = 255 - ((minVal<<8)/maxVal);
00457
00458
00459 bi = maxVal;
00460
00461 midVal = maxVal - (maxVal * (maxVal-midVal))/(maxVal-minVal);
00462 minVal = ( midVal << 8) / maxVal;
00463 if (rh & 1)
00464 minVal = 256 - minVal;
00465
00466 rh = (( ( rh << 8 ) + minVal) / 6) & 255;
00467 }
00468
00469
00470
00471
00472
00473
00474
00475 _inline void CBMagInfo::HSItoRGB (unsigned char &hr, unsigned char &sg, unsigned char &ib)
00476 {
00477
00478 int maxVal,midVal,minVal,hue;
00479
00480 hue = 6*hr;
00481 maxVal = ib;
00482
00483 minVal = (maxVal * (256-sg)) >> 8;
00484
00485 midVal = ( ( (hue & 255 ) + 1 ) * maxVal) >> 8;
00486
00487 if ( hue & 256)
00488 {
00489 midVal = maxVal-midVal;
00490 }
00491
00492 midVal = maxVal-(( (maxVal - midVal) * (sg + 1)) >>8);
00493
00494 hue >>= 8;
00495
00496 switch(hue)
00497 {
00498 case 0: hr=maxVal; sg=midVal; ib=minVal; break;
00499 case 1: hr=midVal; sg=maxVal; ib=minVal; break;
00500 case 2: hr=minVal; sg=maxVal; ib=midVal; break;
00501 case 3: hr=minVal; sg=midVal; ib=maxVal; break;
00502 case 4: hr=midVal; sg=minVal; ib=maxVal; break;
00503 case 5: hr=maxVal; sg=minVal; ib=midVal; break;
00504 }
00505 }
00506
00507
00508 #endif // _CBMAGINFO_H_