wtpt.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // Little cms
  3. // Copyright (C) 1998-2015 Marti Maria
  4. //
  5. //---------------------------------------------------------------------------------
  6. //
  7. // Little Color Management System
  8. // Copyright (c) 1998-2014 Marti Maria Saguer
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the "Software"),
  12. // to deal in the Software without restriction, including without limitation
  13. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14. // and/or sell copies of the Software, and to permit persons to whom the Software
  15. // is furnished to do so, subject to the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be included in
  18. // all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  22. // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. //---------------------------------------------------------------------------------
  29. #include "utils.h"
  30. // The toggles stuff
  31. static cmsBool lShowXYZ = TRUE;
  32. static cmsBool lShowLab = FALSE;
  33. static cmsBool lShowLCh = FALSE;
  34. static
  35. void HandleSwitches(int argc, char *argv[])
  36. {
  37. int s;
  38. while ((s = xgetopt(argc, argv, "lcx")) != EOF) {
  39. switch (s){
  40. case 'l':
  41. lShowLab = TRUE;
  42. break;
  43. case 'c':
  44. lShowLCh = TRUE;
  45. break;
  46. case 'x':
  47. lShowXYZ = FALSE;
  48. break;
  49. default:
  50. FatalError("Unknown option - run without args to see valid ones.\n");
  51. }
  52. }
  53. }
  54. static
  55. void Help(void)
  56. {
  57. fprintf(stderr, "little CMS ICC white point utility - v3 [LittleCMS %2.2f]\n", LCMS_VERSION / 1000.0);
  58. fprintf(stderr, "usage: wtpt [flags] [<ICC profile>]\n\n");
  59. fprintf(stderr, "flags:\n\n");
  60. fprintf(stderr, "%cl - CIE Lab\n", SW);
  61. fprintf(stderr, "%cc - CIE LCh\n", SW);
  62. fprintf(stderr, "%cx - Don't show XYZ\n", SW);
  63. fprintf(stderr, "\nIf no parameters are given, then this program will\n");
  64. fprintf(stderr, "ask for XYZ value of media white. If parameter given, it must be\n");
  65. fprintf(stderr, "the profile to inspect.\n\n");
  66. fprintf(stderr, "This program is intended to be a demo of the little cms\n"
  67. "engine. Both lcms and this program are freeware. You can\n"
  68. "obtain both in source code at http://www.littlecms.com\n"
  69. "For suggestions, comments, bug reports etc. send mail to\n"
  70. "[email protected]\n\n");
  71. exit(0);
  72. }
  73. static
  74. void ShowWhitePoint(cmsCIEXYZ* WtPt)
  75. {
  76. cmsCIELab Lab;
  77. cmsCIELCh LCh;
  78. cmsCIExyY xyY;
  79. cmsXYZ2Lab(NULL, &Lab, WtPt);
  80. cmsLab2LCh(&LCh, &Lab);
  81. cmsXYZ2xyY(&xyY, WtPt);
  82. if (lShowXYZ) printf("XYZ=(%3.1f, %3.1f, %3.1f)\n", WtPt->X, WtPt->Y, WtPt->Z);
  83. if (lShowLab) printf("Lab=(%3.3f, %3.3f, %3.3f)\n", Lab.L, Lab.a, Lab.b);
  84. if (lShowLCh) printf("LCh=(%3.3f, %3.3f, %3.3f)\n", LCh.L, LCh.C, LCh.h);
  85. {
  86. double Ssens = (LCh.C * 100.0 )/ sqrt(LCh.C*LCh.C + LCh.L * LCh.L) ;
  87. printf("Sens = %f\n", Ssens);
  88. }
  89. }
  90. int main(int argc, char *argv[])
  91. {
  92. int nargs;
  93. InitUtils("wtpt");
  94. HandleSwitches(argc, argv);
  95. nargs = (argc - xoptind);
  96. if (nargs != 1)
  97. Help();
  98. else {
  99. cmsCIEXYZ* WtPt;
  100. cmsHPROFILE hProfile = cmsOpenProfileFromFile(argv[xoptind], "r");
  101. if (hProfile == NULL) return 1;
  102. WtPt = cmsReadTag(hProfile, cmsSigMediaWhitePointTag);
  103. ShowWhitePoint(WtPt);
  104. cmsCloseProfile(hProfile);
  105. }
  106. return 0;
  107. }