13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 // This file is available under and governed by the GNU General Public
26 // License version 2 only, as published by the Free Software Foundation.
27 // However, the following notice accompanied the original version of this
28 // file:
29 //
30 //---------------------------------------------------------------------------------
31 //
32 // Little Color Management System
33 // Copyright (c) 1998-2012 Marti Maria Saguer
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining
36 // a copy of this software and associated documentation files (the "Software"),
37 // to deal in the Software without restriction, including without limitation
38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
39 // and/or sell copies of the Software, and to permit persons to whom the Software
40 // is furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 //
53 //---------------------------------------------------------------------------------
608
609 sgn = +1;
610 NextCh(it8);
611 }
612
613 e = 0;
614 while (isdigit(it8->ch)) {
615
616 if ((cmsFloat64Number) e * 10L < INT_MAX)
617 e = e * 10 + (it8->ch - '0');
618
619 NextCh(it8);
620 }
621
622 e = sgn*e;
623 it8 -> dnum = it8 -> dnum * xpow10(e);
624 }
625 }
626
627 // Parses a float number
628 // This can not call directly atof because it uses locale dependant
629 // parsing, while CCMX files always use . as decimal separator
630 static
631 cmsFloat64Number ParseFloatNumber(const char *Buffer)
632 {
633 cmsFloat64Number dnum = 0.0;
634 int sign = 1;
635
636 // keep safe
637 if (Buffer == NULL) return 0.0;
638
639 if (*Buffer == '-' || *Buffer == '+') {
640
641 sign = (*Buffer == '-') ? -1 : 1;
642 Buffer++;
643 }
644
645
646 while (*Buffer && isdigit((int) *Buffer)) {
647
648 dnum = dnum * 10.0 + (*Buffer - '0');
813 it8->inum = it8->inum * 10 + (it8->ch - '0');
814 NextCh(it8);
815 }
816
817 if (it8->ch == '.') {
818
819 ReadReal(it8, it8->inum);
820 it8->sy = SDNUM;
821 it8->dnum *= sign;
822 return;
823 }
824
825 it8 -> inum *= sign;
826
827 // Special case. Numbers followed by letters are taken as identifiers
828
829 if (isidchar(it8 ->ch)) {
830
831 if (it8 ->sy == SINUM) {
832
833 sprintf(it8->id, "%d", it8->inum);
834 }
835 else {
836
837 sprintf(it8->id, it8 ->DoubleFormatter, it8->dnum);
838 }
839
840 k = (int) strlen(it8 ->id);
841 idptr = it8 ->id + k;
842 do {
843
844 if (++k < MAXID) *idptr++ = (char) it8->ch;
845
846 NextCh(it8);
847
848 } while (isidchar(it8->ch));
849
850 *idptr = '\0';
851 it8->sy = SIDENT;
852 }
853 return;
854
855 }
856 else
857 switch ((int) it8->ch) {
1375
1376 return AddToList(it8, &GetTable(it8)->HeaderList, "# ", NULL, Val, WRITE_UNCOOKED) != NULL;
1377 }
1378
1379 // Sets a property
1380 cmsBool CMSEXPORT cmsIT8SetPropertyStr(cmsHANDLE hIT8, const char* Key, const char *Val)
1381 {
1382 cmsIT8* it8 = (cmsIT8*) hIT8;
1383
1384 if (!Val) return FALSE;
1385 if (!*Val) return FALSE;
1386
1387 return AddToList(it8, &GetTable(it8)->HeaderList, Key, NULL, Val, WRITE_STRINGIFY) != NULL;
1388 }
1389
1390 cmsBool CMSEXPORT cmsIT8SetPropertyDbl(cmsHANDLE hIT8, const char* cProp, cmsFloat64Number Val)
1391 {
1392 cmsIT8* it8 = (cmsIT8*) hIT8;
1393 char Buffer[1024];
1394
1395 sprintf(Buffer, it8->DoubleFormatter, Val);
1396
1397 return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_UNCOOKED) != NULL;
1398 }
1399
1400 cmsBool CMSEXPORT cmsIT8SetPropertyHex(cmsHANDLE hIT8, const char* cProp, cmsUInt32Number Val)
1401 {
1402 cmsIT8* it8 = (cmsIT8*) hIT8;
1403 char Buffer[1024];
1404
1405 sprintf(Buffer, "%u", Val);
1406
1407 return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_HEXADECIMAL) != NULL;
1408 }
1409
1410 cmsBool CMSEXPORT cmsIT8SetPropertyUncooked(cmsHANDLE hIT8, const char* Key, const char* Buffer)
1411 {
1412 cmsIT8* it8 = (cmsIT8*) hIT8;
1413
1414 return AddToList(it8, &GetTable(it8)->HeaderList, Key, NULL, Buffer, WRITE_UNCOOKED) != NULL;
1415 }
1416
1417 cmsBool CMSEXPORT cmsIT8SetPropertyMulti(cmsHANDLE hIT8, const char* Key, const char* SubKey, const char *Buffer)
1418 {
1419 cmsIT8* it8 = (cmsIT8*) hIT8;
1420
1421 return AddToList(it8, &GetTable(it8)->HeaderList, Key, SubKey, Buffer, WRITE_PAIR) != NULL;
1422 }
1423
1424 // Gets a property
1425 const char* CMSEXPORT cmsIT8GetProperty(cmsHANDLE hIT8, const char* Key)
1829
1830 for (i=0; i < it8 ->TablesCount; i++) {
1831
1832 cmsIT8SetTable(hIT8, i);
1833 WriteHeader(it8, &sd);
1834 WriteDataFormat(&sd, it8);
1835 WriteData(&sd, it8);
1836 }
1837
1838 sd.Used++; // The \0 at the very end
1839
1840 if (sd.Base)
1841 *sd.Ptr = 0;
1842
1843 *BytesNeeded = sd.Used;
1844
1845 return TRUE;
1846 }
1847
1848
1849 // -------------------------------------------------------------- Higer level parsing
1850
1851 static
1852 cmsBool DataFormatSection(cmsIT8* it8)
1853 {
1854 int iField = 0;
1855 TABLE* t = GetTable(it8);
1856
1857 InSymbol(it8); // Eats "BEGIN_DATA_FORMAT"
1858 CheckEOLN(it8);
1859
1860 while (it8->sy != SEND_DATA_FORMAT &&
1861 it8->sy != SEOLN &&
1862 it8->sy != SEOF &&
1863 it8->sy != SSYNERROR) {
1864
1865 if (it8->sy != SIDENT) {
1866
1867 return SynError(it8, "Sample type expected");
1868 }
1869
2132 }
2133
2134 }
2135 break;
2136
2137 case SEOLN:
2138 SkipEOLN(it8);
2139 break;
2140
2141 default:
2142 if (!HeaderSection(it8)) return FALSE;
2143 }
2144
2145 }
2146
2147 return (it8 -> sy != SSYNERROR);
2148 }
2149
2150
2151
2152 // Init usefull pointers
2153
2154 static
2155 void CookPointers(cmsIT8* it8)
2156 {
2157 int idField, i;
2158 char* Fld;
2159 cmsUInt32Number j;
2160 cmsUInt32Number nOldTable = it8 ->nTable;
2161
2162 for (j=0; j < it8 ->TablesCount; j++) {
2163
2164 TABLE* t = it8 ->Tab + j;
2165
2166 t -> SampleID = 0;
2167 it8 ->nTable = j;
2168
2169 for (idField = 0; idField < t -> nSamples; idField++)
2170 {
2171 if (t ->DataFormat == NULL){
2172 SynError(it8, "Undefined DATA_FORMAT");
2589 }
2590
2591
2592 cmsBool CMSEXPORT cmsIT8SetDataRowCol(cmsHANDLE hIT8, int row, int col, const char* Val)
2593 {
2594 cmsIT8* it8 = (cmsIT8*) hIT8;
2595
2596 _cmsAssert(hIT8 != NULL);
2597
2598 return SetData(it8, row, col, Val);
2599 }
2600
2601
2602 cmsBool CMSEXPORT cmsIT8SetDataRowColDbl(cmsHANDLE hIT8, int row, int col, cmsFloat64Number Val)
2603 {
2604 cmsIT8* it8 = (cmsIT8*) hIT8;
2605 char Buff[256];
2606
2607 _cmsAssert(hIT8 != NULL);
2608
2609 sprintf(Buff, it8->DoubleFormatter, Val);
2610
2611 return SetData(it8, row, col, Buff);
2612 }
2613
2614
2615
2616 const char* CMSEXPORT cmsIT8GetData(cmsHANDLE hIT8, const char* cPatch, const char* cSample)
2617 {
2618 cmsIT8* it8 = (cmsIT8*) hIT8;
2619 int iField, iSet;
2620
2621 _cmsAssert(hIT8 != NULL);
2622
2623 iField = LocateSample(it8, cSample);
2624 if (iField < 0) {
2625 return NULL;
2626 }
2627
2628 iSet = LocatePatch(it8, cPatch);
2629 if (iSet < 0) {
|
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 // This file is available under and governed by the GNU General Public
26 // License version 2 only, as published by the Free Software Foundation.
27 // However, the following notice accompanied the original version of this
28 // file:
29 //
30 //---------------------------------------------------------------------------------
31 //
32 // Little Color Management System
33 // Copyright (c) 1998-2016 Marti Maria Saguer
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining
36 // a copy of this software and associated documentation files (the "Software"),
37 // to deal in the Software without restriction, including without limitation
38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
39 // and/or sell copies of the Software, and to permit persons to whom the Software
40 // is furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 //
53 //---------------------------------------------------------------------------------
608
609 sgn = +1;
610 NextCh(it8);
611 }
612
613 e = 0;
614 while (isdigit(it8->ch)) {
615
616 if ((cmsFloat64Number) e * 10L < INT_MAX)
617 e = e * 10 + (it8->ch - '0');
618
619 NextCh(it8);
620 }
621
622 e = sgn*e;
623 it8 -> dnum = it8 -> dnum * xpow10(e);
624 }
625 }
626
627 // Parses a float number
628 // This can not call directly atof because it uses locale dependent
629 // parsing, while CCMX files always use . as decimal separator
630 static
631 cmsFloat64Number ParseFloatNumber(const char *Buffer)
632 {
633 cmsFloat64Number dnum = 0.0;
634 int sign = 1;
635
636 // keep safe
637 if (Buffer == NULL) return 0.0;
638
639 if (*Buffer == '-' || *Buffer == '+') {
640
641 sign = (*Buffer == '-') ? -1 : 1;
642 Buffer++;
643 }
644
645
646 while (*Buffer && isdigit((int) *Buffer)) {
647
648 dnum = dnum * 10.0 + (*Buffer - '0');
813 it8->inum = it8->inum * 10 + (it8->ch - '0');
814 NextCh(it8);
815 }
816
817 if (it8->ch == '.') {
818
819 ReadReal(it8, it8->inum);
820 it8->sy = SDNUM;
821 it8->dnum *= sign;
822 return;
823 }
824
825 it8 -> inum *= sign;
826
827 // Special case. Numbers followed by letters are taken as identifiers
828
829 if (isidchar(it8 ->ch)) {
830
831 if (it8 ->sy == SINUM) {
832
833 snprintf(it8->id, 127, "%d", it8->inum);
834 }
835 else {
836
837 snprintf(it8->id, 127, it8 ->DoubleFormatter, it8->dnum);
838 }
839
840 k = (int) strlen(it8 ->id);
841 idptr = it8 ->id + k;
842 do {
843
844 if (++k < MAXID) *idptr++ = (char) it8->ch;
845
846 NextCh(it8);
847
848 } while (isidchar(it8->ch));
849
850 *idptr = '\0';
851 it8->sy = SIDENT;
852 }
853 return;
854
855 }
856 else
857 switch ((int) it8->ch) {
1375
1376 return AddToList(it8, &GetTable(it8)->HeaderList, "# ", NULL, Val, WRITE_UNCOOKED) != NULL;
1377 }
1378
1379 // Sets a property
1380 cmsBool CMSEXPORT cmsIT8SetPropertyStr(cmsHANDLE hIT8, const char* Key, const char *Val)
1381 {
1382 cmsIT8* it8 = (cmsIT8*) hIT8;
1383
1384 if (!Val) return FALSE;
1385 if (!*Val) return FALSE;
1386
1387 return AddToList(it8, &GetTable(it8)->HeaderList, Key, NULL, Val, WRITE_STRINGIFY) != NULL;
1388 }
1389
1390 cmsBool CMSEXPORT cmsIT8SetPropertyDbl(cmsHANDLE hIT8, const char* cProp, cmsFloat64Number Val)
1391 {
1392 cmsIT8* it8 = (cmsIT8*) hIT8;
1393 char Buffer[1024];
1394
1395 snprintf(Buffer, 1023, it8->DoubleFormatter, Val);
1396
1397 return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_UNCOOKED) != NULL;
1398 }
1399
1400 cmsBool CMSEXPORT cmsIT8SetPropertyHex(cmsHANDLE hIT8, const char* cProp, cmsUInt32Number Val)
1401 {
1402 cmsIT8* it8 = (cmsIT8*) hIT8;
1403 char Buffer[1024];
1404
1405 snprintf(Buffer, 1023, "%u", Val);
1406
1407 return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_HEXADECIMAL) != NULL;
1408 }
1409
1410 cmsBool CMSEXPORT cmsIT8SetPropertyUncooked(cmsHANDLE hIT8, const char* Key, const char* Buffer)
1411 {
1412 cmsIT8* it8 = (cmsIT8*) hIT8;
1413
1414 return AddToList(it8, &GetTable(it8)->HeaderList, Key, NULL, Buffer, WRITE_UNCOOKED) != NULL;
1415 }
1416
1417 cmsBool CMSEXPORT cmsIT8SetPropertyMulti(cmsHANDLE hIT8, const char* Key, const char* SubKey, const char *Buffer)
1418 {
1419 cmsIT8* it8 = (cmsIT8*) hIT8;
1420
1421 return AddToList(it8, &GetTable(it8)->HeaderList, Key, SubKey, Buffer, WRITE_PAIR) != NULL;
1422 }
1423
1424 // Gets a property
1425 const char* CMSEXPORT cmsIT8GetProperty(cmsHANDLE hIT8, const char* Key)
1829
1830 for (i=0; i < it8 ->TablesCount; i++) {
1831
1832 cmsIT8SetTable(hIT8, i);
1833 WriteHeader(it8, &sd);
1834 WriteDataFormat(&sd, it8);
1835 WriteData(&sd, it8);
1836 }
1837
1838 sd.Used++; // The \0 at the very end
1839
1840 if (sd.Base)
1841 *sd.Ptr = 0;
1842
1843 *BytesNeeded = sd.Used;
1844
1845 return TRUE;
1846 }
1847
1848
1849 // -------------------------------------------------------------- Higher level parsing
1850
1851 static
1852 cmsBool DataFormatSection(cmsIT8* it8)
1853 {
1854 int iField = 0;
1855 TABLE* t = GetTable(it8);
1856
1857 InSymbol(it8); // Eats "BEGIN_DATA_FORMAT"
1858 CheckEOLN(it8);
1859
1860 while (it8->sy != SEND_DATA_FORMAT &&
1861 it8->sy != SEOLN &&
1862 it8->sy != SEOF &&
1863 it8->sy != SSYNERROR) {
1864
1865 if (it8->sy != SIDENT) {
1866
1867 return SynError(it8, "Sample type expected");
1868 }
1869
2132 }
2133
2134 }
2135 break;
2136
2137 case SEOLN:
2138 SkipEOLN(it8);
2139 break;
2140
2141 default:
2142 if (!HeaderSection(it8)) return FALSE;
2143 }
2144
2145 }
2146
2147 return (it8 -> sy != SSYNERROR);
2148 }
2149
2150
2151
2152 // Init useful pointers
2153
2154 static
2155 void CookPointers(cmsIT8* it8)
2156 {
2157 int idField, i;
2158 char* Fld;
2159 cmsUInt32Number j;
2160 cmsUInt32Number nOldTable = it8 ->nTable;
2161
2162 for (j=0; j < it8 ->TablesCount; j++) {
2163
2164 TABLE* t = it8 ->Tab + j;
2165
2166 t -> SampleID = 0;
2167 it8 ->nTable = j;
2168
2169 for (idField = 0; idField < t -> nSamples; idField++)
2170 {
2171 if (t ->DataFormat == NULL){
2172 SynError(it8, "Undefined DATA_FORMAT");
2589 }
2590
2591
2592 cmsBool CMSEXPORT cmsIT8SetDataRowCol(cmsHANDLE hIT8, int row, int col, const char* Val)
2593 {
2594 cmsIT8* it8 = (cmsIT8*) hIT8;
2595
2596 _cmsAssert(hIT8 != NULL);
2597
2598 return SetData(it8, row, col, Val);
2599 }
2600
2601
2602 cmsBool CMSEXPORT cmsIT8SetDataRowColDbl(cmsHANDLE hIT8, int row, int col, cmsFloat64Number Val)
2603 {
2604 cmsIT8* it8 = (cmsIT8*) hIT8;
2605 char Buff[256];
2606
2607 _cmsAssert(hIT8 != NULL);
2608
2609 snprintf(Buff, 255, it8->DoubleFormatter, Val);
2610
2611 return SetData(it8, row, col, Buff);
2612 }
2613
2614
2615
2616 const char* CMSEXPORT cmsIT8GetData(cmsHANDLE hIT8, const char* cPatch, const char* cSample)
2617 {
2618 cmsIT8* it8 = (cmsIT8*) hIT8;
2619 int iField, iSet;
2620
2621 _cmsAssert(hIT8 != NULL);
2622
2623 iField = LocateSample(it8, cSample);
2624 if (iField < 0) {
2625 return NULL;
2626 }
2627
2628 iSet = LocatePatch(it8, cPatch);
2629 if (iSet < 0) {
|