- Main Page
- Data Structures
- Files

- File List

# E:/DevIL/src-IL/src/il_profiles.c

    00001 //-----------------------------------------------------------------------------
    00002 //
    00003 // ImageLib Sources
    00004 // Copyright (C) 2000-2002 by Denton Woods
    00005 // Last modified: 01/23/2001 <--Y2K Compliant! =]
    00006 //
    00007 // Filename: src-IL/src/il_profiles.c
    00008 //
    00009 // Description: Colour profile handler
    00010 //
    00011 //-----------------------------------------------------------------------------
    00012
    00013 #include "il_internal.h"
    00014 #ifndef IL_NO_LCMS
    00015
    00016 #ifdef PACKAGE_NAME
    00017 #define IL_PACKAGE_NAME PACKAGE_NAME;
    00018 #undef  PACKAGE_NAME
    00019 #endif
    00020
    00021 #if (!defined(_WIN32) && !defined(_WIN64))
    00022         #define NON_WINDOWS 1
    00023         #ifdef LCMS_NODIRINCLUDE
    00024                 #include <lcms.h>
    00025         #else
    00026                 #include <lcms/lcms.h>
    00027         #endif
    00028
    00029 #else
    00030         #if defined(IL_USE_PRAGMA_LIBS)
    00031                 #if defined(_MSC_VER) || defined(__BORLANDC__)
    00032                         #ifndef _DEBUG
    00033                                 #pragma comment(lib, "lcms.lib")
    00034                         #else
    00035                                 #pragma comment(lib, "lcms-d.lib")
    00036                         #endif
    00037                 #endif
    00038         #endif
    00039
    00040         #include <lcms.h>
    00041 #endif//_WIN32
    00042
    00043 #ifdef PACKAGE_NAME
    00044 #undef PACKAGE_NAME
    00045 #endif
    00046
    00047 #ifdef IL_PACKAGE_NAME
    00048 #define PACKAGE_NAME IL_PACKAGE_NAME
    00049 #undef  IL_PACKAGE_NAME
    00050 #endif
    00051
    00052 #endif//IL_NO_LCMS
    00053
    00054 ILboolean ILAPIENTRY ilApplyProfile(ILstring InProfile, ILstring OutProfile)
    00055 {
    00056 #ifndef IL_NO_LCMS
    00057         cmsHPROFILE             hInProfile, hOutProfile;
    00058         cmsHTRANSFORM   hTransform;
    00059         ILubyte                 *Temp;
    00060         ILint                   Format=0;
    00061 #ifdef _UNICODE
    00062         char AnsiName[512];
    00063 #endif//_UNICODE
    00064
    00065         if (iCurImage == NULL) {
    00066                 ilSetError(IL_ILLEGAL_OPERATION);
    00067                 return IL_FALSE;
    00068         }
    00069
    00070         switch (iCurImage->Type)
    00071         {
    00072                 case IL_BYTE:
    00073                 case IL_UNSIGNED_BYTE:
    00074                         switch (iCurImage->Format)
    00075                         {
    00076                                 case IL_LUMINANCE:
    00077                                         Format = TYPE_GRAY_8;
    00078                                         break;
    00079                                 case IL_RGB:
    00080                                         Format = TYPE_RGB_8;
    00081                                         break;
    00082                                 case IL_BGR:
    00083                                         Format = TYPE_BGR_8;
    00084                                         break;
    00085                                 case IL_RGBA:
    00086                                         Format = TYPE_RGBA_8;
    00087                                         break;
    00088                                 case IL_BGRA:
    00089                                         Format = TYPE_BGRA_8;
    00090                                         break;
    00091                                 default:
    00092                                         ilSetError(IL_INTERNAL_ERROR);
    00093                                         return IL_FALSE;
    00094                         }
    00095                         break;
    00096
    00097                 case IL_SHORT:
    00098                 case IL_UNSIGNED_SHORT:
    00099                         switch (iCurImage->Format)
    00100                         {
    00101                                 case IL_LUMINANCE:
    00102                                         Format = TYPE_GRAY_16;
    00103                                         break;
    00104                                 case IL_RGB:
    00105                                         Format = TYPE_RGB_16;
    00106                                         break;
    00107                                 case IL_BGR:
    00108                                         Format = TYPE_BGR_16;
    00109                                         break;
    00110                                 case IL_RGBA:
    00111                                         Format = TYPE_RGBA_16;
    00112                                         break;
    00113                                 case IL_BGRA:
    00114                                         Format = TYPE_BGRA_16;
    00115                                         break;
    00116                                 default:
    00117                                         ilSetError(IL_INTERNAL_ERROR);
    00118                                         return IL_FALSE;
    00119                         }
    00120                         break;
    00121
    00122                 // These aren't supported right now.
    00123                 case IL_INT:
    00124                 case IL_UNSIGNED_INT:
    00125                 case IL_FLOAT:
    00126                 case IL_DOUBLE:
    00127                         ilSetError(IL_ILLEGAL_OPERATION);
    00128                         return IL_FALSE;
    00129         }
    00130
    00131
    00132         if (InProfile == NULL) {
    00133                 if (!iCurImage->Profile || !iCurImage->ProfileSize) {
    00134                         ilSetError(IL_INVALID_PARAM);
    00135                         return IL_FALSE;
    00136                 }
    00137                 hInProfile = iCurImage->Profile;
    00138         }
    00139         else {
    00140 #ifndef _UNICODE
    00141                 hInProfile = cmsOpenProfileFromFile(InProfile, "r");
    00142 #else
    00143                 wcstombs(AnsiName, InProfile, 512);
    00144                 hInProfile = cmsOpenProfileFromFile(AnsiName, "r");
    00145 #endif//_UNICODE
    00146         }
    00147 #ifndef _UNICODE
    00148         hOutProfile = cmsOpenProfileFromFile(OutProfile, "r");
    00149 #else
    00150         wcstombs(AnsiName, OutProfile, 512);
    00151         hOutProfile = cmsOpenProfileFromFile(AnsiName, "r");
    00152 #endif//_UNICODE
    00153
    00154         hTransform = cmsCreateTransform(hInProfile, Format, hOutProfile, Format, INTENT_PERCEPTUAL, 0);
    00155
    00156         Temp = (ILubyte*)ialloc(iCurImage->SizeOfData);
    00157         if (Temp == NULL) {
    00158                 return IL_FALSE;
    00159         }
    00160
    00161         cmsDoTransform(hTransform, iCurImage->Data, Temp, iCurImage->SizeOfData / 3);
    00162
    00163         ifree(iCurImage->Data);
    00164         iCurImage->Data = Temp;
    00165
    00166         cmsDeleteTransform(hTransform);
    00167         if (InProfile != NULL)
    00168                 cmsCloseProfile(hInProfile);
    00169         cmsCloseProfile(hOutProfile);
    00170
    00171 #endif//IL_NO_LCMS
    00172
    00173         return IL_TRUE;
    00174 }