Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/lcms2/utils/samples/roundtrip.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 // | |
| 2 // Little cms | |
| 3 // Copyright (C) 1998-2011 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 | |
| 22 #include "lcms2mt.h" | |
| 23 #include <math.h> | |
| 24 | |
| 25 | |
| 26 | |
| 27 static | |
| 28 double VecDist(cmsUInt8Number bin[3], cmsUInt8Number bout[3]) | |
| 29 { | |
| 30 double rdist, gdist, bdist; | |
| 31 | |
| 32 rdist = fabs((double) bout[0] - bin[0]); | |
| 33 gdist = fabs((double) bout[1] - bin[1]); | |
| 34 bdist = fabs((double) bout[2] - bin[2]); | |
| 35 | |
| 36 return (sqrt((rdist*rdist + gdist*gdist + bdist*bdist))); | |
| 37 } | |
| 38 | |
| 39 | |
| 40 int main(int argc, char* argv[]) | |
| 41 { | |
| 42 | |
| 43 int r, g, b; | |
| 44 cmsUInt8Number RGB[3], RGB_OUT[3]; | |
| 45 cmsHTRANSFORM xform; | |
| 46 cmsHPROFILE hProfile; | |
| 47 double err, SumX=0, SumX2=0, Peak = 0, n = 0; | |
| 48 | |
| 49 | |
| 50 if (argc != 2) { | |
| 51 printf("roundtrip <RGB icc profile>\n"); | |
| 52 return 1; | |
| 53 } | |
| 54 | |
| 55 hProfile = cmsOpenProfileFromFile(argv[1], "r"); | |
| 56 if (hProfile == NULL) | |
| 57 { | |
| 58 printf("invalid profile\n"); | |
| 59 return 1; | |
| 60 } | |
| 61 | |
| 62 xform = cmsCreateTransform(hProfile,TYPE_RGB_8, hProfile, TYPE_RGB_8, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE); | |
| 63 if (xform == NULL) | |
| 64 { | |
| 65 printf("Not a valid RGB profile\n"); | |
| 66 return 1; | |
| 67 } | |
| 68 | |
| 69 for (r=0; r< 256; r++) { | |
| 70 printf("%d \r", r); | |
| 71 for (g=0; g < 256; g++) { | |
| 72 for (b=0; b < 256; b++) { | |
| 73 | |
| 74 RGB[0] = r; | |
| 75 RGB[1] = g; | |
| 76 RGB[2] = b; | |
| 77 | |
| 78 cmsDoTransform(xform, RGB, RGB_OUT, 1); | |
| 79 | |
| 80 err = VecDist(RGB, RGB_OUT); | |
| 81 | |
| 82 SumX += err; | |
| 83 SumX2 += err * err; | |
| 84 n += 1.0; | |
| 85 if (err > Peak) | |
| 86 Peak = err; | |
| 87 | |
| 88 } | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 printf("Average %g\n", SumX / n); | |
| 93 printf("Max %g\n", Peak); | |
| 94 printf("Std %g\n", sqrt((n*SumX2 - SumX * SumX) / (n*(n-1)))); | |
| 95 cmsCloseProfile(hProfile); | |
| 96 cmsDeleteTransform(xform); | |
| 97 | |
| 98 return 0; | |
| 99 } |
