Test initialisation of MUIA_List_AdjustWidth and MUIA_List_AdjustHeight, and
[AROS.git] / workbench / libs / lcms2 / utils / samples / itufax.c
blob79c7c4400a173557656b42a151c6505e189187e2
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:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
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.
24 #include "lcms.h"
26 // This is a sample on how to build a profile for decoding ITU T.42/Fax JPEG
27 // streams. The profile has an additional ability in the input direction of
28 // gamut compress values between 85 < a < -85 and -75 < b < 125. This conforms
29 // the default range for ITU/T.42 -- See RFC 2301, section 6.2.3 for details
32 // L* = [0, 100]
33 // a* = [–85, 85]
34 // b* = [–75, 125]
37 // These functions does convert the encoding of ITUFAX to floating point
39 static
40 void ITU2Lab(WORD In[3], LPcmsCIELab Lab)
42 Lab -> L = (double) In[0] / 655.35;
43 Lab -> a = (double) 170.* (In[1] - 32768.) / 65535.;
44 Lab -> b = (double) 200.* (In[2] - 24576.) / 65535.;
48 static
49 void Lab2ITU(LPcmsCIELab Lab, WORD Out[3])
51 Out[0] = (WORD) floor((double) (Lab -> L / 100.)* 65535. + 0.5);
52 Out[1] = (WORD) floor((double) (Lab -> a / 170.)* 65535. + 32768. + 0.5);
53 Out[2] = (WORD) floor((double) (Lab -> b / 200.)* 65535. + 24576. + 0.5);
57 // These are the samplers-- They are passed as callbacks to cmsSample3DGrid()
58 // then, cmsSample3DGrid() will sweel whole Lab gamut calling these functions
59 // once for each node. In[] will contain the Lab PCS value to convert to ITUFAX
60 // on InputDirection, or the ITUFAX value to convert to Lab in OutputDirection
61 // You can change the number of sample points if desired, the algorithm will
62 // remain same. 33 points gives good accurancy, but you can reduce to 22 or less
63 // is space is critical
65 #define GRID_POINTS 33
67 static
68 int InputDirection(register WORD In[], register WORD Out[], register LPVOID Cargo)
70 cmsCIELab Lab;
72 cmsLabEncoded2Float(&Lab, In);
73 cmsClampLab(&Lab, 85, -85, 125, -75); // This function does the necessary gamut remapping
74 Lab2ITU(&Lab, Out);
76 return TRUE;
80 static
81 int OutputDirection(register WORD In[], register WORD Out[], register LPVOID Cargo)
84 cmsCIELab Lab;
86 ITU2Lab(In, &Lab);
87 cmsFloat2LabEncoded(Out, &Lab);
89 return TRUE;
93 // The main entry point. Just create a profile an populate it with required tags.
94 // note that cmsOpenProfileFromFile("itufax.icm", "w") will NOT delete the file
95 // if already exists. This is for obvious safety reasons.
98 int main(int argc, char *argv[])
100 LPLUT AToB0, BToA0;
101 cmsHPROFILE hProfile;
103 fprintf(stderr, "Creating itufax.icm...");
105 unlink("itufax.icm");
106 hProfile = cmsOpenProfileFromFile("itufax.icm", "w");
108 AToB0 = cmsAllocLUT();
109 BToA0 = cmsAllocLUT();
111 cmsAlloc3DGrid(AToB0, GRID_POINTS, 3, 3);
112 cmsAlloc3DGrid(BToA0, GRID_POINTS, 3, 3);
114 cmsSample3DGrid(AToB0, InputDirection, NULL, 0);
115 cmsSample3DGrid(BToA0, OutputDirection, NULL, 0);
117 cmsAddTag(hProfile, icSigAToB0Tag, AToB0);
118 cmsAddTag(hProfile, icSigBToA0Tag, BToA0);
121 cmsSetColorSpace(hProfile, icSigLabData);
122 cmsSetPCS(hProfile, icSigLabData);
123 cmsSetDeviceClass(hProfile, icSigColorSpaceClass);
125 cmsAddTag(hProfile, icSigProfileDescriptionTag, "ITU T.42/Fax JPEG CIEL*a*b*");
126 cmsAddTag(hProfile, icSigCopyrightTag, "No Copyright, use freely.");
127 cmsAddTag(hProfile, icSigDeviceMfgDescTag, "Little cms");
128 cmsAddTag(hProfile, icSigDeviceModelDescTag, "ITU T.42/Fax JPEG CIEL*a*b*");
130 cmsCloseProfile(hProfile);
132 cmsFreeLUT(AToB0);
133 cmsFreeLUT(BToA0);
135 fprintf(stderr, "Done.\n");
137 return 0;