📄 cmscgats.c
字号:
//// Little cms// Copyright (C) 1998-2005 Marti Maria//// Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the Software // is furnished to do so, subject to the following conditions://// The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software.//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.// // IT8.7 / CGATS.17-200x handling#include "lcms.h"LCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8Alloc(void);LCMSAPI void LCMSEXPORT cmsIT8Free(LCMSHANDLE IT8);// TablesLCMSAPI int LCMSEXPORT cmsIT8TableCount(LCMSHANDLE IT8);LCMSAPI int LCMSEXPORT cmsIT8SetTable(LCMSHANDLE IT8, int nTable);// PersistenceLCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8LoadFromFile(const char* cFileName);LCMSAPI LCMSHANDLE LCMSEXPORT cmsIT8LoadFromMem(void *Ptr, size_t len);LCMSAPI BOOL LCMSEXPORT cmsIT8SaveToFile(LCMSHANDLE IT8, const char* cFileName);// PropertiesLCMSAPI const char* LCMSEXPORT cmsIT8GetSheetType(LCMSHANDLE hIT8);LCMSAPI BOOL LCMSEXPORT cmsIT8SetSheetType(LCMSHANDLE hIT8, const char* Type);LCMSAPI BOOL LCMSEXPORT cmsIT8SetComment(LCMSHANDLE hIT8, const char* cComment);LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyStr(LCMSHANDLE hIT8, const char* cProp, const char *Str);LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyDbl(LCMSHANDLE hIT8, const char* cProp, double Val);LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyHex(LCMSHANDLE hIT8, const char* cProp, int Val);LCMSAPI BOOL LCMSEXPORT cmsIT8SetPropertyUncooked(LCMSHANDLE hIT8, const char* Key, const char* Buffer);LCMSAPI const char* LCMSEXPORT cmsIT8GetProperty(LCMSHANDLE hIT8, const char* cProp);LCMSAPI double LCMSEXPORT cmsIT8GetPropertyDbl(LCMSHANDLE hIT8, const char* cProp);LCMSAPI int LCMSEXPORT cmsIT8EnumProperties(LCMSHANDLE IT8, char ***PropertyNames);// DatasetsLCMSAPI const char* LCMSEXPORT cmsIT8GetPatchName(LCMSHANDLE hIT8, int nPatch, char* buffer);LCMSAPI const char* LCMSEXPORT cmsIT8GetDataRowCol(LCMSHANDLE IT8, int row, int col); LCMSAPI double LCMSEXPORT cmsIT8GetDataRowColDbl(LCMSHANDLE IT8, int col, int row);LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataRowCol(LCMSHANDLE hIT8, int row, int col, const char* Val);LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataRowColDbl(LCMSHANDLE hIT8, int row, int col, double Val);LCMSAPI const char* LCMSEXPORT cmsIT8GetData(LCMSHANDLE IT8, const char* cPatch, const char* cSample);LCMSAPI double LCMSEXPORT cmsIT8GetDataDbl(LCMSHANDLE IT8, const char* cPatch, const char* cSample); LCMSAPI BOOL LCMSEXPORT cmsIT8SetData(LCMSHANDLE IT8, const char* cPatch, const char* cSample, const char *Val);LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataDbl(LCMSHANDLE hIT8, const char* cPatch, const char* cSample, double Val);LCMSAPI BOOL LCMSEXPORT cmsIT8SetDataFormat(LCMSHANDLE IT8, int n, const char *Sample);LCMSAPI int LCMSEXPORT cmsIT8EnumDataFormat(LCMSHANDLE IT8, char ***SampleNames);LCMSAPI void LCMSEXPORT cmsIT8DefineDblFormat(LCMSHANDLE IT8, const char* Formatter);LCMSAPI int LCMSEXPORT cmsIT8SetTableByLabel(LCMSHANDLE hIT8, const char* cSet, const char* cField, const char* ExpectedType);// ------------------------------------------------------------- Implementation#define SIZEOFLONGMINUS1 (sizeof(long)-1)#define ALIGNLONG(x) (((x)+SIZEOFLONGMINUS1) & ~(SIZEOFLONGMINUS1)) // #define STRICT_CGATS 1#define MAXID 128 // Max lenght of identifier#define MAXSTR 255 // Max lenght of string#define MAXTABLES 255 // Max Number of tables in a single stream#define MAXINCLUDE 20 // Max number of nested includes#define DEFAULT_DBL_FORMAT "%.10g" // Double formatting#include <ctype.h>#include <limits.h>#ifndef NON_WINDOWS#include <io.h>#endif// Symbolstypedef enum { SNONE, SINUM, // Integer SDNUM, // Real SIDENT, // Identifier SSTRING, // string SCOMMENT, // comment SEOLN, // End of line SEOF, // End of stream SSYNERROR, // Syntax error found on stream // Keywords SBEGIN_DATA, SBEGIN_DATA_FORMAT, SEND_DATA, SEND_DATA_FORMAT, SKEYWORD, SINCLUDE } SYMBOL;// How to write the valuetypedef enum { WRITE_UNCOOKED, WRITE_STRINGIFY, WRITE_HEXADECIMAL, WRITE_BINARY } WRITEMODE;// Linked list of variable namestypedef struct _KeyVal { struct _KeyVal* Next; char* Keyword; // Name of variable char* Value; // Points to value WRITEMODE WriteAs; // How to write the value } KEYVALUE, *LPKEYVALUE;// Linked list of memory chunks (Memory sink)typedef struct _OwnedMem { struct _OwnedMem* Next; void * Ptr; // Point to value } OWNEDMEM, *LPOWNEDMEM;// Suballocatortypedef struct _SubAllocator { LPBYTE Block; size_t BlockSize; size_t Used; } SUBALLOCATOR, *LPSUBALLOCATOR;// Table. Each individual table can hold properties and rows & colstypedef struct _Table { int nSamples, nPatches; // Cols, Rows int SampleID; // Pos of ID LPKEYVALUE HeaderList; // The properties char** DataFormat; // The binary stream descriptor char** Data; // The binary stream } TABLE, *LPTABLE;// This struct hold all information about an openened// IT8 handler. Only one dataset is allowed.typedef struct { char SheetType[MAXSTR]; int TablesCount; // How many tables in this stream int nTable; // The actual table TABLE Tab[MAXTABLES]; // Memory management LPOWNEDMEM MemorySink; // The storage backend SUBALLOCATOR Allocator; // String suballocator -- just to keep it fast // Parser state machine SYMBOL sy; // Current symbol int ch; // Current character int inum; // integer value double dnum; // real value char id[MAXID]; // identifier char str[MAXSTR]; // string // Allowed keywords & datasets. They have visibility on whole stream LPKEYVALUE ValidKeywords; LPKEYVALUE ValidSampleID; char* Source; // Points to loc. being parsed int lineno; // line counter for error reporting char FileName[MAX_PATH]; // File name if being readed from file FILE* Stream[MAXINCLUDE]; // File stream or NULL if holded in memory int IncludeSP; // Include Stack Pointer char* MemoryBlock; // The stream if holded in memory char DoubleFormatter[MAXID]; // Printf-like 'double' formatter } IT8, *LPIT8;typedef struct { FILE* stream; // For save-to-file behaviour LPBYTE Base; LPBYTE Ptr; // For save-to-mem behaviour size_t Used; size_t Max; } SAVESTREAM, FAR* LPSAVESTREAM;// ------------------------------------------------------ IT8 parsing routines// A keywordtypedef struct { const char *id; SYMBOL sy; } KEYWORD;// The keyword->symbol translation table. Sorting is required.static const KEYWORD TabKeys[] = { {"$INCLUDE", SINCLUDE}, {".INCLUDE", SINCLUDE}, {"BEGIN_DATA", SBEGIN_DATA }, {"BEGIN_DATA_FORMAT", SBEGIN_DATA_FORMAT }, {"END_DATA", SEND_DATA}, {"END_DATA_FORMAT", SEND_DATA_FORMAT}, {"KEYWORD", SKEYWORD} };#define NUMKEYS (sizeof(TabKeys)/sizeof(KEYWORD))// Predefined propertiesstatic const char* PredefinedProperties[] = { "NUMBER_OF_FIELDS", // Required - NUMBER OF FIELDS "NUMBER_OF_SETS", // Required - NUMBER OF SETS "ORIGINATOR", // Required - Identifies the specific system, organization or individual that created the data file. "CREATED", // Required - Indicates date of creation of the data file. "DESCRIPTOR", // Required - Describes the purpose or contents of the data file. "DIFFUSE_GEOMETRY", // The diffuse geometry used. Allowed values are "sphere" or "opal". "MANUFACTURER", "MANUFACTURE", // Some broken Fuji targets does store this value "PROD_DATE", // Identifies year and month of production of the target in the form yyyy:mm. "SERIAL", // Uniquely identifies individual physical target. "MATERIAL", // Identifies the material on which the target was produced using a code // uniquely identifying th e material. This is intend ed to be used for IT8.7 // physical targets only (i.e . IT8.7/1 a nd IT8.7/2). "INSTRUMENTATION", // Used to report the specific instrumentation used (manufacturer and // model number) to generate the data reported. This data will often // provide more information about the particular data collected than an // extensive list of specific details. This is particularly important for // spectral data or data derived from spectrophotometry. "MEASUREMENT_SOURCE", // Illumination used for spectral measurements. This data helps provide // a guide to the potential for issues of paper fluorescence, etc. "PRINT_CONDITIONS", // Used to define the characteristics of the printed sheet being reported. // Where standard conditions have been defined (e.g., SWOP at nominal) // named conditions may suffice. Otherwise, detailed information is // needed. "SAMPLE_BACKING", // Identifies the backing material used behind the sample during // measurement. Allowed values are 揵lack
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -