Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/lcms2/utils/samples/mkcmy.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-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 // THIS SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, | |
| 16 // EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY | |
| 17 // WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. | |
| 18 // | |
| 19 // IN NO EVENT SHALL MARTI MARIA BE LIABLE FOR ANY SPECIAL, INCIDENTAL, | |
| 20 // INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, | |
| 21 // OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
| 22 // WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF | |
| 23 // LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | |
| 24 // OF THIS SOFTWARE. | |
| 25 // | |
| 26 // Version 1.12 | |
| 27 | |
| 28 | |
| 29 #include "lcms.h" | |
| 30 | |
| 31 | |
| 32 typedef struct { | |
| 33 cmsHPROFILE hLab; | |
| 34 cmsHPROFILE hRGB; | |
| 35 cmsHTRANSFORM Lab2RGB; | |
| 36 cmsHTRANSFORM RGB2Lab; | |
| 37 | |
| 38 } CARGO, FAR* LPCARGO; | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 // Our space will be CIE primaries plus a gamma of 4.5 | |
| 45 | |
| 46 static | |
| 47 int Forward(register WORD In[], register WORD Out[], register LPVOID Cargo) | |
| 48 { | |
| 49 LPCARGO C = (LPCARGO) Cargo; | |
| 50 WORD RGB[3]; | |
| 51 cmsCIELab Lab; | |
| 52 | |
| 53 cmsLabEncoded2Float(&Lab, In); | |
| 54 | |
| 55 printf("%g %g %g\n", Lab.L, Lab.a, Lab.b); | |
| 56 | |
| 57 cmsDoTransform(C ->Lab2RGB, In, &RGB, 1); | |
| 58 | |
| 59 | |
| 60 Out[0] = 0xFFFF - RGB[0]; // Our CMY is negative of RGB | |
| 61 Out[1] = 0xFFFF - RGB[1]; | |
| 62 Out[2] = 0xFFFF - RGB[2]; | |
| 63 | |
| 64 | |
| 65 return TRUE; | |
| 66 | |
| 67 } | |
| 68 | |
| 69 | |
| 70 static | |
| 71 int Reverse(register WORD In[], register WORD Out[], register LPVOID Cargo) | |
| 72 { | |
| 73 | |
| 74 LPCARGO C = (LPCARGO) Cargo; | |
| 75 WORD RGB[3]; | |
| 76 | |
| 77 RGB[0] = 0xFFFF - In[0]; | |
| 78 RGB[1] = 0xFFFF - In[1]; | |
| 79 RGB[2] = 0xFFFF - In[2]; | |
| 80 | |
| 81 cmsDoTransform(C ->RGB2Lab, &RGB, Out, 1); | |
| 82 | |
| 83 return TRUE; | |
| 84 | |
| 85 } | |
| 86 | |
| 87 | |
| 88 | |
| 89 static | |
| 90 void InitCargo(LPCARGO Cargo) | |
| 91 { | |
| 92 | |
| 93 | |
| 94 Cargo -> hLab = cmsCreateLabProfile(NULL); | |
| 95 Cargo -> hRGB = cmsCreate_sRGBProfile(); | |
| 96 | |
| 97 Cargo->Lab2RGB = cmsCreateTransform(Cargo->hLab, TYPE_Lab_16, | |
| 98 Cargo ->hRGB, TYPE_RGB_16, | |
| 99 INTENT_RELATIVE_COLORIMETRIC, | |
| 100 cmsFLAGS_NOTPRECALC); | |
| 101 | |
| 102 Cargo->RGB2Lab = cmsCreateTransform(Cargo ->hRGB, TYPE_RGB_16, | |
| 103 Cargo ->hLab, TYPE_Lab_16, | |
| 104 INTENT_RELATIVE_COLORIMETRIC, | |
| 105 cmsFLAGS_NOTPRECALC); | |
| 106 } | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 static | |
| 112 void FreeCargo(LPCARGO Cargo) | |
| 113 { | |
| 114 cmsDeleteTransform(Cargo ->Lab2RGB); | |
| 115 cmsDeleteTransform(Cargo ->RGB2Lab); | |
| 116 cmsCloseProfile(Cargo ->hLab); | |
| 117 cmsCloseProfile(Cargo ->hRGB); | |
| 118 } | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 int main(void) | |
| 124 { | |
| 125 LPLUT AToB0, BToA0; | |
| 126 CARGO Cargo; | |
| 127 cmsHPROFILE hProfile; | |
| 128 | |
| 129 fprintf(stderr, "Creating lcmscmy.icm..."); | |
| 130 | |
| 131 InitCargo(&Cargo); | |
| 132 | |
| 133 hProfile = cmsCreateLabProfile(NULL); | |
| 134 | |
| 135 | |
| 136 AToB0 = cmsAllocLUT(); | |
| 137 BToA0 = cmsAllocLUT(); | |
| 138 | |
| 139 cmsAlloc3DGrid(AToB0, 25, 3, 3); | |
| 140 cmsAlloc3DGrid(BToA0, 25, 3, 3); | |
| 141 | |
| 142 | |
| 143 cmsSample3DGrid(AToB0, Reverse, &Cargo, 0); | |
| 144 cmsSample3DGrid(BToA0, Forward, &Cargo, 0); | |
| 145 | |
| 146 | |
| 147 cmsAddTag(hProfile, icSigAToB0Tag, AToB0); | |
| 148 cmsAddTag(hProfile, icSigBToA0Tag, BToA0); | |
| 149 | |
| 150 cmsSetColorSpace(hProfile, icSigCmyData); | |
| 151 cmsSetDeviceClass(hProfile, icSigOutputClass); | |
| 152 | |
| 153 cmsAddTag(hProfile, icSigProfileDescriptionTag, "CMY "); | |
| 154 cmsAddTag(hProfile, icSigCopyrightTag, "Copyright (c) HP, 2007. All rights reserved."); | |
| 155 cmsAddTag(hProfile, icSigDeviceMfgDescTag, "Little cms"); | |
| 156 cmsAddTag(hProfile, icSigDeviceModelDescTag, "CMY space"); | |
| 157 | |
| 158 _cmsSaveProfile(hProfile, "lcmscmy.icm"); | |
| 159 | |
| 160 | |
| 161 cmsFreeLUT(AToB0); | |
| 162 cmsFreeLUT(BToA0); | |
| 163 cmsCloseProfile(hProfile); | |
| 164 FreeCargo(&Cargo); | |
| 165 fprintf(stderr, "Done.\n"); | |
| 166 | |
| 167 | |
| 168 | |
| 169 return 0; | |
| 170 } |
