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-2017 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 //---------------------------------------------------------------------------------
550 return FALSE;
551
552 v ->List = NewPtr;
553 v ->Allocated = size;
554 return TRUE;
555 }
556
557 // Allocate a list for n elements
558 cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUInt32Number n, cmsUInt32Number ColorantCount, const char* Prefix, const char* Suffix)
559 {
560 cmsNAMEDCOLORLIST* v = (cmsNAMEDCOLORLIST*) _cmsMallocZero(ContextID, sizeof(cmsNAMEDCOLORLIST));
561
562 if (v == NULL) return NULL;
563
564 v ->List = NULL;
565 v ->nColors = 0;
566 v ->ContextID = ContextID;
567
568 while (v -> Allocated < n) {
569 if (!GrowNamedColorList(v)) {
570 _cmsFree(ContextID, (void*) v);
571 return NULL;
572 }
573 }
574
575 strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix)-1);
576 strncpy(v ->Suffix, Suffix, sizeof(v ->Suffix)-1);
577 v->Prefix[32] = v->Suffix[32] = 0;
578
579 v -> ColorantCount = ColorantCount;
580
581 return v;
582 }
583
584 // Free a list
585 void CMSEXPORT cmsFreeNamedColorList(cmsNAMEDCOLORLIST* v)
586 {
587 if (v == NULL) return;
588 if (v ->List) _cmsFree(v ->ContextID, v ->List);
589 _cmsFree(v ->ContextID, v);
590 }
591
592 cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v)
593 {
594 cmsNAMEDCOLORLIST* NewNC;
595
596 if (v == NULL) return NULL;
597
598 NewNC= cmsAllocNamedColorList(v ->ContextID, v -> nColors, v ->ColorantCount, v ->Prefix, v ->Suffix);
599 if (NewNC == NULL) return NULL;
600
601 // For really large tables we need this
602 while (NewNC ->Allocated < v ->Allocated){
603 if (!GrowNamedColorList(NewNC)) return NULL;
604 }
605
606 memmove(NewNC ->Prefix, v ->Prefix, sizeof(v ->Prefix));
607 memmove(NewNC ->Suffix, v ->Suffix, sizeof(v ->Suffix));
608 NewNC ->ColorantCount = v ->ColorantCount;
609 memmove(NewNC->List, v ->List, v->nColors * sizeof(_cmsNAMEDCOLOR));
610 NewNC ->nColors = v ->nColors;
611 return NewNC;
612 }
613
614
615 // Append a color to a list. List pointer may change if reallocated
616 cmsBool CMSEXPORT cmsAppendNamedColor(cmsNAMEDCOLORLIST* NamedColorList,
617 const char* Name,
618 cmsUInt16Number PCS[3], cmsUInt16Number Colorant[cmsMAXCHANNELS])
619 {
620 cmsUInt32Number i;
621
622 if (NamedColorList == NULL) return FALSE;
623
|
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-2020 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 //---------------------------------------------------------------------------------
550 return FALSE;
551
552 v ->List = NewPtr;
553 v ->Allocated = size;
554 return TRUE;
555 }
556
557 // Allocate a list for n elements
558 cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUInt32Number n, cmsUInt32Number ColorantCount, const char* Prefix, const char* Suffix)
559 {
560 cmsNAMEDCOLORLIST* v = (cmsNAMEDCOLORLIST*) _cmsMallocZero(ContextID, sizeof(cmsNAMEDCOLORLIST));
561
562 if (v == NULL) return NULL;
563
564 v ->List = NULL;
565 v ->nColors = 0;
566 v ->ContextID = ContextID;
567
568 while (v -> Allocated < n) {
569 if (!GrowNamedColorList(v)) {
570 cmsFreeNamedColorList(v);
571 return NULL;
572 }
573 }
574
575 strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix)-1);
576 strncpy(v ->Suffix, Suffix, sizeof(v ->Suffix)-1);
577 v->Prefix[32] = v->Suffix[32] = 0;
578
579 v -> ColorantCount = ColorantCount;
580
581 return v;
582 }
583
584 // Free a list
585 void CMSEXPORT cmsFreeNamedColorList(cmsNAMEDCOLORLIST* v)
586 {
587 if (v == NULL) return;
588 if (v ->List) _cmsFree(v ->ContextID, v ->List);
589 _cmsFree(v ->ContextID, v);
590 }
591
592 cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v)
593 {
594 cmsNAMEDCOLORLIST* NewNC;
595
596 if (v == NULL) return NULL;
597
598 NewNC= cmsAllocNamedColorList(v ->ContextID, v -> nColors, v ->ColorantCount, v ->Prefix, v ->Suffix);
599 if (NewNC == NULL) return NULL;
600
601 // For really large tables we need this
602 while (NewNC ->Allocated < v ->Allocated){
603 if (!GrowNamedColorList(NewNC))
604 {
605 cmsFreeNamedColorList(NewNC);
606 return NULL;
607 }
608 }
609
610 memmove(NewNC ->Prefix, v ->Prefix, sizeof(v ->Prefix));
611 memmove(NewNC ->Suffix, v ->Suffix, sizeof(v ->Suffix));
612 NewNC ->ColorantCount = v ->ColorantCount;
613 memmove(NewNC->List, v ->List, v->nColors * sizeof(_cmsNAMEDCOLOR));
614 NewNC ->nColors = v ->nColors;
615 return NewNC;
616 }
617
618
619 // Append a color to a list. List pointer may change if reallocated
620 cmsBool CMSEXPORT cmsAppendNamedColor(cmsNAMEDCOLORLIST* NamedColorList,
621 const char* Name,
622 cmsUInt16Number PCS[3], cmsUInt16Number Colorant[cmsMAXCHANNELS])
623 {
624 cmsUInt32Number i;
625
626 if (NamedColorList == NULL) return FALSE;
627
|