Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CAT/CBMagInfo.cpp Source File

CBMagInfo.cpp

Go to the documentation of this file.
00001 /// \file CBMagInfo.cpp
00002 /// \brief Color Modification Information for CodeBlind.
00003 /// \ingroup CAT
00004 ///
00005 /// Copyright (c) 2002-2008 by Michael Ellison.
00006 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00007 ///
00008 // $Author: mikeellison $
00009 // $Date: 2008-01-21 08:33:12 -0600 (Mon, 21 Jan 2008) $
00010 // $Revision:   $
00011 // $NoKeywords: $
00012 #include "CBMagInfo.h"
00013 #include <string.h>
00014 #include <memory.h>
00015 #include <math.h>
00016 //---------------------------------------------------
00017 // CBMagInfo()
00018 CBMagInfo::CBMagInfo()
00019 {
00020     fRedLUT        = fGreenLUT    = fBlueLUT       = 0;
00021     fIntLUTRed     = fIntLUTGreen = fIntLUTBlue    = 0;
00022     fSatLUTRed     = fSatLUTGreen = fSatLUTBlue    = 0;
00023     fIntLUTYellow  = fIntLUTCyan  = fIntLUTMagenta = 0;
00024     fSatLUTYellow  = fSatLUTCyan  = fSatLUTMagenta = 0;
00025     fHueLUT        = 0;
00026 
00027     // Static LUTs
00028     fMergeRedLUT = fMergeGreenLUT = fMergeBlueLUT  = 0;
00029     fSevLUT      = 0;
00030     fGreyRedLUT  = fGreyGreenLUT  = fGreyBlueLUT   = 0;
00031 
00032     SetupDefaults(&this->fInfo);    
00033     fFileDirty   = true;
00034     InitLUTs();
00035 }
00036 
00037 //---------------------------------------------------
00038 // ~CBMagInfo()
00039 CBMagInfo::~CBMagInfo()
00040 {
00041     FreeLUTs();
00042 }
00043 
00044 //---------------------------------------------------
00045 // CBMagInfo()
00046 //        Copy constructors
00047 CBMagInfo::CBMagInfo( const CBMAGINFOSTRUCT& copyStruct)
00048 {
00049     *this = copyStruct;    
00050     InitLUTs();
00051 }
00052 
00053 //---------------------------------------------------
00054 // CBMagInfo()
00055 //        Copy constructors
00056 CBMagInfo::CBMagInfo( const CBMagInfo&  copyInfo  )
00057 {
00058     *this = copyInfo;    
00059     InitLUTs();
00060 }
00061 
00062 //---------------------------------------------------
00063 // ProcessImage
00064 //        Main processing function
00065 //
00066 // RGB buffer is an array for 24-bit RGB pixels.
00067 // Right now, assumes it's in B,G,R order for wintel.
00068 // Buffer is top down (y = 0 is at the top)
00069 //            
00070 // imgWidth and imgHeight are the total image buffer
00071 // sizes. They are assumed not to be width-padded.
00072 // i.e. imgWidth*3 should be the total width of a line.
00073 //            
00074 // xOff and yOff are the offsets to the top-left of
00075 // the region of interest within the image array to
00076 // be processed.
00077 //
00078 // procWidth and procHeight are the width and height
00079 // of the region of interest to be processed.
00080 //
00081 //
00082 void CBMagInfo::ProcessImage    (    unsigned char*        rgbBuffer,
00083                                      int                   imgWidth,
00084                                      int                   imgHeight,
00085                                      int                   xOff,
00086                                      int                   yOff,
00087                                      int                   procWidth,
00088                                      int                   procHeight)
00089 {
00090     int x,y;
00091 
00092     // Rebuild our lookup tables if something has changed.
00093     if (this->fStructDirty)
00094     {
00095         BuildLookupTables();
00096     }
00097     
00098     // per pixel for now - optimize into SIMD-type stuff
00099     // later as much as possible per platform.
00100     unsigned char tmp = 0;
00101 
00102     unsigned char* srcPtr;
00103     unsigned char* dstPtr;
00104 
00105     // offset from end of one line to beginning of next
00106     int step = (imgWidth*3) - (procWidth*3);
00107 
00108     // Starting points in buffer
00109     srcPtr = rgbBuffer + ((yOff)*imgWidth*3) + xOff*3;
00110     dstPtr = srcPtr;
00111 
00112     // convert to DWORD widths.    
00113 
00114     for (y = yOff; y < yOff + procHeight; y++)
00115     {
00116 
00117         for (x = 0; x < procWidth; x++)
00118         {
00119             // Get pixel            
00120             unsigned char r,g,b;
00121             short bg;
00122             // get two in one... it'd be better to do 4, but ah well...
00123             bg = *(short*)srcPtr;            
00124             b = (unsigned char)(bg);
00125             g = (unsigned char)(bg >> 8);
00126             
00127             ++srcPtr;
00128             ++srcPtr;
00129             
00130             r = *srcPtr;
00131             ++srcPtr;
00132             
00133             // Negate image
00134             if (fInfo.fNegative)
00135             {
00136                 b = 255 - b;
00137                 g = 255 - g;
00138                 r = 255 -r ;
00139             }
00140 
00141             // Swap colors first
00142             switch (fInfo.fSwapType)
00143             {
00144                 case SWAP_GREEN_BLUE: tmp = g; g = b; b = tmp; break;
00145                 case SWAP_RED_BLUE:   tmp = r; r = b; b = tmp; break;
00146                 case SWAP_RED_GREEN:  tmp = r; r = g; g = tmp; break;
00147             }                
00148 
00149             // Integer versions are much mo' faster, 
00150             // big thanks to Jace/TBL for posting that info.
00151             RGBtoHSI(r,g,b);
00152 
00153             // -------- BIG NOTE - r,g,b are now hue, saturation, and intensity!!!!
00154             // They are converted back by HSItoRGB.
00155             
00156             r = fHueLUT[r];
00157 
00158             // Grey requested colors
00159             if ((r < 22) || (r >= 234)) // red
00160             {                
00161                 b = fIntLUTRed[b + g*256];
00162                 g = fSatLUTRed[g];
00163             }            
00164             else if (r < 64) // yellow
00165             {
00166                 b = fIntLUTYellow[b + g*256];
00167                 g = fSatLUTYellow[g];
00168             }
00169             else if (r < 107) // green
00170             {
00171                 b = fIntLUTGreen[b + g*256];
00172                 g = fSatLUTGreen[g];
00173             }
00174             else if (r < 150) // cyan
00175             {
00176                 b = fIntLUTCyan[b + g*256];
00177                 g = fSatLUTCyan[g];
00178             }
00179             else if (r < 192) // blue
00180             {
00181                 b = fIntLUTBlue[b + g*256];
00182                 g = fSatLUTBlue[g];
00183             }
00184             else // magenta
00185             {
00186                 b = fIntLUTMagenta[b + g*256];
00187                 g = fSatLUTMagenta[g];
00188             }
00189 
00190             HSItoRGB(r,g,b);
00191 
00192             // Process pixel - try to use LUTs as much as possible here
00193             // instead of doing the calculations real-time.
00194             // 
00195             r =   fRedLUT[r];
00196             g =   fGreenLUT[g];
00197             b =   fBlueLUT[b];
00198 
00199 
00200             // Merge colors if any of the modes are on.
00201             switch (fInfo.fMergeType)
00202             {                
00203                 case MERGE_Red:     
00204                     r =  (unsigned char)((int)fSevLUT[r] + fMergeRedLUT[g + b*256]);
00205                     break;                                                  
00206                 
00207                 case MERGE_Green:                         
00208                     g =  (unsigned char)((int)fSevLUT[g] + fMergeGreenLUT[r + b*256]);                     
00209                     break;
00210                 
00211                 case MERGE_Blue:  
00212                     b = (unsigned char)((int)fSevLUT[b] + fMergeBlueLUT[r + g*256]); 
00213                     break;
00214                 
00215                 // Can't do a single LUT in easy space, so use LUTs for intensities at least
00216                 case MERGE_ALL: 
00217                     {
00218                         unsigned char grey = (unsigned char)(((unsigned int)fGreyRedLUT[r] + fGreyGreenLUT[g] + fGreyBlueLUT[b]) * fInfo.fSeverity);
00219                         r = (unsigned char)(fSevLUT[r]   + grey);
00220                         g = (unsigned char)(fSevLUT[g] + grey);
00221                         b = (unsigned char)(fSevLUT[b]  + grey);
00222                     }
00223                     break;
00224             }
00225 
00226             // get two in one... it'd be better to do 4, but ah well...
00227             *(short*)dstPtr = ((short)b | (g << 8));
00228             ++dstPtr;
00229             ++dstPtr;            
00230             *dstPtr = r;
00231             ++dstPtr;
00232         }
00233 
00234         // Inc to next line        
00235         srcPtr += step;
00236         dstPtr += step;
00237     }
00238 }
00239 
00240 
00241 // Build gamma related lookups
00242 void CBMagInfo::BuildGamma(bool red, bool green, bool blue)
00243 {
00244     int i;
00245     float gamDiv = 1.0f;
00246     float rLevel, gLevel, bLevel;
00247 
00248 
00249     for (i = 0; i < 256; i++)
00250     {        
00251         float level = (float)i;
00252                 
00253         if (red)
00254         {
00255             rLevel = i + (fInfo.fBright_Red - 0.5f)*512;
00256             if (rLevel < 0)   rLevel = 0;
00257             if (rLevel > 255) rLevel = 255;
00258         }
00259         
00260         if (green)
00261         {
00262             gLevel = i + (fInfo.fBright_Green - 0.5f)*512;
00263             if (gLevel < 0)   gLevel = 0;
00264             if (gLevel > 255) gLevel = 255;
00265         }
00266         
00267         if (blue)
00268         {
00269             bLevel = i + (fInfo.fBright_Blue - 0.5f)*512;        
00270             if (bLevel < 0)   bLevel = 0;
00271             if (bLevel > 255) bLevel = 255;
00272         }
00273 
00274         float gamDiv = 1.0f;
00275 
00276         if (fInfo.fGamma > 0.5f)
00277         {            
00278             gamDiv = 1.0f / (1.0f - (fInfo.fGamma - 0.5f));
00279             
00280             if (red)
00281             {
00282                 level = (float) pow(rLevel, gamDiv);
00283                 if (level > 255)
00284                     level = 255;
00285                 fRedLUT[i] = (unsigned char)level;
00286             }
00287 
00288             if (green)
00289             {
00290                 level = (float) pow(gLevel, gamDiv);
00291                 if (level > 255)
00292                     level = 255;
00293                 fGreenLUT[i] = (unsigned char)level;
00294             }
00295 
00296             if (blue)
00297             {
00298                 level = (float) pow(bLevel, gamDiv);
00299                 if (level > 255)
00300                     level = 255;
00301                 fBlueLUT[i] = (unsigned char)level;
00302             }
00303 
00304         }
00305         else if (fInfo.fGamma < 0.5f)
00306         {
00307             gamDiv = 1.0f/(1.0f + (0.5f - fInfo.fGamma)*2);
00308 
00309             if (red)
00310             {
00311                 level =(float) pow(rLevel, gamDiv);
00312                 if (level > 255)
00313                     level = 255;
00314                 fRedLUT[i] = (unsigned char)level;
00315             }
00316 
00317             if (green)
00318             {
00319                 level =(float) pow(gLevel, gamDiv);
00320                 if (level > 255)
00321                     level = 255;
00322                 fGreenLUT[i] = (unsigned char)level;
00323             }
00324 
00325             if (blue)
00326             {
00327                 level =(float) pow(bLevel, gamDiv);
00328                 if (level > 255)
00329                     level = 255;
00330                 fBlueLUT[i] = (unsigned char)level;
00331             }
00332         }
00333         else
00334         {
00335             if (red)
00336             {
00337                 fRedLUT[i]   = (unsigned char)rLevel;
00338             }
00339             if (green)
00340             {
00341                 fGreenLUT[i] = (unsigned char)gLevel;
00342             }
00343             if (blue)
00344             {
00345                 fBlueLUT[i]  = (unsigned char)bLevel;
00346             }
00347         }
00348     }
00349 }
00350 
00351 
00352 // Build grey-related lookups
00353 void CBMagInfo::BuildGreys(bool buildRed, bool buildYellow, bool buildGreen, bool buildCyan, bool buildBlue, bool buildMag)
00354 {
00355     int i,j;
00356 
00357     if (buildRed)
00358     {
00359         for (i = 0; i < 256; i++)
00360         {
00361             for (j = 0; j < 256; j++)
00362             {
00363                 fIntLUTRed[i+j*256] = (unsigned char)((i * (255 - j*fInfo.fGreyRed * 0.3f)) / 255);
00364             }
00365             fSatLUTRed[i] = (unsigned char)(i * (1.0f - fInfo.fGreyRed));
00366         }
00367     }
00368 
00369     if (buildYellow)
00370     {
00371         for (i = 0; i < 256; i++)
00372         {
00373             for (j = 0; j < 256; j++)
00374             {
00375                 fIntLUTYellow[i+j*256] = (unsigned char)((i * (255 - j*fInfo.fGreyYellow *0.45f)) / 255);                
00376             }
00377             fSatLUTYellow[i] = (unsigned char)(i * (1.0f - fInfo.fGreyYellow));
00378         }
00379     }
00380 
00381     if (buildGreen)
00382     {
00383         for (i = 0; i < 256; i++)
00384         {
00385             for (j = 0; j < 256; j++)
00386             {
00387                 fIntLUTGreen[i+j*256] = (unsigned char)((i * (255 - j*fInfo.fGreyGreen * 0.59f)) / 255);
00388             }
00389             fSatLUTGreen[i] = (unsigned char)(i * (1.0f - fInfo.fGreyGreen));
00390         }
00391     }
00392 
00393     if (buildCyan)
00394     {
00395         for (i = 0; i < 256; i++)
00396         {
00397             for (j = 0; j < 256; j++)
00398             {
00399                 fIntLUTCyan[i+j*256] = (unsigned char)((i * (255 - j*fInfo.fGreyCyan * 0.3f)) / 255);                
00400             }
00401 
00402             fSatLUTCyan[i] = (unsigned char)(i * (1.0f - fInfo.fGreyCyan));
00403         }
00404     }
00405 
00406 
00407     if (buildBlue)
00408     {
00409         for (i = 0; i < 256; i++)
00410         {
00411             for (j = 0; j < 256; j++)
00412             {
00413                 fIntLUTBlue[i+j*256] = (unsigned char)((i * (255 - j*fInfo.fGreyBlue * 0.11f)) /255);                
00414             }
00415 
00416             fSatLUTBlue[i] = (unsigned char)(i * (1.0f - fInfo.fGreyBlue));
00417         }
00418     }
00419 
00420     if (buildMag)
00421     {
00422         for (i = 0; i < 256; i++)
00423         {
00424             for (j = 0; j < 256; j++)
00425             {
00426                 fIntLUTMagenta[i+j*256] = (unsigned char)((i * (255 - j*fInfo.fGreyMagenta*0.21f)) /255);
00427             }
00428             
00429             fSatLUTMagenta[i] = (unsigned char)(i * (1.0f - fInfo.fGreyMagenta));
00430         }        
00431     }
00432 
00433 }
00434 
00435 void CBMagInfo::BuildHue()
00436 {
00437     int i;
00438     // Build the lookup tables
00439     for (i = 0; i < 256; i++)
00440     {                
00441         // Compress hue space        
00442         fHueLUT[i] = (unsigned char)(i * (1.0f - fInfo.fHueCompress));
00443         
00444         // Wrap around is automatic and fine - it's a circle.        
00445         fHueLUT[i] += (unsigned char)(fInfo.fHue*255.0f - 128.0f);
00446     }    
00447 }
00448 
00449 void CBMagInfo::BuildSeverity()
00450 {
00451     // Build severity luts
00452     for (int i=0; i < 256; i++)
00453     {
00454         // Severity luts for merging
00455         fSevLUT[i]   =  (unsigned char)((1.0f -fInfo.fSeverity)*i);
00456 
00457         // Setup colorblind conversion LUTs
00458         for (int j = 0; j < 256; j++)
00459         {
00460             // These are the assignments in processing
00461             fMergeRedLUT[i + j*256]   =  (unsigned char)(fInfo.fSeverity*((0.59f*i) + (0.11f*j)) * 1.42f);
00462             fMergeGreenLUT[i + j*256] =  (unsigned char)(fInfo.fSeverity*((0.3f*i)  + (0.11f*j)) * 2.4f);
00463             fMergeBlueLUT[i + j*256]  =  (unsigned char)(fInfo.fSeverity*((0.3f*i)  + (0.59f*j)) * 1.12f);
00464             // no lut for fMergeRGB, is 3-dimensional. Maybe LUT the grey conversion though...
00465         }
00466     }
00467 }
00468 
00469 //---------------------------------------------------------------
00470 // BuildLookupTables()
00471 //
00472 //        Lookup table builder - this rebuilds the LUTs for the
00473 //        ProcessImage() function from the CBMAGINFOSTRUCT.  It's called
00474 //        automatically if the fStructDirty flag is set and ProcessImage
00475 //        gets called, but if for some reason this ends up being a long
00476 //        function you can call it ahead of time to avoid the speed hit
00477 //        on the first process func.
00478 //
00479 void CBMagInfo::BuildLookupTables()
00480 {
00481 
00482     BuildGamma(true,true,true);
00483     BuildGreys(true,true,true,true,true,true);
00484     BuildHue();
00485     BuildSeverity();
00486 
00487     // Mark structs as clean since we've rebuild from them.
00488     fStructDirty = false;
00489 }
00490 
00491 //---------------------------------------------------
00492 // operator=
00493 CBMagInfo& CBMagInfo::operator= (const CBMAGINFOSTRUCT& copyStruct)
00494 {
00495     // Perform validation on copy
00496     this->SetBrightBlue    (    copyStruct.fBright_Blue          );
00497     this->SetBrightGreen   (    copyStruct.fBright_Green         );
00498     this->SetBrightRed     (    copyStruct.fBright_Red           );
00499     this->SetGamma         (    copyStruct.fGamma                );
00500     this->SetHue           (    copyStruct.fHue                  );
00501     this->SetSeverity      (    copyStruct.fSeverity             );
00502     this->SetCompress      (    copyStruct.fHueCompress          );
00503     this->SetGreyRed       (    copyStruct.fGreyRed              );
00504     this->SetGreyGreen     (    copyStruct.fGreyGreen            );
00505     this->SetGreyBlue      (    copyStruct.fGreyBlue             );
00506     this->SetGreyYellow    (    copyStruct.fGreyYellow           );
00507     this->SetGreyCyan      (    copyStruct.fGreyCyan             );
00508     this->SetGreyMagenta   (    copyStruct.fGreyMagenta          );
00509     this->SetMagLevel      (    copyStruct.fMagnificationLevel   );
00510     this->SetFilterMouse   (    copyStruct.fFilterMouse          );
00511     this->SetMergeType     (    (MERGETYPE)copyStruct.fMergeType );
00512     this->SetName          (    copyStruct.fInfoName             );
00513     this->SetRefresh       (    copyStruct.fRefresh              );
00514     this->SetFeedback      (    copyStruct.fAllowFeedback > 0    );
00515     this->SetOnTop         (    copyStruct.fOnTop > 0            );
00516     this->SetNegative      (    copyStruct.fNegative > 0         );
00517     this->SetSwapType      (    (SWAPTYPE)copyStruct.fSwapType   );    
00518         
00519     fFileDirty        = true;    
00520     return *this;
00521 }
00522 
00523 //---------------------------------------------------
00524 // operator=
00525 CBMagInfo& CBMagInfo::operator= (const CBMagInfo& copyInfo)
00526 {
00527     // Do item by item so we can refresh LUTs only if needed.
00528     
00529     this->SetBrightBlue   (    copyInfo.fInfo.fBright_Blue          );
00530     this->SetBrightGreen  (    copyInfo.fInfo.fBright_Green         );
00531     this->SetBrightRed    (    copyInfo.fInfo.fBright_Red           );
00532     this->SetGamma        (    copyInfo.fInfo.fGamma                );
00533     this->SetHue          (    copyInfo.fInfo.fHue                  );
00534     this->SetSeverity     (    copyInfo.fInfo.fSeverity             );
00535     this->SetCompress     (    copyInfo.fInfo.fHueCompress          );
00536     this->SetGreyRed      (    copyInfo.fInfo.fGreyRed              );
00537     this->SetGreyGreen    (    copyInfo.fInfo.fGreyGreen            );
00538     this->SetGreyBlue     (    copyInfo.fInfo.fGreyBlue             );
00539     this->SetGreyYellow   (    copyInfo.fInfo.fGreyYellow           );
00540     this->SetGreyCyan     (    copyInfo.fInfo.fGreyCyan             );
00541     this->SetGreyMagenta  (    copyInfo.fInfo.fGreyMagenta          );
00542     this->SetMagLevel     (    copyInfo.fInfo.fMagnificationLevel   );
00543     this->SetFilterMouse  (    copyInfo.fInfo.fFilterMouse          );
00544     this->SetMergeType    (    (MERGETYPE)copyInfo.fInfo.fMergeType );
00545     this->SetName         (    copyInfo.fInfo.fInfoName             );
00546     this->SetRefresh      (    copyInfo.fInfo.fRefresh              );
00547     this->SetFeedback     (    copyInfo.fInfo.fAllowFeedback > 0    );
00548     this->SetOnTop        (    copyInfo.fInfo.fOnTop > 0            );
00549     this->SetNegative     (    copyInfo.fInfo.fNegative > 0         );
00550     this->SetSwapType     (    (SWAPTYPE)copyInfo.fInfo.fSwapType   );    
00551 
00552     fFileDirty = copyInfo.fFileDirty;
00553     return *this;    
00554 }
00555 
00556 //---------------------------------------------------
00557 // LoadFromFile
00558 //        Load a MagInfo file
00559 CBMAGRESULT CBMagInfo::LoadFromFile(const char* filename)
00560 {
00561     FILE *fp = fopen(filename,"rb");
00562     
00563     if (fp == 0)
00564     {
00565         return CBMAG_ERR_FILE_OPEN;
00566     }
00567     
00568     CBMAGRESULT result = LoadFromHandle(fp);        
00569     fclose(fp);
00570 
00571     return result;
00572 }
00573 
00574 //---------------------------------------------------
00575 // LoadFromHandle
00576 CBMAGRESULT CBMagInfo::LoadFromHandle(FILE* fp)
00577 {
00578     CBMAGRESULT res = CBMAG_SUCCESS;
00579 
00580     CBMAGINFOSTRUCT tmpStruct;
00581 
00582     // Verify file read
00583     if (sizeof(fInfo) != fread(&tmpStruct,1,sizeof(CBMAGINFOSTRUCT),fp))
00584     {
00585         return CBMAG_ERR_FILE_READ_FAIL;
00586     }    
00587 
00588     // Correct endian-ness of struct if needed.
00589     if (CBMAGFAILED(res = CorrectEndian(tmpStruct)))
00590     {
00591         return res;
00592     }
00593 
00594     // Copy it
00595     *this = tmpStruct;
00596 
00597     // Version check
00598     if (tmpStruct.fVersion > kCBMagVersion)
00599     {
00600         res = CBMAG_STAT_NEW_VERSION;
00601     }
00602 
00603     return res;
00604 }
00605 
00606 //---------------------------------------------------
00607 // SavetoFile
00608 //        Save our config to a MagInfo file
00609 CBMAGRESULT CBMagInfo::SaveToFile(const char* filename)
00610 {
00611     FILE *fp = fopen(filename,"wb");
00612     
00613     if (fp == 0)
00614     {
00615         return CBMAG_ERR_FILE_CREATE;
00616     }
00617     
00618     CBMAGRESULT result = SaveToHandle(fp);        
00619     fclose(fp);
00620 
00621     return result;
00622 }
00623 
00624 
00625 //---------------------------------------------------
00626 // SavetoHandle
00627 CBMAGRESULT CBMagInfo::SaveToHandle   (FILE*       fp)
00628 {
00629     if (sizeof(fInfo) != fwrite(&fInfo,1,sizeof(fInfo),fp))
00630     {
00631         return CBMAG_ERR_FILE_WRITE_FAIL;
00632     }
00633 
00634     fFileDirty = false;
00635     return CBMAG_SUCCESS;
00636 }
00637 
00638 //----------------------------------------------------
00639 // Accessors w/validation
00640 //----------------------------------------------------
00641 
00642 
00643 //---------------------------------------------------
00644 // SetName
00645 CBMAGRESULT CBMagInfo::SetName(const char* name)
00646 {
00647     if (name == 0)
00648     {
00649         strcpy(fInfo.fInfoName, "Untitled");
00650         return CBMAG_SUCCESS;
00651     }
00652 
00653     strncpy(fInfo.fInfoName,name,kCBMagMaxNameLength);
00654     fInfo.fInfoName[kCBMagMaxNameLength] = 0;
00655     
00656     fFileDirty = true;        
00657 
00658     return CBMAG_SUCCESS;
00659 }
00660 
00661 //---------------------------------------------------
00662 // SetOnTop
00663 CBMAGRESULT CBMagInfo::SetOnTop(bool onTop)
00664 {    
00665     fInfo.fOnTop = onTop;
00666     fFileDirty   = true;    
00667     
00668     return CBMAG_SUCCESS;
00669 }
00670 
00671 //---------------------------------------------------
00672 // SetNegative
00673 CBMAGRESULT CBMagInfo::SetNegative(bool negative)
00674 {    
00675     fInfo.fNegative   = negative;
00676     fFileDirty        = true;    
00677     return CBMAG_SUCCESS;
00678 }
00679 //---------------------------------------------------
00680 // SetFeedback
00681 CBMAGRESULT CBMagInfo::SetFeedback(bool allow)
00682 {    
00683     fInfo.fAllowFeedback  = allow?1:0;
00684     fFileDirty            = true;    
00685     
00686     return CBMAG_SUCCESS;
00687 }
00688 //---------------------------------------------------
00689 // SetRefresh
00690 //    time is in milliseconds between refreshes
00691 CBMAGRESULT CBMagInfo::SetRefresh(int refresh)
00692 {    
00693     if (fInfo.fRefresh == refresh)
00694         return CBMAG_SUCCESS;
00695 
00696     fInfo.fRefresh         = refresh;
00697     fFileDirty             = true;    
00698     return CBMAG_SUCCESS;
00699 }
00700 
00701 //---------------------------------------------------
00702 // SetMagLevel
00703 CBMAGRESULT CBMagInfo::SetMagLevel(float magLvl)
00704 {
00705     if (fInfo.fMagnificationLevel == magLvl)
00706         return CBMAG_SUCCESS;
00707 
00708     CBMAGRESULT res = CBMAG_SUCCESS;
00709 
00710     if (magLvl < 1.0f)
00711     {
00712         magLvl = 1.0f;
00713         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00714     }
00715 
00716 
00717     if (magLvl > 16.0f)
00718     {
00719         magLvl = 16.0f;
00720         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00721     }
00722 
00723     fInfo.fMagnificationLevel = magLvl;
00724     
00725     fFileDirty        = true;
00726 //    fStructDirty    = true;
00727     
00728     return res;
00729 }
00730 
00731 //---------------------------------------------------
00732 // SetFilterMouse
00733 CBMAGRESULT CBMagInfo::SetFilterMouse(float coef)
00734 {
00735     if (fInfo.fFilterMouse = coef)
00736         return CBMAG_SUCCESS;
00737 
00738     CBMAGRESULT res = CBMAG_SUCCESS;
00739 
00740     if (coef < 0.0f)
00741     {
00742         coef = 0.0f;
00743         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00744     }
00745 
00746 
00747     if (coef > 0.9f)
00748     {
00749         coef = 0.9f;
00750         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00751     }
00752 
00753     fInfo.fFilterMouse = coef;
00754     
00755     fFileDirty        = true;
00756 //    fStructDirty    = true;
00757     
00758     return res;
00759 }
00760 
00761 
00762 //---------------------------------------------------
00763 // SetGammaBlue
00764 CBMAGRESULT CBMagInfo::SetGamma(float gamma)
00765 {
00766     if (fInfo.fGamma == gamma)
00767         return CBMAG_SUCCESS;
00768 
00769     CBMAGRESULT res = CBMAG_SUCCESS;
00770 
00771     if (gamma < 0.0f)
00772     {
00773         gamma = 0.0f;
00774         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00775     }
00776 
00777     
00778     if (gamma > 1.0f)
00779     {
00780         gamma = 1.0f;
00781         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00782     }
00783 
00784 
00785     fInfo.fGamma        = gamma;
00786     fFileDirty          = true;
00787     
00788     BuildGamma(true,true,true);
00789 
00790     return res;
00791 }
00792 
00793 //---------------------------------------------------
00794 // SetBrightRed
00795 CBMAGRESULT CBMagInfo::SetBrightRed(float brightRed)
00796 {
00797     if (fInfo.fBright_Red == brightRed)
00798         return CBMAG_SUCCESS;
00799 
00800     CBMAGRESULT res = CBMAG_SUCCESS;
00801 
00802     if (brightRed < 0.0f)
00803     {
00804         brightRed = 0.0f;
00805         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00806     }
00807 
00808     
00809     if (brightRed > 1.0f)
00810     {
00811         brightRed = 1.0f;
00812         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00813     }
00814 
00815 
00816     fInfo.fBright_Red = brightRed;
00817     fFileDirty        = true;
00818     
00819     BuildGamma(true,false,false);
00820 
00821     return res;
00822 }
00823 
00824 //---------------------------------------------------
00825 // SetBrightGreen
00826 CBMAGRESULT CBMagInfo::SetBrightGreen(float brightGreen)
00827 {
00828     if (fInfo.fBright_Green == brightGreen)
00829         return CBMAG_SUCCESS;
00830 
00831     CBMAGRESULT res = CBMAG_SUCCESS;
00832 
00833     if (brightGreen < 0.0f)
00834     {
00835         brightGreen = 0.0f;
00836         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00837     }
00838 
00839     
00840     if (brightGreen > 1.0f)
00841     {
00842         brightGreen = 1.0f;
00843         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00844     }
00845 
00846     fInfo.fBright_Green    = brightGreen;
00847     fFileDirty             = true;
00848     
00849     BuildGamma(false,true,false);
00850     return res;
00851 }
00852 
00853 //---------------------------------------------------
00854 // SetBrightBlue
00855 CBMAGRESULT CBMagInfo::SetBrightBlue(float brightBlue)
00856 {
00857     CBMAGRESULT res = CBMAG_SUCCESS;
00858     if (this->fInfo.fBright_Blue == brightBlue)
00859         return res;
00860 
00861     if (brightBlue < 0.0f)
00862     {
00863         brightBlue = 0.0f;
00864         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00865     }
00866 
00867     
00868     if (brightBlue > 1.0f)
00869     {
00870         brightBlue = 1.0f;
00871         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00872     }
00873 
00874     fInfo.fBright_Blue    = brightBlue;
00875     fFileDirty            = true;
00876 
00877     BuildGamma(false,false,true);
00878     return res;
00879 }
00880 
00881 //---------------------------------------------------
00882 // SetHue
00883 CBMAGRESULT CBMagInfo::SetHue(float hue)
00884 {
00885     CBMAGRESULT res = CBMAG_SUCCESS;
00886     if (this->fInfo.fHue == hue)
00887         return res;
00888     
00889     if (hue < 0.0f)
00890     {    
00891         hue = 0.0f;
00892         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00893     }
00894 
00895     if (hue > 1.0f)
00896     {
00897         hue = 1.0f;
00898         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00899     }
00900 
00901 
00902     fInfo.fHue        = hue;
00903     fFileDirty        = true;
00904     
00905     BuildHue();
00906 
00907     return res;
00908 }
00909 
00910 //---------------------------------------------------
00911 // SetSeverity
00912 CBMAGRESULT CBMagInfo::SetSeverity(float severity)
00913 {
00914     CBMAGRESULT res = CBMAG_SUCCESS;
00915     if (this->fInfo.fSeverity == severity)
00916         return res;
00917     
00918     if (severity < 0.0f)
00919     {    
00920         severity = 0.0f;
00921         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00922     }
00923 
00924     if (severity > 1.0f)
00925     {
00926         severity = 1.0f;
00927         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00928     }
00929 
00930 
00931     fInfo.fSeverity = severity;
00932     fFileDirty      = true;
00933     
00934     BuildSeverity();
00935     
00936     return res;
00937 }
00938 
00939 //---------------------------------------------------
00940 // SetGreyRed
00941 CBMAGRESULT CBMagInfo::SetGreyRed(float addbg2r)
00942 {
00943     if (fInfo.fGreyRed == addbg2r)
00944         return CBMAG_SUCCESS;
00945 
00946     CBMAGRESULT res = CBMAG_SUCCESS;
00947     
00948     if (addbg2r < 0.0f)
00949     {    
00950         addbg2r = 0.0f;
00951         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00952     }
00953 
00954     if (addbg2r > 1.0f)
00955     {
00956         addbg2r = 1.0f;
00957         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00958     }
00959 
00960     fInfo.fGreyRed    = addbg2r;    
00961     fFileDirty        = true;
00962     
00963     BuildGreys(true,false,false,false,false,false);
00964     return res;
00965 }
00966 
00967 //---------------------------------------------------
00968 // SetGreyGreen
00969 CBMAGRESULT CBMagInfo::SetGreyGreen(float addbr2g)
00970 {
00971     if (fInfo.fGreyGreen == addbr2g)
00972         return CBMAG_SUCCESS;
00973 
00974     CBMAGRESULT res = CBMAG_SUCCESS;
00975     
00976     if (addbr2g < 0.0f)
00977     {    
00978         addbr2g = 0.0f;
00979         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00980     }
00981 
00982     if (addbr2g > 1.0f)
00983     {
00984         addbr2g = 1.0f;
00985         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
00986     }
00987 
00988     fInfo.fGreyGreen    = addbr2g;    
00989     fFileDirty          = true;
00990     
00991     BuildGreys(false,false,true,false,false,false);
00992 
00993     return res;
00994 }
00995 
00996 //---------------------------------------------------
00997 // SetGreyBlue
00998 CBMAGRESULT CBMagInfo::SetGreyBlue(float addrg2b)
00999 {
01000     if (fInfo.fGreyBlue == addrg2b)
01001         return CBMAG_SUCCESS;
01002 
01003     CBMAGRESULT res = CBMAG_SUCCESS;
01004     
01005     if (addrg2b < 0.0f)
01006     {    
01007         addrg2b = 0.0f;
01008         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01009     }
01010 
01011     if (addrg2b > 1.0f)
01012     {
01013         addrg2b = 1.0f;
01014         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01015     }
01016 
01017     fInfo.fGreyBlue        = addrg2b;    
01018     fFileDirty             = true;
01019 
01020     BuildGreys(false,false,false,false,true,false);
01021 
01022     return res;
01023 }
01024 //---------------------------------------------------
01025 // SetGreyYellow
01026 CBMAGRESULT CBMagInfo::SetGreyYellow(float addbg2r)
01027 {
01028     if (fInfo.fGreyYellow == addbg2r)
01029         return CBMAG_SUCCESS;
01030 
01031     CBMAGRESULT res = CBMAG_SUCCESS;
01032     
01033     if (addbg2r < 0.0f)
01034     {    
01035         addbg2r = 0.0f;
01036         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01037     }
01038 
01039     if (addbg2r > 1.0f)
01040     {
01041         addbg2r = 1.0f;
01042         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01043     }
01044 
01045     fInfo.fGreyYellow    = addbg2r;    
01046     fFileDirty           = true;
01047     
01048     BuildGreys(false,true,false,false,false,false);
01049 
01050     return res;
01051 }
01052 //---------------------------------------------------
01053 // SetGreyCyan
01054 CBMAGRESULT CBMagInfo::SetGreyCyan(float addbg2r)
01055 {
01056     if (fInfo.fGreyCyan == addbg2r)
01057         return CBMAG_SUCCESS;
01058 
01059     CBMAGRESULT res = CBMAG_SUCCESS;
01060     
01061     if (addbg2r < 0.0f)
01062     {    
01063         addbg2r = 0.0f;
01064         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01065     }
01066 
01067     if (addbg2r > 1.0f)
01068     {
01069         addbg2r = 1.0f;
01070         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01071     }
01072 
01073     fInfo.fGreyCyan    = addbg2r;    
01074     fFileDirty         = true;
01075     
01076     BuildGreys(false,false,false,true,false,false);
01077     
01078     return res;
01079 }
01080 //---------------------------------------------------
01081 // SetGreyMagenta
01082 CBMAGRESULT CBMagInfo::SetGreyMagenta(float addbg2r)
01083 {
01084     if (fInfo.fGreyMagenta == addbg2r)
01085         return CBMAG_SUCCESS;
01086 
01087     CBMAGRESULT res = CBMAG_SUCCESS;
01088     
01089     if (addbg2r < 0.0f)
01090     {    
01091         addbg2r = 0.0f;
01092         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01093     }
01094 
01095     if (addbg2r > 1.0f)
01096     {
01097         addbg2r = 1.0f;
01098         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01099     }
01100 
01101     fInfo.fGreyMagenta    = addbg2r;    
01102     fFileDirty            = true;
01103     
01104     BuildGreys(false,false,false,false,false,true);
01105     
01106     return res;
01107 }
01108 
01109 //---------------------------------------------------
01110 // SetSwapType
01111 CBMAGRESULT CBMagInfo::SetSwapType(SWAPTYPE swapType)
01112 {
01113     if (fInfo.fSwapType == swapType)
01114         return CBMAG_SUCCESS;
01115 
01116     CBMAGRESULT res = CBMAG_SUCCESS;
01117 
01118     if (swapType > SWAP_LAST_TYPE)
01119     {
01120         swapType = SWAP_NONE;
01121         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01122     }
01123 
01124     
01125     if (swapType < SWAP_NONE)
01126     {
01127         swapType = SWAP_NONE;
01128         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01129     }
01130 
01131 
01132     fInfo.fSwapType    = swapType;
01133     fFileDirty         = true;    
01134 
01135     return res;
01136 }
01137 
01138 //---------------------------------------------------
01139 // SetMergeType
01140 CBMAGRESULT CBMagInfo::SetMergeType(MERGETYPE mergeType)
01141 {
01142     if (fInfo.fMergeType == mergeType)
01143         return CBMAG_SUCCESS;
01144 
01145     CBMAGRESULT res = CBMAG_SUCCESS;
01146 
01147     if (mergeType > MERGE_LAST_TYPE)
01148     {
01149         mergeType = MERGE_NONE;
01150         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01151     }
01152 
01153     if (mergeType < MERGE_NONE)
01154     {
01155         mergeType = MERGE_NONE;
01156         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01157     }
01158         
01159     fInfo.fMergeType = mergeType;
01160     fFileDirty = true;    
01161 
01162     return res;
01163 }
01164 
01165 
01166 //---------------------------------------------------
01167 // SetCompress
01168 CBMAGRESULT CBMagInfo::SetCompress(float hueCompress)
01169 {
01170     if (fInfo.fHueCompress == hueCompress)
01171         return CBMAG_SUCCESS;
01172 
01173     CBMAGRESULT res = CBMAG_SUCCESS;
01174     
01175     if (hueCompress < 0.0f)
01176     {    
01177         hueCompress = 0.0f;
01178         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01179     }
01180 
01181     if (hueCompress > 1.0f)
01182     {
01183         hueCompress = 1.0f;
01184         res = CBMAG_ERR_PARAMETER_OUT_OF_RANGE;
01185     }
01186 
01187 
01188     fInfo.fHueCompress    = hueCompress;
01189     fFileDirty            = true;
01190     
01191     BuildHue();
01192 
01193     return res;
01194 }
01195 
01196 
01197 //---------------------------------------------
01198 // Retrieval Accessors
01199 //---------------------------------------------
01200 
01201 
01202 
01203 //---------------------------------------------------
01204 // GetName
01205 CBMAGRESULT CBMagInfo::GetName( char*        nameBuffer, 
01206                                 int&         bufLen) const
01207 {
01208     CBMAGRESULT res = CBMAG_SUCCESS;
01209 
01210     if (nameBuffer == 0)
01211     {
01212         return CBMAG_ERR_INVALID_PARAMETER;
01213     }
01214 
01215     strncpy(nameBuffer, fInfo.fInfoName, bufLen);
01216     
01217     if (bufLen <= (int)strlen(fInfo.fInfoName))
01218     {        
01219         nameBuffer[bufLen - 1] = 0;        
01220         res = CBMAG_ERR_BUF_TOO_SMALL;
01221     }
01222 
01223     bufLen = (int)strlen(fInfo.fInfoName);
01224     
01225     return res;
01226 }
01227 
01228 //---------------------------------------------------
01229 // GetOnTop
01230 bool CBMagInfo::GetOnTop() const
01231 {
01232     return (fInfo.fOnTop > 0);
01233 }
01234 
01235 //---------------------------------------------------
01236 // GetNegative
01237 bool CBMagInfo::GetNegative() const
01238 {
01239     return (fInfo.fNegative > 0);
01240 }
01241 
01242 //---------------------------------------------------
01243 // GetFeedback
01244 bool CBMagInfo::GetFeedback() const
01245 {    
01246     return fInfo.fAllowFeedback > 0;
01247 }
01248 //---------------------------------------------------
01249 // GetRefresh
01250 //    time is in milliseconds between refreshes
01251 int CBMagInfo::GetRefresh() const
01252 {    
01253     return fInfo.fRefresh;
01254 }
01255 
01256 //---------------------------------------------------
01257 // GetMagLevel
01258 float CBMagInfo::GetMagLevel() const
01259 {
01260     return fInfo.fMagnificationLevel;
01261 }
01262 
01263 //---------------------------------------------------
01264 // GetFilterMouse
01265 float CBMagInfo::GetFilterMouse() const
01266 {
01267     return fInfo.fFilterMouse;
01268 }
01269 
01270 //---------------------------------------------------
01271 // GetGamma
01272 float CBMagInfo::GetGamma() const
01273 {
01274     return fInfo.fGamma;
01275 }
01276 
01277 //---------------------------------------------------
01278 // GetBrightRed
01279 float CBMagInfo::GetBrightRed() const
01280 {
01281     return fInfo.fBright_Red;
01282 }
01283 
01284 //---------------------------------------------------
01285 // GetBrightGreen
01286 float CBMagInfo::GetBrightGreen() const
01287 {
01288     return fInfo.fBright_Green;
01289 }
01290 
01291 //---------------------------------------------------
01292 // GetBrightBlue
01293 float CBMagInfo::GetBrightBlue() const
01294 {
01295     return fInfo.fBright_Red;
01296 }
01297 
01298 //---------------------------------------------------
01299 // GetHue
01300 float CBMagInfo::GetHue() const
01301 {
01302     return fInfo.fHue;
01303 }
01304 
01305 //---------------------------------------------------
01306 // GetSeverity
01307 float CBMagInfo::GetSeverity() const
01308 {
01309     return fInfo.fSeverity;
01310 }
01311 
01312 
01313 //---------------------------------------------------
01314 // 
01315 float CBMagInfo::GetGreyRed() const
01316 {
01317     return fInfo.fGreyRed;
01318 }
01319 float CBMagInfo::GetGreyGreen() const
01320 {
01321     return fInfo.fGreyGreen;
01322 }
01323 float CBMagInfo::GetGreyBlue() const
01324 {
01325     return fInfo.fGreyBlue;
01326 }
01327 float CBMagInfo::GetGreyYellow() const
01328 {
01329     return fInfo.fGreyYellow;
01330 }
01331 float CBMagInfo::GetGreyCyan() const
01332 {
01333     return fInfo.fGreyCyan;
01334 }
01335 float CBMagInfo::GetGreyMagenta() const
01336 {
01337     return fInfo.fGreyMagenta;
01338 }
01339 
01340 //---------------------------------------------------
01341 // GetSwapType
01342 CBMagInfo::SWAPTYPE CBMagInfo::GetSwapType() const
01343 {
01344     return (CBMagInfo::SWAPTYPE)fInfo.fSwapType;
01345 }
01346 
01347 //---------------------------------------------------
01348 // GetMergeType
01349 CBMagInfo::MERGETYPE CBMagInfo::GetMergeType() const
01350 {
01351     return (CBMagInfo::MERGETYPE)fInfo.fMergeType;
01352 }
01353 
01354 
01355 //---------------------------------------------------
01356 // GetCompress
01357 float CBMagInfo::GetCompress() const
01358 {
01359     return fInfo.fHueCompress;
01360 }
01361 
01362 
01363 //---------------------------------------------------
01364 // SetupDefaults
01365 //        Setup a mag info struct with the defaults (no process)
01366 CBMAGRESULT CBMagInfo::SetupDefaults ( CBMAGINFOSTRUCT* magInfo )
01367 {
01368     if (magInfo == 0)    
01369         return CBMAG_ERR_INVALID_PARAMETER;
01370     
01371     memset(magInfo->fInfoName,0,kCBMagNameBufferSize);
01372     strcpy(magInfo->fInfoName,"Untitled");
01373     
01374     magInfo->fCBMagSigInt          = 0x43424D47;
01375     magInfo->fVersion              = kCBMagVersion;
01376     magInfo->fGamma                = 0.5f;
01377     magInfo->fBright_Red           = 0.5f;
01378     magInfo->fBright_Green         = 0.5f;
01379     magInfo->fBright_Blue          = 0.5f;
01380     magInfo->fHue                  = 0.5f;
01381     magInfo->fSeverity             = 1.0f;
01382     magInfo->fHueCompress          = 0.0f;
01383     
01384     magInfo->fGreyRed              = 0.0f;
01385     magInfo->fGreyGreen            = 0.0f;
01386     magInfo->fGreyBlue             = 0.0f;
01387     magInfo->fGreyYellow           = 0.0f;
01388     magInfo->fGreyCyan             = 0.0f;
01389     magInfo->fGreyMagenta          = 0.0f;
01390     
01391     magInfo->fSwapType             = SWAP_NONE;
01392     magInfo->fMergeType            = MERGE_NONE;
01393     magInfo->fOnTop                = true;    
01394     magInfo->fNegative             = false;    
01395     magInfo->fMagnificationLevel   = 1.0f;
01396     magInfo->fFilterMouse          = 0.0f;
01397     magInfo->fAllowFeedback        = false;
01398     magInfo->fRefresh              = 100;    // 10Hz refresh speed default (for slower PC's)
01399         
01400     memset(magInfo->fReserved,0,sizeof(magInfo->fReserved));
01401     memset(magInfo->fThirdParty,0,sizeof(magInfo->fThirdParty));    
01402     return CBMAG_SUCCESS;
01403 }
01404 
01405 //---------------------------------------------------
01406 // FlipEndian (float)
01407 //     Swap the endian-ness of the value
01408 //     For using mac files on pc, vise-versa, etc.
01409 void CBMagInfo::FlipEndian(float& value)
01410 {
01411     int* tmpSpot = (int *)&value;
01412     
01413     FlipEndian(*tmpSpot);
01414 
01415     value = *(float *)tmpSpot;
01416 }
01417 
01418 //---------------------------------------------------
01419 // FlipEndian (int)
01420 void CBMagInfo::FlipEndian(int& value)
01421 {
01422     value = ((value & 0x000000ff) << 24) |
01423             ((value & 0x0000ff00) << 8)  |
01424             ((value & 0x00ff0000) >> 8)  |
01425             ((value & 0xff000000) >> 24);
01426 }
01427 
01428 
01429 //---------------------------------------------------
01430 // FlipEndian (entire structure)
01431 void CBMagInfo::FlipEndian(CBMAGINFOSTRUCT& infoStruct)
01432 {
01433     // It's in reversed endian from us. flip everything.
01434     FlipEndian(infoStruct.fCBMagSigInt);
01435     FlipEndian(infoStruct.fVersion);
01436     FlipEndian(infoStruct.fAllowFeedback);
01437     FlipEndian(infoStruct.fRefresh);
01438     FlipEndian(infoStruct.fOnTop);
01439     FlipEndian(infoStruct.fNegative);
01440     FlipEndian(infoStruct.fMagnificationLevel);
01441     FlipEndian(infoStruct.fFilterMouse);
01442     FlipEndian(infoStruct.fGamma);
01443     FlipEndian(infoStruct.fBright_Red);
01444     FlipEndian(infoStruct.fBright_Green);
01445     FlipEndian(infoStruct.fBright_Blue);
01446     FlipEndian(infoStruct.fGreyRed);
01447     FlipEndian(infoStruct.fGreyGreen);
01448     FlipEndian(infoStruct.fGreyBlue);
01449     FlipEndian(infoStruct.fGreyYellow);
01450     FlipEndian(infoStruct.fGreyCyan);
01451     FlipEndian(infoStruct.fGreyMagenta);
01452     FlipEndian(infoStruct.fHue);
01453     FlipEndian(infoStruct.fSeverity);
01454     FlipEndian(infoStruct.fHueCompress);
01455     FlipEndian(infoStruct.fSwapType);
01456     FlipEndian(infoStruct.fMergeType);
01457 }
01458 
01459 //---------------------------------------------------
01460 // CorrectEndian (corrects to our machine)
01461 CBMAGRESULT CBMagInfo::CorrectEndian(CBMAGINFOSTRUCT&    infoStruct)
01462 {
01463     // Check sanity on the struct...
01464     if (0x43424D47 == infoStruct.fCBMagSigInt)
01465     {
01466         // It's good and in our format.
01467         return CBMAG_SUCCESS;
01468     }
01469     else if (0x474D4243 == infoStruct.fCBMagSigInt)
01470     {
01471         FlipEndian(infoStruct);
01472         return CBMAG_STAT_ENDIAN_FLIPPED;
01473     }
01474     else
01475     {
01476         return CBMAG_ERR_FILE_CORRUPT;
01477     }
01478 }
01479 
01480 //---------------------------------------------------
01481 void CBMagInfo::InitLUTs()
01482 {
01483     // Some platforms, new throws on, some it doesn't.
01484     // If a new fails, throw. We catch at the end, clean up,
01485     // and rethrow, so CBMagInfo() can only throw a
01486     // CBMAG_ERR_OUT_OF_MEMORY error.
01487     FreeLUTs();
01488 
01489     try
01490     {
01491         if (0 == (fRedLUT   = new unsigned char[256]))
01492         {
01493             throw CBMAG_ERR_OUT_OF_MEMORY;
01494         }
01495         
01496         if (0 == (fGreenLUT = new unsigned char[256]))
01497         {
01498             throw CBMAG_ERR_OUT_OF_MEMORY;
01499         }
01500 
01501         if (0 == (fBlueLUT  = new unsigned char[256]))
01502         {
01503             throw CBMAG_ERR_OUT_OF_MEMORY;
01504         }
01505 
01506         if (0 == (fGreyRedLUT   = new unsigned char[256]))
01507         {
01508             throw CBMAG_ERR_OUT_OF_MEMORY;
01509         }
01510         
01511         if (0 == (fGreyGreenLUT = new unsigned char[256]))
01512         {
01513             throw CBMAG_ERR_OUT_OF_MEMORY;
01514         }
01515 
01516         if (0 == (fGreyBlueLUT  = new unsigned char[256]))
01517         {
01518             throw CBMAG_ERR_OUT_OF_MEMORY;
01519         }
01520 
01521 
01522         if (0 == (fIntLUTRed = new unsigned char[256*256]))
01523         {
01524             throw CBMAG_ERR_OUT_OF_MEMORY;
01525         }
01526         
01527         if (0 == (fIntLUTGreen = new unsigned char[256*256]))
01528         {
01529             throw CBMAG_ERR_OUT_OF_MEMORY;
01530         }
01531 
01532         if (0 == (fIntLUTBlue  = new unsigned char[256*256]))
01533         {
01534             throw CBMAG_ERR_OUT_OF_MEMORY;
01535         }
01536 
01537         if (0 == (fIntLUTYellow = new unsigned char[256*256]))
01538         {
01539             throw CBMAG_ERR_OUT_OF_MEMORY;
01540         }
01541         
01542         if (0 == (fIntLUTCyan = new unsigned char[256*256]))
01543         {
01544             throw CBMAG_ERR_OUT_OF_MEMORY;
01545         }
01546 
01547         if (0 == (fIntLUTMagenta  = new unsigned char[256*256]))
01548         {
01549             throw CBMAG_ERR_OUT_OF_MEMORY;
01550         }
01551 
01552         if (0 == (fSatLUTRed = new unsigned char[256*256]))
01553         {
01554             throw CBMAG_ERR_OUT_OF_MEMORY;
01555         }
01556         
01557         if (0 == (fSatLUTGreen = new unsigned char[256*256]))
01558         {
01559             throw CBMAG_ERR_OUT_OF_MEMORY;
01560         }
01561 
01562         if (0 == (fSatLUTBlue  = new unsigned char[256*256]))
01563         {
01564             throw CBMAG_ERR_OUT_OF_MEMORY;
01565         }
01566 
01567         if (0 == (fSatLUTYellow = new unsigned char[256*256]))
01568         {
01569             throw CBMAG_ERR_OUT_OF_MEMORY;
01570         }
01571         
01572         if (0 == (fSatLUTCyan = new unsigned char[256*256]))
01573         {
01574             throw CBMAG_ERR_OUT_OF_MEMORY;
01575         }
01576 
01577         if (0 == (fSatLUTMagenta  = new unsigned char[256*256]))
01578         {
01579             throw CBMAG_ERR_OUT_OF_MEMORY;
01580         }
01581 
01582         if (0 == (fHueLUT  = new unsigned char[256]))
01583         {
01584             throw CBMAG_ERR_OUT_OF_MEMORY;
01585         }
01586 
01587 
01588         if (0 == (fMergeRedLUT  = new unsigned char[256*256]))
01589         {
01590             throw CBMAG_ERR_OUT_OF_MEMORY;
01591         }
01592 
01593         if (0 == (fMergeGreenLUT  = new unsigned char[256*256]))
01594         {
01595             throw CBMAG_ERR_OUT_OF_MEMORY;
01596         }
01597 
01598         if (0 == (fMergeBlueLUT  = new unsigned char[256*256]))
01599         {
01600             throw CBMAG_ERR_OUT_OF_MEMORY;
01601         }
01602 
01603         if (0 == (fSevLUT  = new unsigned char[256*256]))
01604         {
01605             throw CBMAG_ERR_OUT_OF_MEMORY;
01606         }
01607 
01608         memset(fRedLUT,0,256);
01609         memset(fGreenLUT,0,256);
01610         memset(fBlueLUT,0,256);        
01611         memset(fGreyRedLUT,0,256);
01612         memset(fGreyGreenLUT,0,256);
01613         memset(fGreyBlueLUT,0,256);        
01614         memset(fIntLUTRed,0,256*256);
01615         memset(fIntLUTGreen,0,256*256);
01616         memset(fIntLUTBlue,0,256*256);        
01617         memset(fIntLUTYellow,0,256*256);
01618         memset(fIntLUTCyan,0,256*256);
01619         memset(fIntLUTMagenta,0,256*256);        
01620         memset(fSatLUTRed,0,256);
01621         memset(fSatLUTGreen,0,256);
01622         memset(fSatLUTBlue,0,256);        
01623         memset(fSatLUTYellow,0,256);
01624         memset(fSatLUTCyan,0,256);
01625         memset(fSatLUTMagenta,0,256);        
01626         memset(fHueLUT,0,256);        
01627         memset(fMergeRedLUT,0,256*256);        
01628         memset(fMergeGreenLUT,0,256*256);        
01629         memset(fMergeBlueLUT,0,256*256);        
01630         memset(fSevLUT,0,256*256);        
01631     }        
01632     catch (...)
01633     {
01634         FreeLUTs();
01635         throw CBMAG_ERR_OUT_OF_MEMORY;
01636     }
01637 
01638     // Setup static LUTs
01639     int i;
01640     for (i=0; i<256; i++)
01641     {        
01642         // Greyscale intensity LUTs for colors. Based on standard NTSC values
01643         fGreyRedLUT[i]     = (unsigned char)(i*0.3f);
01644         fGreyGreenLUT[i]   = (unsigned char)(i*0.59f);
01645         fGreyBlueLUT[i]    = (unsigned char)(i*0.11f);
01646     }
01647 
01648     fStructDirty = true;
01649 }
01650 
01651 //---------------------------------------------------
01652 // FreeLUTs
01653 //    Private function to free the lookup tables
01654 //    Don't call externally.
01655 //
01656 void CBMagInfo::FreeLUTs()
01657 {
01658     if (fRedLUT)        { delete fRedLUT;        fRedLUT        = 0;  }
01659     if (fGreenLUT)      { delete fGreenLUT;      fGreenLUT      = 0;  }
01660     if (fBlueLUT)       { delete fBlueLUT;       fBlueLUT       = 0;  }
01661     if (fGreyRedLUT)    { delete fGreyRedLUT;    fGreyRedLUT    = 0;  }
01662     if (fGreyGreenLUT)  { delete fGreyGreenLUT;  fGreyGreenLUT  = 0;  }
01663     if (fGreyBlueLUT)   { delete fGreyBlueLUT;   fGreyBlueLUT   = 0;  }
01664     if (fIntLUTRed)     { delete fIntLUTRed;     fIntLUTRed     = 0;  }
01665     if (fIntLUTGreen)   { delete fIntLUTGreen;   fIntLUTGreen   = 0;  }
01666     if (fIntLUTBlue)    { delete fIntLUTBlue;    fIntLUTBlue    = 0;  }
01667     if (fIntLUTYellow)  { delete fIntLUTYellow;  fIntLUTYellow  = 0;  }
01668     if (fIntLUTCyan)    { delete fIntLUTCyan;    fIntLUTCyan    = 0;  }
01669     if (fIntLUTMagenta) { delete fIntLUTMagenta; fIntLUTMagenta = 0;  }
01670     if (fSatLUTRed)     { delete fSatLUTRed;     fSatLUTRed     = 0;  }
01671     if (fSatLUTGreen)   { delete fSatLUTGreen;   fSatLUTGreen   = 0;  }
01672     if (fSatLUTBlue)    { delete fSatLUTBlue;    fSatLUTBlue    = 0;  }
01673     if (fSatLUTYellow)  { delete fSatLUTYellow;  fSatLUTYellow  = 0;  }
01674     if (fSatLUTCyan)    { delete fSatLUTCyan;    fSatLUTCyan    = 0;  }
01675     if (fSatLUTMagenta) { delete fSatLUTMagenta; fSatLUTMagenta = 0;  }
01676     if (fHueLUT)        { delete fHueLUT;        fHueLUT        = 0;  }
01677     if (fMergeRedLUT)   { delete fMergeRedLUT;   fMergeRedLUT   = 0;  }
01678     if (fMergeGreenLUT) { delete fMergeGreenLUT; fMergeGreenLUT = 0;  }
01679     if (fMergeBlueLUT)  { delete fMergeBlueLUT;  fMergeBlueLUT  = 0;  }
01680     if (fSevLUT)        { delete fSevLUT;        fSevLUT        = 0;  }
01681 }
01682 
01683 
01684 void CBMagInfo::Reset()
01685 {
01686     SetupDefaults(&fInfo);
01687     fStructDirty = true;
01688     BuildLookupTables();
01689 }
01690 

Generated on Mon Feb 11 04:09:50 2008 for Game Accessibility Suite by doxygen 1.5.4