il_profiles.c
Upload User: wmy0603
Upload Date: 2022-05-02
Package Size: 1808k
Code Size: 3k
Development Platform:

Visual C++

  1. //-----------------------------------------------------------------------------
  2. //
  3. // ImageLib Sources
  4. // Copyright (C) 2000-2002 by Denton Woods
  5. // Last modified: 01/23/2001 <--Y2K Compliant! =]
  6. //
  7. // Filename: src-IL/src/il_profiles.c
  8. //
  9. // Description: Colour profile handler
  10. //
  11. //-----------------------------------------------------------------------------
  12. #include "il_internal.h"
  13. #ifndef IL_NO_LCMS
  14. #ifdef PACKAGE_NAME
  15. #define IL_PACKAGE_NAME PACKAGE_NAME;
  16. #undef  PACKAGE_NAME
  17. #endif
  18. #if (!defined(_WIN32) && !defined(_WIN64))
  19. #define NON_WINDOWS 1
  20. #ifdef LCMS_NODIRINCLUDE
  21. #include <lcms.h>
  22. #else
  23. #include <lcms/lcms.h>
  24. #endif
  25. #else
  26. #if defined(IL_USE_PRAGMA_LIBS)
  27. #if defined(_MSC_VER) || defined(__BORLANDC__)
  28. #ifndef _DEBUG
  29. #pragma comment(lib, "lcms.lib")
  30. #else
  31. #pragma comment(lib, "lcms-d.lib")
  32. #endif
  33. #endif
  34. #endif
  35. #include <lcms.h>
  36. #endif//_WIN32
  37. #ifdef PACKAGE_NAME
  38. #undef PACKAGE_NAME
  39. #endif
  40. #ifdef IL_PACKAGE_NAME
  41. #define PACKAGE_NAME IL_PACKAGE_NAME
  42. #undef  IL_PACKAGE_NAME
  43. #endif
  44. #endif//IL_NO_LCMS
  45. ILboolean ILAPIENTRY ilApplyProfile(ILstring InProfile, ILstring OutProfile)
  46. {
  47. #ifndef IL_NO_LCMS
  48. cmsHPROFILE hInProfile, hOutProfile;
  49. cmsHTRANSFORM hTransform;
  50. ILubyte *Temp;
  51. ILint Format=0;
  52. #ifdef _UNICODE
  53. char AnsiName[512];
  54. #endif//_UNICODE
  55. if (iCurImage == NULL) {
  56. ilSetError(IL_ILLEGAL_OPERATION);
  57. return IL_FALSE;
  58. }
  59. switch (iCurImage->Type)
  60. {
  61. case IL_BYTE:
  62. case IL_UNSIGNED_BYTE:
  63. switch (iCurImage->Format)
  64. {
  65. case IL_LUMINANCE:
  66. Format = TYPE_GRAY_8;
  67. break;
  68. case IL_RGB:
  69. Format = TYPE_RGB_8;
  70. break;
  71. case IL_BGR:
  72. Format = TYPE_BGR_8;
  73. break;
  74. case IL_RGBA:
  75. Format = TYPE_RGBA_8;
  76. break;
  77. case IL_BGRA:
  78. Format = TYPE_BGRA_8;
  79. break;
  80. default:
  81. ilSetError(IL_INTERNAL_ERROR);
  82. return IL_FALSE;
  83. }
  84. break;
  85. case IL_SHORT:
  86. case IL_UNSIGNED_SHORT:
  87. switch (iCurImage->Format)
  88. {
  89. case IL_LUMINANCE:
  90. Format = TYPE_GRAY_16;
  91. break;
  92. case IL_RGB:
  93. Format = TYPE_RGB_16;
  94. break;
  95. case IL_BGR:
  96. Format = TYPE_BGR_16;
  97. break;
  98. case IL_RGBA:
  99. Format = TYPE_RGBA_16;
  100. break;
  101. case IL_BGRA:
  102. Format = TYPE_BGRA_16;
  103. break;
  104. default:
  105. ilSetError(IL_INTERNAL_ERROR);
  106. return IL_FALSE;
  107. }
  108. break;
  109. // These aren't supported right now.
  110. case IL_INT:
  111. case IL_UNSIGNED_INT:
  112. case IL_FLOAT:
  113. case IL_DOUBLE:
  114. ilSetError(IL_ILLEGAL_OPERATION);
  115. return IL_FALSE;
  116. }
  117. if (InProfile == NULL) {
  118. if (!iCurImage->Profile || !iCurImage->ProfileSize) {
  119. ilSetError(IL_INVALID_PARAM);
  120. return IL_FALSE;
  121. }
  122. hInProfile = iCurImage->Profile;
  123. }
  124. else {
  125. #ifndef _UNICODE
  126.   hInProfile = cmsOpenProfileFromFile(InProfile, "r");
  127. #else
  128. wcstombs(AnsiName, InProfile, 512);
  129. hInProfile = cmsOpenProfileFromFile(AnsiName, "r");
  130. #endif//_UNICODE
  131. }
  132. #ifndef _UNICODE
  133.   hOutProfile = cmsOpenProfileFromFile(OutProfile, "r");
  134. #else
  135. wcstombs(AnsiName, OutProfile, 512);
  136. hOutProfile = cmsOpenProfileFromFile(AnsiName, "r");
  137. #endif//_UNICODE
  138. hTransform = cmsCreateTransform(hInProfile, Format, hOutProfile, Format, INTENT_PERCEPTUAL, 0);
  139. Temp = (ILubyte*)ialloc(iCurImage->SizeOfData);
  140. if (Temp == NULL) {
  141. return IL_FALSE;
  142. }
  143. cmsDoTransform(hTransform, iCurImage->Data, Temp, iCurImage->SizeOfData / 3);
  144. ifree(iCurImage->Data);
  145. iCurImage->Data = Temp;
  146. cmsDeleteTransform(hTransform);
  147. if (InProfile != NULL)
  148. cmsCloseProfile(hInProfile);
  149. cmsCloseProfile(hOutProfile);
  150. #endif//IL_NO_LCMS
  151. return IL_TRUE;
  152. }