mkgrayer.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Little cms
  3. // Copyright (C) 1998-2003 Marti Maria
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining
  6. // a copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the Software
  10. // is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  17. // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #include "lcms.h"
  23. static
  24. int Forward(register WORD In[], register WORD Out[], register LPVOID Cargo)
  25. {
  26. cmsCIELab Lab;
  27. cmsLabEncoded2Float(&Lab, In);
  28. if (fabs(Lab.a) < 3 && fabs(Lab.b) < 3) {
  29. double L_01 = Lab.L / 100.0;
  30. WORD K;
  31. if (L_01 > 1) L_01 = 1;
  32. K = (WORD) floor(L_01* 65535.0 + 0.5);
  33. Out[0] = Out[1] = Out[2] = K;
  34. }
  35. else {
  36. Out[0] = 0xFFFF; Out[1] = 0; Out[2] = 0;
  37. }
  38. return TRUE;
  39. }
  40. int main(int argc, char *argv[])
  41. {
  42. LPLUT BToA0;
  43. cmsHPROFILE hProfile;
  44. fprintf(stderr, "Creating interpol2.icc...");
  45. unlink("interpol2.icc");
  46. hProfile = cmsOpenProfileFromFile("interpol2.icc", "w8");
  47. BToA0 = cmsAllocLUT();
  48. cmsAlloc3DGrid(BToA0, 17, 3, 3);
  49. cmsSample3DGrid(BToA0, Forward, NULL, 0);
  50. cmsAddTag(hProfile, icSigBToA0Tag, BToA0);
  51. cmsSetColorSpace(hProfile, icSigRgbData);
  52. cmsSetPCS(hProfile, icSigLabData);
  53. cmsSetDeviceClass(hProfile, icSigOutputClass);
  54. cmsAddTag(hProfile, icSigProfileDescriptionTag, "Interpolation test");
  55. cmsAddTag(hProfile, icSigCopyrightTag, "Copyright (c) HP 2007. All rights reserved.");
  56. cmsAddTag(hProfile, icSigDeviceMfgDescTag, "Little cms");
  57. cmsAddTag(hProfile, icSigDeviceModelDescTag, "Interpolation test profile");
  58. cmsCloseProfile(hProfile);
  59. cmsFreeLUT(BToA0);
  60. fprintf(stderr, "Done.\n");
  61. return 0;
  62. }