00001 #ifndef OPENTISSUE_GPU_IMAGE_IO_IMAGE_IL_WRAP_H
00002 #define OPENTISSUE_GPU_IMAGE_IO_IMAGE_IL_WRAP_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012
00013
00014
00015
00016 #include <IL/ilut.h>
00017 #ifndef IL_LBM
00018 #define IL_LBM IL_ILBM
00019 #endif
00020
00021
00022 namespace OpenTissue
00023 {
00024 namespace image
00025 {
00026 namespace detail
00027 {
00028
00029
00030 void check_IL_errors()
00031 {
00032 ILenum Error;
00033 while ((Error = ilGetError()) != IL_NO_ERROR)
00034 {
00035 std::cerr << "check_IL_errors(): "
00036 << Error
00037 << " : "
00038 << iluErrorString(Error)
00039 << std::endl;
00040 }
00041 }
00042
00043
00044 std::string get_IL_string(ILenum code)
00045 {
00046 switch(code)
00047 {
00048
00049 case IL_COLOR_INDEX : return "IL_COLOR_INDEX";
00050 case IL_RGB : return "IL_RGB";
00051 case IL_RGBA: return "IL_RGBA";
00052 case IL_BGR : return "IL_BGR";
00053 case IL_BGRA: return "IL_BGRA";
00054 case IL_LUMINANCE : return "IL_LUMINANCE";
00055 case IL_LUMINANCE_ALPHA : return "IL_LUMINANCE_ALPHA";
00056 case IL_BYTE: return "IL_BYTE";
00057 case IL_UNSIGNED_BYTE: return "IL_UNSIGNED_BYTE";
00058 case IL_SHORT: return "IL_SHORT";
00059 case IL_UNSIGNED_SHORT: return "IL_UNSIGNED_SHORT";
00060 case IL_INT: return "IL_INT";
00061 case IL_UNSIGNED_INT: return "IL_UNSIGNED_INT";
00062 case IL_FLOAT: return "IL_FLOAT";
00063 case IL_DOUBLE: return "IL_DOUBLE";
00064
00065 case IL_PAL_NONE: return "IL_PAL_NONE";
00066 case IL_PAL_RGB24: return "IL_PAL_RGB24";
00067 case IL_PAL_RGB32: return "IL_PAL_RGB32";
00068 case IL_PAL_RGBA32: return "IL_PAL_RGBA32";
00069 case IL_PAL_BGR24: return "IL_PAL_BGR24";
00070 case IL_PAL_BGR32: return "IL_PAL_BGR32";
00071 case IL_PAL_BGRA32: return "IL_PAL_BGRA32";
00072 case IL_TYPE_UNKNOWN: return "IL_TYPE_UNKNOWN";
00073 case IL_BMP: return "IL_BMP";
00074 case IL_CUT: return "IL_CUT";
00075 case IL_DOOM: return "IL_DOOM";
00076 case IL_DOOM_FLAT: return "IL_DOOM_FLAT";
00077 case IL_ICO: return "IL_ICO";
00078 case IL_JPG: return "IL_JPG";
00079
00080 case IL_LBM: return "IL_LBM";
00081 case IL_PCD: return "IL_PCD";
00082 case IL_PCX: return "IL_PCX";
00083 case IL_PIC: return "IL_PIC";
00084 case IL_PNG: return "IL_PNG";
00085 case IL_PNM: return "IL_PNM";
00086 case IL_SGI: return "IL_SGI";
00087 case IL_TGA: return "IL_TGA";
00088 case IL_TIF: return "IL_TIF";
00089 case IL_CHEAD: return "IL_CHEAD";
00090 case IL_RAW: return "IL_RAW";
00091 case IL_MDL: return "IL_MDL";
00092 case IL_WAL: return "IL_WAL";
00093 case IL_LIF: return "IL_LIF";
00094 case IL_MNG: return "IL_MNG";
00095
00096 case IL_GIF: return "IL_GIF";
00097 case IL_DDS: return "IL_DDS";
00098 case IL_DCX: return "IL_DCX";
00099 case IL_PSD: return "IL_PSD";
00100 case IL_EXIF: return "IL_EXIF";
00101 case IL_PSP: return "IL_PSP";
00102 case IL_PIX: return "IL_PIX";
00103 case IL_PXR: return "IL_PXR";
00104 case IL_XPM: return "IL_XPM";
00105 case IL_JASC_PAL: return "IL_JASC_PAL";
00106 case IL_ORIGIN_SET: return "IL_ORIGIN_SET";
00107 case IL_ORIGIN_LOWER_LEFT: return "IL_ORIGIN_LOWER_LEFT";
00108 case IL_ORIGIN_UPPER_LEFT: return "IL_ORIGIN_UPPER_LEFT";
00109 case IL_ORIGIN_MODE: return "IL_ORIGIN_MODE";
00110 case IL_FORMAT_SET: return "IL_FORMAT_SET";
00111 case IL_FORMAT_MODE: return "IL_FORMAT_MODE";
00112 case IL_TYPE_SET: return "IL_TYPE_SET";
00113 case IL_TYPE_MODE: return "IL_TYPE_MODE";
00114 };
00115 return "unregonized";
00116 }
00117
00118 class ilImage
00119 {
00120 public:
00121 ilImage()
00122 {
00123 this->Id = 0;
00124
00125 this->iGenBind();
00126 return;
00127 }
00128
00129 ilImage(char *FileName)
00130 {
00131 this->Id = 0;
00132
00133 this->iGenBind();
00134 ilLoadImage(FileName);
00135 return;
00136 }
00137
00138 ilImage(const ilImage &Image)
00139 {
00140 this->Id = 0;
00141
00142 this->iGenBind();
00143 *this = Image;
00144 return;
00145 }
00146
00147 ~ilImage()
00148 {
00149 if (this->Id)
00150 ilDeleteImages(1, &this->Id);
00151 this->Id = 0;
00152 return;
00153 }
00154
00155 ILboolean Load(char *FileName)
00156 {
00157 this->iGenBind();
00158 return ilLoadImage(FileName);
00159 }
00160
00161 ILboolean Load(char *FileName, ILenum type)
00162 {
00163 this->iGenBind();
00164 return ilLoad(type, FileName);
00165 }
00166
00167 ILboolean Save(char *FileName)
00168 {
00169 this->iGenBind();
00170 return ilSaveImage(FileName);
00171 }
00172
00173 ILboolean Save(char *FileName, ILenum type)
00174 {
00175 this->iGenBind();
00176 return ilSave(type, FileName);
00177 }
00178
00180
00182
00183 ILboolean ActiveImage(ILuint Number)
00184 {
00185 if (this->Id) {
00186 this->Bind();
00187 return ilActiveImage(Number);
00188 }
00189 return IL_FALSE;
00190 }
00191
00192 ILboolean ActiveLayer(ILuint Number)
00193 {
00194 if (this->Id) {
00195 this->Bind();
00196 return ilActiveLayer(Number);
00197 }
00198 return IL_FALSE;
00199 }
00200
00201 ILboolean ActiveMipmap(ILuint Number)
00202 {
00203 if (this->Id) {
00204 this->Bind();
00205 return ilActiveMipmap(Number);
00206 }
00207 return IL_FALSE;
00208 }
00209
00210 ILboolean Clear()
00211 {
00212 if (this->Id) {
00213 this->Bind();
00214 return ilClearImage();
00215 }
00216 return IL_FALSE;
00217 }
00218
00219 void ClearColour(ILubyte Red, ILubyte Green, ILubyte Blue, ILubyte Alpha)
00220 {
00221 ilClearColour(Red, Green, Blue, Alpha);
00222 return;
00223 }
00224
00225 ILboolean Convert(ILenum NewFormat)
00226 {
00227 if (this->Id) {
00228 this->Bind();
00229 return ilConvertImage(NewFormat, IL_UNSIGNED_BYTE);
00230 }
00231 return IL_FALSE;
00232 }
00233
00234 ILboolean Copy(ILuint Src)
00235 {
00236 if (this->Id) {
00237 this->Bind();
00238 return ilCopyImage(Src);
00239 }
00240 return IL_FALSE;
00241 }
00242
00243 ILboolean Default()
00244 {
00245 if (this->Id) {
00246 this->Bind();
00247 return ilDefaultImage();
00248 }
00249 return IL_FALSE;
00250 }
00251
00252 ILboolean Flip()
00253 {
00254 if (this->Id) {
00255 this->Bind();
00256 return iluFlipImage();
00257 }
00258 return IL_FALSE;
00259 }
00260
00261 ILboolean SwapColours()
00262 {
00263 if (this->Id) {
00264 this->Bind();
00265 return iluSwapColours();
00266 }
00267 return IL_FALSE;
00268 }
00269
00270 ILboolean Resize(ILuint width, ILuint height, ILuint depth)
00271 {
00272 if (this->Id) {
00273 this->Bind();
00274 return iluScale(width, height, depth);
00275 }
00276 return IL_FALSE;
00277 }
00278
00279 ILboolean TexImage(ILuint width, ILuint height, ILuint depth, ILubyte bpp, ILenum format, ILenum type, void *data)
00280 {
00281 if (this->Id) {
00282 this->Bind();
00283 return ilTexImage(width, height, depth, bpp, format, type, data);
00284 }
00285 return IL_FALSE;
00286 }
00287
00289
00291
00292 void Bind() const
00293 {
00294 if (this->Id)
00295 ilBindImage(this->Id);
00296 return;
00297 }
00298
00299
00300 void Bind(ILuint Image)
00301 {
00302 if (this->Id == Image)
00303 return;
00304 this->Delete();
00305 this->Id = Image;
00306 ilBindImage(this->Id);
00307 return;
00308 }
00309
00310 void Delete()
00311 {
00312 if (this->Id == 0)
00313 return;
00314 ilDeleteImages(1, &this->Id);
00315 this->Id = 0;
00316 return;
00317 }
00318
00320
00322
00323 ILuint Width()
00324 {
00325 if (this->Id) {
00326 this->Bind();
00327 return ilGetInteger(IL_IMAGE_WIDTH);
00328 }
00329 return 0;
00330 }
00331
00332 ILuint Height()
00333 {
00334 if (this->Id) {
00335 this->Bind();
00336 return ilGetInteger(IL_IMAGE_HEIGHT);
00337 }
00338 return 0;
00339 }
00340
00341 ILuint Depth()
00342 {
00343 if (this->Id) {
00344 this->Bind();
00345 return ilGetInteger(IL_IMAGE_DEPTH);
00346 }
00347 return 0;
00348 }
00349
00350 ILubyte Bpp()
00351 {
00352 if (this->Id) {
00353 this->Bind();
00354 return static_cast<ILubyte>( ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL) );
00355 }
00356 return 0;
00357 }
00358
00359 ILubyte Bitpp()
00360 {
00361 if (this->Id) {
00362 this->Bind();
00363 return static_cast<ILubyte>( ilGetInteger(IL_IMAGE_BITS_PER_PIXEL) );
00364 }
00365 return 0;
00366 }
00367
00368 ILenum Format()
00369 {
00370 if (this->Id) {
00371 this->Bind();
00372 return ilGetInteger(IL_IMAGE_FORMAT);
00373 }
00374 return 0;
00375 }
00376
00377 ILenum PaletteType()
00378 {
00379 if (this->Id) {
00380 this->Bind();
00381 return ilGetInteger(IL_PALETTE_TYPE);
00382 }
00383 return 0;
00384 }
00385
00386 ILenum Type()
00387 {
00388 if (this->Id) {
00389 this->Bind();
00390 return ilGetInteger(IL_IMAGE_TYPE);
00391 }
00392 return 0;
00393 }
00394
00395 ILenum NumImages()
00396 {
00397 if (this->Id) {
00398 this->Bind();
00399 return ilGetInteger(IL_NUM_IMAGES);
00400 }
00401 return 0;
00402 }
00403
00404 ILenum NumMipmaps()
00405 {
00406 if (this->Id) {
00407 this->Bind();
00408 return ilGetInteger(IL_NUM_MIPMAPS);
00409 }
00410 return 0;
00411 }
00412
00413 ILuint GetId() const
00414 {
00415 return this->Id;
00416 }
00417
00418 ILenum GetOrigin()
00419 {
00420 ILinfo Info;
00421
00422 if (this->Id) {
00423 this->Bind();
00424 iluGetImageInfo(&Info);
00425 return Info.Origin;
00426 }
00427 return 0;
00428 }
00429
00430 ILubyte* GetData()
00431 {
00432 if (this->Id) {
00433 this->Bind();
00434 return ilGetData();
00435 }
00436 return 0;
00437 }
00438
00439 ILubyte* GetPalette()
00440 {
00441 if (this->Id) {
00442 this->Bind();
00443 return ilGetPalette();
00444 }
00445 return 0;
00446 }
00447
00448 void iGenBind()
00449 {
00450 if (this->Id == 0) {
00451 ilGenImages(1, &this->Id);
00452 }
00453 ilBindImage(this->Id);
00454 return;
00455 }
00456
00458
00460
00461 ilImage& operator = (ILuint Image)
00462 {
00463 if (this->Id == 0)
00464 this->Id = Image;
00465 else {
00466 this->Bind();
00467 ilCopyImage(Image);
00468 }
00469
00470 return *this;
00471 }
00472
00473 ilImage& operator = (const ilImage &Image)
00474 {
00475 if (Id == 0)
00476 Id = Image.GetId();
00477 else {
00478 Bind();
00479 ilCopyImage(Image.GetId());
00480 }
00481
00482 return *this;
00483 }
00484
00485 protected:
00486 ILuint Id;
00487
00488 private:
00490
00492
00493 void iStartUp()
00494 {
00495 ilInit();
00496 iluInit();
00497 ilutInit();
00498 return;
00499 }
00500
00501 };
00502
00503 class ilFilters
00504 {
00505 public:
00507
00509
00510 static ILboolean Alienify(ilImage &Image)
00511 {
00512 Image.Bind();
00513 return iluAlienify();
00514 }
00515
00516 static ILboolean BlurAvg(ilImage &Image, ILuint Iter)
00517 {
00518 Image.Bind();
00519 return iluBlurAvg(Iter);
00520 }
00521
00522 static ILboolean BlurGaussian(ilImage &Image, ILuint Iter)
00523 {
00524 Image.Bind();
00525 return iluBlurGaussian(Iter);
00526 }
00527
00528 static ILboolean Contrast(ilImage &Image, ILfloat Contrast)
00529 {
00530 Image.Bind();
00531 return iluContrast(Contrast);
00532 }
00533
00534 static ILboolean EdgeDetectE(ilImage &Image)
00535 {
00536 Image.Bind();
00537 return iluEdgeDetectP();
00538 }
00539
00540 static ILboolean EdgeDetectP(ilImage &Image)
00541 {
00542 Image.Bind();
00543 return iluEdgeDetectP();
00544 }
00545
00546 static ILboolean EdgeDetectS(ilImage &Image)
00547 {
00548 Image.Bind();
00549 return iluEdgeDetectS();
00550 }
00551
00552 static ILboolean Emboss(ilImage &Image)
00553 {
00554 Image.Bind();
00555 return iluEmboss();
00556 }
00557
00558 static ILboolean Gamma(ilImage &Image, ILfloat Gamma)
00559 {
00560 Image.Bind();
00561 return iluGammaCorrect(Gamma);
00562 }
00563
00564 static ILboolean Negative(ilImage &Image)
00565 {
00566 Image.Bind();
00567 return iluNegative();
00568 }
00569
00570 static ILboolean Noisify(ilImage &Image, ILubyte Factor)
00571 {
00572 Image.Bind();
00573 return iluNoisify(Factor);
00574 }
00575
00576 static ILboolean Pixelize(ilImage &Image, ILuint PixSize)
00577 {
00578 Image.Bind();
00579 return iluPixelize(PixSize);
00580 }
00581
00582 static ILboolean Saturate(ilImage &Image, ILfloat Saturation)
00583 {
00584 Image.Bind();
00585 return iluSaturate1f(Saturation);
00586 }
00587
00588 static ILboolean Saturate(ilImage &Image, ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation)
00589 {
00590 Image.Bind();
00591 return iluSaturate4f(r, g, b, Saturation);
00592 }
00593
00594 static ILboolean ScaleColours(ilImage &Image, ILfloat r, ILfloat g, ILfloat b)
00595 {
00596 Image.Bind();
00597 return iluScaleColours(r, g, b);
00598 }
00599
00600 static ILboolean Sharpen(ilImage &Image, ILfloat Factor, ILuint Iter)
00601 {
00602 Image.Bind();
00603 return iluSharpen(Factor, Iter);
00604 }
00605
00606 };
00607
00608
00609 #ifdef ILUT_USE_OPENGL
00610 class ilOgl
00611 {
00612 public:
00613 static void Init()
00614 {
00615 ilutRenderer(ILUT_OPENGL);
00616 return;
00617 }
00618
00619 static GLuint BindTex(ilImage &Image)
00620 {
00621 Image.Bind();
00622 return ilutGLBindTexImage();
00623 }
00624
00625 static ILboolean Upload(ilImage &Image, ILuint Level)
00626 {
00627 Image.Bind();
00628 return ilutGLTexImage(Level);
00629 }
00630
00631 static GLuint Mipmap(ilImage &Image)
00632 {
00633 Image.Bind();
00634 return ilutGLBuildMipmaps();
00635 }
00636
00637 static ILboolean Screen()
00638 {
00639 return ilutGLScreen();
00640 }
00641
00642 static ILboolean Screenie()
00643 {
00644 return ilutGLScreenie();
00645 }
00646 };
00647 #endif//ILUT_USE_OPENGL
00648
00649
00650 #ifdef ILUT_USE_ALLEGRO
00651 class ilAlleg
00652 {
00653 public:
00654 static void Init()
00655 {
00656 ilutRenderer(IL_ALLEGRO);
00657 return;
00658 }
00659
00660 static BITMAP * Convert(ilImage &Image, PALETTE Pal)
00661 {
00662 Image.Bind();
00663 return ilutConvertToAlleg(Pal);
00664 }
00665 };
00666 #endif//ILUT_USE_ALLEGRO
00667
00668
00669 #ifdef ILUT_USE_WIN32
00670 class ilWin32
00671 {
00672 public:
00673 static void Init()
00674 {
00675 ilutRenderer(ILUT_WIN32);
00676 return;
00677 }
00678
00679 static HBITMAP Convert(ilImage &Image)
00680 {
00681 Image.Bind();
00682 return ilutConvertToHBitmap(GetDC(NULL));
00683 }
00684
00685 static ILboolean GetClipboard(ilImage &Image)
00686 {
00687 Image.Bind();
00688 return ilutGetWinClipboard();
00689 }
00690
00691 static void GetInfo(ilImage &Image, BITMAPINFO *Info)
00692 {
00693 Image.Bind();
00694 ilutGetBmpInfo(Info);
00695 return;
00696 }
00697
00698 static ILubyte* GetPadData(ilImage &Image)
00699 {
00700 Image.Bind();
00701 return ilutGetPaddedData();
00702 }
00703
00704 static HPALETTE GetPal(ilImage &Image)
00705 {
00706 Image.Bind();
00707 return ilutGetHPal();
00708 }
00709
00710 static ILboolean GetResource(ilImage &Image, HINSTANCE hInst, ILint ID, char *ResourceType)
00711 {
00712 Image.Bind();
00713 return ilutLoadResource(hInst, ID, ResourceType, IL_TYPE_UNKNOWN);
00714 }
00715
00716 static ILboolean GetResource(ilImage &Image, HINSTANCE hInst, ILint ID, char *ResourceType, ILenum Type)
00717 {
00718 Image.Bind();
00719 return ilutLoadResource(hInst, ID, ResourceType, Type);
00720 }
00721
00722 static ILboolean SetClipboard(ilImage &Image)
00723 {
00724 Image.Bind();
00725 return ilutSetWinClipboard();
00726 }
00727 };
00728 #endif//ILUT_USE_WIN32
00729
00730
00731 class ilValidate
00732 {
00733 public:
00734 static ILboolean Valid(ILenum Type, char *FileName)
00735 {
00736 return ilIsValid(Type, FileName);
00737 }
00738
00739 static ILboolean Valid(ILenum Type, FILE *File)
00740 {
00741 return ilIsValidF(Type, File);
00742 }
00743
00744 static ILboolean Valid(ILenum Type, void *Lump, ILuint Size)
00745 {
00746 return ilIsValidL(Type, Lump, Size);
00747 }
00748
00749 protected:
00750
00751 private:
00752
00753 };
00754
00755
00756 class ilState
00757 {
00758 public:
00759 static ILboolean Disable(ILenum State)
00760 {
00761 return ilDisable(State);
00762 }
00763
00764 static ILboolean Enable(ILenum State)
00765 {
00766 return ilEnable(State);
00767 }
00768
00769 static void Get(ILenum Mode, ILboolean &Param)
00770 {
00771 ilGetBooleanv(Mode, &Param);
00772 return;
00773 }
00774
00775 static void Get(ILenum Mode, ILint &Param)
00776 {
00777 ilGetIntegerv(Mode, &Param);
00778 return;
00779 }
00780
00781 static ILboolean GetBool(ILenum Mode)
00782 {
00783 return ilGetBoolean(Mode);
00784 }
00785
00786 static ILint GetInt(ILenum Mode)
00787 {
00788 return ilGetInteger(Mode);
00789 }
00790
00791 static const char *GetString(ILenum StringName)
00792 {
00793 return ilGetString(StringName);
00794 }
00795
00796 static ILboolean IsDisabled(ILenum Mode)
00797 {
00798 return ilIsDisabled(Mode);
00799 }
00800
00801 static ILboolean IsEnabled(ILenum Mode)
00802 {
00803 return ilIsEnabled(Mode);
00804 }
00805
00806 static ILboolean Origin(ILenum Mode)
00807 {
00808 return ilOriginFunc(Mode);
00809 }
00810
00811 static void Pop()
00812 {
00813 ilPopAttrib();
00814 return;
00815 }
00816
00817 static void Push(ILuint Bits = IL_ALL_ATTRIB_BITS)
00818 {
00819 ilPushAttrib(Bits);
00820 return;
00821 }
00822
00823
00824 protected:
00825
00826 private:
00827
00828 };
00829
00830
00831 class ilError
00832 {
00833 public:
00834 static void Check(void (*Callback)(const char*))
00835 {
00836 static ILenum Error;
00837
00838 while ((Error = ilGetError()) != IL_NO_ERROR) {
00839 Callback(iluErrorString(Error));
00840 }
00841
00842 return;
00843 }
00844
00845 static void Check(void (*Callback)(ILenum))
00846 {
00847 static ILenum Error;
00848
00849 while ((Error = ilGetError()) != IL_NO_ERROR) {
00850 Callback(Error);
00851 }
00852
00853 return;
00854 }
00855
00856 static ILenum Get()
00857 {
00858 return ilGetError();
00859 }
00860
00861 static const char *String()
00862 {
00863 return iluErrorString(ilGetError());
00864 }
00865
00866 static const char *String(ILenum Error)
00867 {
00868 return iluErrorString(Error);
00869 }
00870
00871 protected:
00872
00873 private:
00874
00875 };
00876
00877 }
00878 }
00879 }
00880
00881
00882 #endif