Subversion Repositories Scribus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2454 craig 1
//
2
//  Little cms - profiler construction set
3
//  Copyright (C) 1998-2001 Marti Maria
4
//
5
// THIS SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
6
// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
7
// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
8
//
9
// IN NO EVENT SHALL MARTI MARIA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
10
// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
11
// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
12
// WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
13
// LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
14
// OF THIS SOFTWARE.
15
//
16
// This file is free software; you can redistribute it and/or modify it
17
// under the terms of the GNU General Public License as published by
18
// the Free Software Foundation; either version 2 of the License, or
19
// (at your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but
22
// WITHOUT ANY WARRANTY; without even the implied warranty of
23
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24
// General Public License for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with this program; if not, write to the Free Software
28
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
//
30
// As a special exception to the GNU General Public License, if you
31
// distribute this file as part of a program that contains a
32
// configuration script generated by Autoconf, you may include it under
33
// the same distribution terms that you use for the rest of that program.
34
//
35
// Version 1.09a
36
 
37
#ifndef __cmsprf_H
38
 
39
#include "lcms.h"
40
#include <ctype.h>
41
#include <limits.h>
42
#include <stdarg.h>
43
#include <sys/stat.h>
44
 
45
 
46
#ifdef __cplusplus
47
extern "C" {
48
#endif
49
 
50
#ifdef NON_WINDOWS
51
#  ifndef stricmp
52
#     define stricmp strcasecmp
53
#  endif
54
#endif
55
 
56
#ifndef max
57
#define max(a,b) ((a) > (b)?(a):(b))
58
#endif
59
 
60
 
61
// Matrix operations - arbitrary size -----------------------------------------------------
62
 
63
typedef struct {
64
 
65
    int       Cols, Rows;
66
    double**  Values;
67
 
68
    } MATN,FAR* LPMATN;
69
 
70
 
71
LPMATN      cdecl MATNalloc(int Rows, int Cols);
72
void        cdecl MATNfree (LPMATN mat);
73
LPMATN      cdecl MATNmult(LPMATN a1, LPMATN a2);
74
double      cdecl MATNcross(LPMATN a);
75
void        cdecl MATNscalar (LPMATN a, double scl, LPMATN b);
76
LPMATN      cdecl MATNtranspose (LPMATN a);
77
BOOL        cdecl MATNsolve(LPMATN a, LPMATN b);
78
 
79
 
80
// IT8.7 / CGATS.17-200x handling --------------------------------------------------------
81
 
82
#define cmsxIT8_ROWS                    12
83
#define cmsxIT8_COLS                    22
84
#define cmsxIT8_GRAYCOLS                24
85
#define cmsxIT8_NORMAL_PATCHES          (cmsxIT8_ROWS*cmsxIT8_COLS + cmsxIT8_GRAYCOLS)
86
#define cmsxIT8_CUSTOM_PATCHES          10
87
#define cmsxIT8_TOTAL_PATCHES           (cmsxIT8_NORMAL_PATCHES + cmsxIT8_CUSTOM_PATCHES)
88
 
89
 
90
LCMSHANDLE  cdecl cmsxIT8Alloc(void);
91
void        cdecl cmsxIT8Free(LCMSHANDLE cmsxIT8);
92
LCMSHANDLE  cdecl cmsxIT8LoadFromFile(const char* cFileName);
93
LCMSHANDLE  cdecl cmsxIT8LoadFromMem(void *Ptr, size_t len);
94
BOOL        cdecl cmsxIT8SaveToFile(LCMSHANDLE cmsxIT8, const char* cFileName);
95
const char* cdecl cmsxIT8GetSheetType(LCMSHANDLE hIT8);
96
BOOL        cdecl cmsxIT8SetSheetType(LCMSHANDLE hIT8, const char* Type);
97
const char* cdecl cmsxIT8GetPatchName(LCMSHANDLE hIT8, int nPatch, char* buffer);
98
BOOL        cdecl cmsxIT8SetProperty(LCMSHANDLE hcmsxIT8, const char* cProp, const char *Str);
99
BOOL        cdecl cmsxIT8SetPropertyDbl(LCMSHANDLE hcmsxIT8, const char* cProp, double Val);
100
const char* cdecl cmsxIT8GetProperty(LCMSHANDLE hcmsxIT8, const char* cProp);
101
double      cdecl cmsxIT8GetPropertyDbl(LCMSHANDLE hcmsxIT8, const char* cProp);
102
int         cdecl cmsxIT8EnumProperties(LCMSHANDLE cmsxIT8, char ***PropertyNames);
103
int         cdecl cmsxIT8EnumDataFormat(LCMSHANDLE cmsxIT8, char ***SampleNames);
104
BOOL        cdecl cmsxIT8SetDataFormat(LCMSHANDLE cmsxIT8, int n, const char *Sample);
105
 
106
BOOL        cdecl cmsxIT8GetDataSetByPos(LCMSHANDLE IT8, int col, int row, char* Val, int ValBufferLen);
107
 
108
BOOL        cdecl cmsxIT8GetDataSet(LCMSHANDLE cmsxIT8, const char* cPatch,
109
                        const char* cSample,
110
                        char* Val, int ValBuffLen);
111
 
112
BOOL        cdecl cmsxIT8GetDataSetDbl(LCMSHANDLE cmsxIT8, const char* cPatch, const char* cSample, double* v);
113
 
114
BOOL        cdecl cmsxIT8SetDataSet(LCMSHANDLE cmsxIT8, const char* cPatch,
115
                        const char* cSample,
116
                        char *Val);
117
 
118
BOOL        cdecl cmsxIT8SetDataSetDbl(LCMSHANDLE cmsxIT8, const char* cPatch, const char* cSample, double Val);
119
 
120
const char *cdecl cmsxIT8GenericPatchName(int nPatch, char* buffer);
121
 
122
 
123
 
124
// Patch collections (measurement lists) --------------------------------------------------
125
 
126
#define PATCH_HAS_Lab         0x00000001
127
#define PATCH_HAS_XYZ         0x00000002
128
#define PATCH_HAS_RGB         0x00000004
129
#define PATCH_HAS_CMY         0x00000008
130
#define PATCH_HAS_CMYK        0x00000010
131
#define PATCH_HAS_HEXACRM     0x00000020
132
#define PATCH_HAS_STD_Lab     0x00010000
133
#define PATCH_HAS_STD_XYZ     0x00020000
134
#define PATCH_HAS_XYZ_PROOF   0x00100000  
135
#define PATCH_HAS_MEAN_DE     0x01000000
136
#define PATCH_HAS_STD_DE      0x02000000
137
#define PATCH_HAS_CHISQ       0x04000000
138
 
139
 
140
#define MAXPATCHNAMELEN     20
141
// A patch in memory
142
 
143
typedef struct {
144
 
145
                DWORD        dwFlags;   // Is quite possible to have colorant in only
146
                                        // some patches of sheet, so mark each entry with
147
                                        // the values it has.
148
 
149
                char Name[MAXPATCHNAMELEN];
150
 
151
                cmsCIELab Lab;          // The tristimulus values of target
152
                cmsCIEXYZ XYZ;
153
 
154
                                cmsCIEXYZ XYZProof;             // The absolute XYZ value returned by profile
155
                                                                                // (gamut constrained to device)
156
 
157
                union {                 // The possible colorants. Only one space is
158
                                        // allowed...obviously only one set of
159
                                        // device-dependent values per patch does make sense.
160
                        double RGB[3];
161
                        double CMY[3];
162
                        double CMYK[4];
163
                        double Hexa[MAXCHANNELS];
164
 
165
                        } Colorant;            
166
 
167
                double dEStd;               // Standard deviation 
168
                double ChiSq;               // Chi-square parameter (mean of STD of colorants)
169
                double dEMean;              // Mean dE
170
 
171
           } PATCH, FAR* LPPATCH;
172
 
173
 
174
 
175
// A set of patches is simply an array of bools, TRUE if the patch
176
// belong to the set, false otherwise.
177
 
178
typedef BOOL* SETOFPATCHES;
179
 
180
// This struct holds whole Patches collection
181
 
182
typedef struct _measurement {
183
 
184
           int          nPatches;
185
           LPPATCH      Patches;
186
           SETOFPATCHES Allowed;
187
 
188
           } MEASUREMENT,FAR *LPMEASUREMENT;
189
 
190
 
191
void         cdecl cmsxPCollFreeMeasurements(LPMEASUREMENT m);
192
SETOFPATCHES cdecl cmsxPCollBuildSet(LPMEASUREMENT m, BOOL lDefault);
193
 
194
BOOL         cdecl cmsxPCollBuildMeasurement(LPMEASUREMENT m,
195
                                             const char *ReferenceSheet,
196
                                             const char *MeasurementSheet,
197
                                             DWORD dwNeededSamplesType);
198
 
199
int          cdecl cmsxPCollCountSet(LPMEASUREMENT m, SETOFPATCHES Set);
200
BOOL         cdecl cmsxPCollValidatePatches(LPMEASUREMENT m, DWORD dwFlags);
201
 
202
BOOL         cdecl cmsxPCollLoadFromSheet(LPMEASUREMENT m, LCMSHANDLE hSheet);
203
BOOL         cdecl cmsxPCollSaveToSheet(LPMEASUREMENT m, LCMSHANDLE it8);
204
 
205
LPPATCH      cdecl cmsxPCollGetPatch(LPMEASUREMENT m, int n);
206
LPPATCH      cdecl cmsxPCollGetPatchByName(LPMEASUREMENT m, const char* Name, int* lpPos);
207
LPPATCH      cdecl cmsxPCollGetPatchByPos(LPMEASUREMENT m, int row, int col);
208
LPPATCH      cdecl cmsxPCollAddPatchRGB(LPMEASUREMENT m, const char *Name,
209
                                        double r, double g, double b,
210
                                        LPcmsCIEXYZ XYZ, LPcmsCIELab Lab);
211
 
212
void         cdecl cmsxPCollLinearizePatches(LPMEASUREMENT m, SETOFPATCHES Valids,
213
                                             LPGAMMATABLE Gamma[3]);
214
 
215
// Extraction utilities
216
 
217
// Collect "need" patches of the specific kind, return the number of collected (that
218
// could be less if set of patches is exhausted)
219
 
220
void         cdecl cmsxPCollPatchesGS(LPMEASUREMENT m, SETOFPATCHES Result);
221
 
222
int          cdecl cmsxPCollPatchesNearRGB(LPMEASUREMENT m, SETOFPATCHES Valids,
223
                                            double r, double g, double b, int need, SETOFPATCHES Result);
224
 
225
int          cdecl cmsxPCollPatchesNearNeutral(LPMEASUREMENT m, SETOFPATCHES Valids,
226
                                            int need, SETOFPATCHES Result);
227
 
228
int          cdecl cmsxPCollPatchesNearPrimary(LPMEASUREMENT m, SETOFPATCHES Valids,
229
                                           int nChannel, int need, SETOFPATCHES Result);
230
 
231
int          cdecl cmsxPCollPatchesInLabCube(LPMEASUREMENT m, SETOFPATCHES Valids,
232
                                           double Lmin, double LMax, double a, double b, SETOFPATCHES Result);
233
 
234
int          cdecl cmsxPCollPatchesInGamutLUT(LPMEASUREMENT m, SETOFPATCHES Valids,
235
                                              LPLUT Gamut, SETOFPATCHES Result);
236
 
237
// Find important values
238
 
239
LPPATCH          cdecl cmsxPCollFindWhite(LPMEASUREMENT m, SETOFPATCHES Valids, double* Distance);
240
LPPATCH          cdecl cmsxPCollFindBlack(LPMEASUREMENT m, SETOFPATCHES Valids, double* Distance);
241
LPPATCH          cdecl cmsxPCollFindPrimary(LPMEASUREMENT m, SETOFPATCHES Valids, int Channel, double* Distance);
242
 
243
// Multiple linear regression stuff ----------------------------------------
244
 
245
 
246
// A measurement of error
247
 
248
typedef struct {
249
 
250
        double SSE;             // The error sum of squares
251
        double MSE;             // The error mean sum of squares
252
        double SSR;             // The regression sum of squares
253
        double MSR;             // The regression mean sum of squares
254
        double SSTO;            // Total sum of squares
255
        double F;               // The Fisher-F value (MSR / MSE)
256
        double R2;              // Proportion of variability explained by the regression
257
                                // (root is Pearson correlation coefficient)
258
 
259
        double R2adj;           // The adjusted coefficient of multiple determination.
260
                                // R2-adjusted or R2adj. This is calculated as
261
                                // R2adj = 1 - (1-R2)(N-n-1)/(N-1)
262
                                // and used as multiple correlation coefficient
263
                                // (really, it should be square root)
264
 
265
    } MLRSTATISTICS, FAR* LPMLRSTATISTICS;
266
 
267
 
268
int  cdecl cmsxRegressionCreateMatrix(LPMEASUREMENT m, SETOFPATCHES Allowed, int nterms,
269
                                       int ColorSpace,
270
                                       LPMATN* lpMat, LPMLRSTATISTICS Stat);
271
 
272
BOOL cdecl cmsxRegressionRGB2Lab(double r, double g, double b,
273
                                       LPMATN tfm, LPcmsCIELab Lab);
274
 
275
BOOL cdecl cmsxRegressionRGB2XYZ(double r, double g, double b,
276
                                       LPMATN tfm, LPcmsCIEXYZ XYZ);
277
 
278
BOOL cdecl cmsxRegressionInterpolatorRGB(LPMEASUREMENT m,
279
                                       int ColorSpace,                            
280
                                       int    RegressionTerms,
281
                                       BOOL   lUseLocalPatches,
282
                                       int    MinPatchesToCollect,
283
                                       double r, double g, double b,
284
                                       void* Res);
285
 
286
 
287
 
288
// Levenberg-Marquardt ----------------------------------------------------------------------
289
 
290
LCMSHANDLE cdecl cmsxLevenbergMarquardtInit(LPSAMPLEDCURVE x, LPSAMPLEDCURVE y, double sig,
291
                                                                double a[],
292
                                                                int ma,  
293
                                                                void (*funcs)(double, double[], double*, double[], int)
294
                                                                );
295
 
296
double    cdecl cmsxLevenbergMarquardtAlamda(LCMSHANDLE hMRQ);
297
double    cdecl cmsxLevenbergMarquardtChiSq(LCMSHANDLE hMRQ);
298
BOOL      cdecl cmsxLevenbergMarquardtIterate(LCMSHANDLE hMRQ);
299
BOOL      cdecl cmsxLevenbergMarquardtFree(LCMSHANDLE hMRQ);
300
 
301
 
302
// Convex hull geometric routines ------------------------------------------------------------
303
 
304
LCMSHANDLE cdecl cmsxHullInit(void);
305
void       cdecl cmsxHullDone(LCMSHANDLE hHull);
306
BOOL       cdecl cmsxHullAddPoint(LCMSHANDLE hHull, int x, int y, int z);
307
BOOL       cdecl cmsxHullComputeHull(LCMSHANDLE hHull);
308
char       cdecl cmsxHullCheckpoint(LCMSHANDLE hHull, int x, int y, int z);
309
BOOL       cdecl cmsxHullDumpVRML(LCMSHANDLE hHull, const char* fname);
310
 
311
 
312
// Linearization ----------------------------------------------------------------------------
313
 
314
 
315
#define MEDIUM_REFLECTIVE_D50   0       // Used for scanner targets
316
#define MEDIUM_TRANSMISSIVE             1       // Used for monitors & projectors
317
 
318
void cdecl cmsxComputeLinearizationTables(LPMEASUREMENT m,
319
                                    int ColorSpace,
320
                                    LPGAMMATABLE Lin[3],
321
                                                                        int nResultingPoints,
322
                                                                        int Medium);                                    
323
 
324
 
325
void             cdecl cmsxCompleteLabOfPatches(LPMEASUREMENT m, SETOFPATCHES Valids, int Medium);
326
LPGAMMATABLE cdecl cmsxEstimateGamma(LPSAMPLEDCURVE X, LPSAMPLEDCURVE Y, int nResultingPoints);
327
 
328
void cdecl cmsxApplyLinearizationTable(double In[3], LPGAMMATABLE Gamma[3], double Out[3]);
329
void cdecl cmsxApplyLinearizationGamma(WORD In[3], LPGAMMATABLE Gamma[3], WORD Out[3]);
330
 
331
// Support routines ----------------------------------------------------------------------
332
 
333
double cdecl _cmsxSaturate65535To255(double d);
334
double cdecl _cmsxSaturate255To65535(double d);
335
void   cdecl _cmsxClampXYZ100(LPcmsCIEXYZ xyz);
336
 
337
// Matrix shaper profiler API -------------------------------------------------------------
338
 
339
 
340
BOOL cdecl cmsxComputeMatrixShaper(const char* ReferenceSheet,                              
341
                                   const char* MeasurementSheet,
342
                                                                   int Medium,
343
                                   LPGAMMATABLE TransferCurves[3],
344
                                   LPcmsCIEXYZ WhitePoint,
345
                                   LPcmsCIEXYZ BlackPoint,
346
                                   LPcmsCIExyYTRIPLE Primaries);
347
 
348
 
349
// Common to all profilers -------------------------------------------------------------------
350
 
351
#define MAX_STR 256
352
 
353
typedef int (* cmsxGAUGER)(const char *Label, int nMin, int nMax, int Pos);
354
typedef int (* cmsxPRINTF)(const char *Frm, ...);
355
 
356
typedef struct {
357
 
358
           // Files
359
           char ReferenceSheet[MAX_PATH];
360
           char MeasurementSheet[MAX_PATH];
361
           char OutputProfileFile[MAX_PATH];
362
 
363
           // Some infos           
364
           char Description[MAX_STR];
365
           char Manufacturer[MAX_STR];
366
           char Model[MAX_STR];
367
           char Copyright[MAX_STR];
368
 
369
           // Callbacks
370
           cmsxGAUGER Gauger;
371
           cmsxPRINTF printf;
372
 
373
           // EndPoints
374
           cmsCIEXYZ WhitePoint;            // Black point in 0.xxx notation
375
           cmsCIEXYZ BlackPoint;            // Black point in 0.xxx notation
376
           cmsCIExyYTRIPLE Primaries;       // The primaries
377
           LPGAMMATABLE Gamma[3];           // Gamma curves
378
 
379
                   // Profile 
380
                   cmsHPROFILE hProfile;            // handle to profile
381
 
382
           icProfileClassSignature DeviceClass;
383
           icColorSpaceSignature   ColorSpace;
384
 
385
           int PCSType;                    // PT_XYZ or PT_Lab
386
           int CLUTPoints;                 // Final CLUT resolution
387
                   int ProfileVerbosityLevel;      // 0=minimum, 1=additional, 2=Verbose, 3=Any suitable
388
 
389
 
390
                   // Measurement       
391
           MEASUREMENT m;                   // Contains list of available patches
392
                   int Medium;
393
 
394
 
395
                   // RGB Gamut hull
396
                   LCMSHANDLE hRGBHull;   // Contains bobbin of valid RGB values
397
 
398
                   // CIECAM97s
399
                   BOOL lUseCIECAM97s;              // Use CIECAM97s for chromatic adaptation?
400
 
401
                   cmsViewingConditions device;     // Viewing condition of source
402
           cmsViewingConditions PCS;        // Viewing condition of PCS
403
 
404
           LCMSHANDLE hDevice;              // CIECAM97s models used for adaptation
405
           LCMSHANDLE hPCS;                 // and viewing conditions
406
 
407
 
408
    } PROFILERCOMMONDATA,FAR* LPPROFILERCOMMONDATA;
409
 
410
 
411
// Shared routines
412
 
413
BOOL cdecl cmsxEmbedCharTarget(LPPROFILERCOMMONDATA hdr);
414
BOOL cdecl cmsxEmbedMatrixShaper(LPPROFILERCOMMONDATA hdr);
415
BOOL cdecl cmsxEmbedTextualInfo(LPPROFILERCOMMONDATA hdr);
416
 
417
int  cdecl cmsxFindOptimumNumOfTerms(LPPROFILERCOMMONDATA hdr, int nMaxTerms, BOOL* lAllOk);
418
void cdecl cmsxChromaticAdaptationAndNormalization(LPPROFILERCOMMONDATA hdr, LPcmsCIEXYZ xyz, BOOL lReverse);
419
void cdecl cmsxInitPCSViewingConditions(LPPROFILERCOMMONDATA hdr);
420
void cdecl cmsxComputeGamutHull(LPPROFILERCOMMONDATA hdr);
421
BOOL cdecl cmsxChoosePCS(LPPROFILERCOMMONDATA hdr);
422
 
423
// Monitor profiler API -------------------------------------------------------------------
424
 
425
typedef struct {
426
 
427
           PROFILERCOMMONDATA hdr;
428
 
429
 
430
           LPGAMMATABLE         Prelinearization[3];    // Canonic gamma
431
           LPGAMMATABLE         ReverseTables[3];       // Reverse (direct) gamma
432
           LPGAMMATABLE         PreLab[3];
433
           LPGAMMATABLE         PreLabRev[3];
434
 
435
 
436
           MAT3                 PrimariesMatrix;
437
           MAT3                 PrimariesMatrixRev;
438
 
439
 
440
           } MONITORPROFILERDATA,FAR* LPMONITORPROFILERDATA;
441
 
442
 
443
 
444
BOOL   cdecl cmsxMonitorProfilerInit(LPMONITORPROFILERDATA sys);
445
BOOL   cdecl cmsxMonitorProfilerDo(LPMONITORPROFILERDATA sys);
446
 
447
 
448
// Scanner profiler API -------------------------------------------------------------------
449
 
450
 
451
typedef struct {
452
 
453
           PROFILERCOMMONDATA hdr;
454
 
455
           LPGAMMATABLE Prelinearization[3];        
456
 
457
                   LPMATN HiTerms;      // Regression matrix of many terms       
458
                   LPMATN LoTerms;              // Low order regression matrix used for extrapolation
459
 
460
                   BOOL   lLocalConvergenceExtrapolation;
461
 
462
 
463
           } SCANNERPROFILERDATA,FAR* LPSCANNERPROFILERDATA;
464
 
465
 
466
 
467
 
468
BOOL   cdecl cmsxScannerProfilerInit(LPSCANNERPROFILERDATA sys);                                      
469
BOOL   cdecl cmsxScannerProfilerDo(LPSCANNERPROFILERDATA sys);
470
 
471
// ----------------------------------------------------------- end of profilers
472
 
473
 
474
#ifdef __cplusplus
475
}
476
#endif
477
 
478
#define __cmsprf_H
479
#endif