diff --git a/src/cmstypes.c b/src/cmstypes.c index 6b6bc287..667bf167 100644 --- a/src/cmstypes.c +++ b/src/cmstypes.c @@ -570,6 +570,178 @@ void Type_ColorantOrderType_Free(struct _cms_typehandler_struct* self, void* Ptr _cmsFree(self ->ContextID, Ptr); } +// ******************************************************************************** +// Type cmsSigUInt8ArrayType +// ******************************************************************************** +// This type represents an array of generic 1-byte/8-bit quantity. + +static +void* Type_UInt8_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag) +{ + cmsUInt8Number* array; + cmsUInt32Number i, n; + + *nItems = 0; + n = SizeOfTag / sizeof(cmsUInt8Number); + array = (cmsUInt8Number*)_cmsCalloc(self->ContextID, n, sizeof(cmsUInt8Number)); + if (array == NULL) return NULL; + + for (i = 0; i < n; i++) { + + if (!_cmsReadUInt8Number(io, &array[i])) { + + _cmsFree(self->ContextID, array); + return NULL; + } + } + + *nItems = n; + return (void*)array; +} + +static +cmsBool Type_UInt8_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems) +{ + cmsUInt8Number* Value = (cmsUInt8Number*)Ptr; + cmsUInt32Number i; + + for (i = 0; i < nItems; i++) { + + if (!_cmsWriteUInt8Number(io, Value[i])) return FALSE; + } + + return TRUE; + + cmsUNUSED_PARAMETER(self); +} + +static +void* Type_UInt8_Dup(struct _cms_typehandler_struct* self, const void* Ptr, cmsUInt32Number n) +{ + return _cmsDupMem(self->ContextID, Ptr, n * sizeof(cmsUInt8Number)); +} + + +static +void Type_UInt8_Free(struct _cms_typehandler_struct* self, void* Ptr) +{ + _cmsFree(self->ContextID, Ptr); +} + +// ******************************************************************************** +// Type cmsSigUInt32ArrayType +// ******************************************************************************** +// This type represents an array of generic 4-byte/32-bit quantity. +static +void* Type_UInt32_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag) +{ + cmsUInt32Number* array; + cmsUInt32Number i, n; + + *nItems = 0; + n = SizeOfTag / sizeof(cmsUInt32Number); + array = (cmsUInt32Number*)_cmsCalloc(self->ContextID, n, sizeof(cmsUInt32Number)); + if (array == NULL) return NULL; + + for (i = 0; i < n; i++) { + + if (!_cmsReadUInt32Number(io, &array[i])) { + + _cmsFree(self->ContextID, array); + return NULL; + } + } + + *nItems = n; + return (void*)array; +} + +static +cmsBool Type_UInt32_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems) +{ + cmsUInt32Number* Value = (cmsUInt32Number*)Ptr; + cmsUInt32Number i; + + for (i = 0; i < nItems; i++) { + + if (!_cmsWriteUInt32Number(io, Value[i])) return FALSE; + } + + return TRUE; + + cmsUNUSED_PARAMETER(self); +} + +static +void* Type_UInt32_Dup(struct _cms_typehandler_struct* self, const void* Ptr, cmsUInt32Number n) +{ + return _cmsDupMem(self->ContextID, Ptr, n * sizeof(cmsUInt32Number)); +} + + +static +void Type_UInt32_Free(struct _cms_typehandler_struct* self, void* Ptr) +{ + _cmsFree(self->ContextID, Ptr); +} + +// ******************************************************************************** +// Type cmsSigUInt64ArrayType +// ******************************************************************************** +// This type represents an array of generic 8-byte/64-bit quantity. +static +void* Type_UInt64_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag) +{ + cmsUInt64Number* array; + cmsUInt32Number i, n; + + *nItems = 0; + n = SizeOfTag / sizeof(cmsUInt64Number); + array = (cmsUInt64Number*)_cmsCalloc(self->ContextID, n, sizeof(cmsUInt64Number)); + if (array == NULL) return NULL; + + for (i = 0; i < n; i++) { + + if (!_cmsReadUInt64Number(io, &array[i])) { + + _cmsFree(self->ContextID, array); + return NULL; + } + } + + *nItems = n; + return (void*)array; +} + +static +cmsBool Type_UInt64_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems) +{ + cmsUInt64Number* Value = (cmsUInt64Number*)Ptr; + cmsUInt32Number i; + + for (i = 0; i < nItems; i++) { + + if (!_cmsWriteUInt64Number(io, &Value[i])) return FALSE; + } + + return TRUE; + + cmsUNUSED_PARAMETER(self); +} + +static +void* Type_UInt64_Dup(struct _cms_typehandler_struct* self, const void* Ptr, cmsUInt32Number n) +{ + return _cmsDupMem(self->ContextID, Ptr, n * sizeof(cmsUInt64Number)); +} + + +static +void Type_UInt64_Free(struct _cms_typehandler_struct* self, void* Ptr) +{ + _cmsFree(self->ContextID, Ptr); +} + // ******************************************************************************** // Type cmsSigS15Fixed16ArrayType // ******************************************************************************** @@ -5743,7 +5915,10 @@ static const _cmsTagTypeLinkedList SupportedTagTypes[] = { {TYPE_HANDLER(cmsSigDictType, Dictionary), (_cmsTagTypeLinkedList*) &SupportedTagTypes[30] }, {TYPE_HANDLER(cmsSigcicpType, VideoSignal), (_cmsTagTypeLinkedList*) &SupportedTagTypes[31] }, {TYPE_HANDLER(cmsSigVcgtType, vcgt), (_cmsTagTypeLinkedList*) &SupportedTagTypes[32] }, -{TYPE_HANDLER(cmsSigMHC2Type, MHC2), NULL } +{TYPE_HANDLER(cmsSigMHC2Type, MHC2), (_cmsTagTypeLinkedList*) &SupportedTagTypes[33] }, +{TYPE_HANDLER(cmsSigUInt8ArrayType, UInt8), (_cmsTagTypeLinkedList*) &SupportedTagTypes[34] }, +{TYPE_HANDLER(cmsSigUInt32ArrayType, UInt32), (_cmsTagTypeLinkedList*) &SupportedTagTypes[35] }, +{TYPE_HANDLER(cmsSigUInt64ArrayType, UInt64), NULL } }; diff --git a/testbed/testplugin.c b/testbed/testplugin.c index f288c35d..db8991e4 100755 --- a/testbed/testplugin.c +++ b/testbed/testplugin.c @@ -762,6 +762,8 @@ cmsInt32Number CheckFormattersPlugin(void) #define SigIntType ((cmsTagTypeSignature) 0x74747448) // 'tttH' #define SigInt ((cmsTagSignature) 0x74747448) // 'tttH' +#define SigInt32 ((cmsTagSignature) 0x74747449) // 'tttI' + static void *Type_int_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, @@ -803,9 +805,16 @@ static cmsPluginTag HiddenTagPluginSample = { SigInt, { 1, 1, { SigIntType }, NULL } }; +static cmsPluginTag HiddenTagPluginSample2 = { + + { cmsPluginMagicNumber, 2060, cmsPluginTagSig, &HiddenTagPluginSample}, + SigInt32, { 1, 1, { cmsSigUInt32ArrayType }, NULL } +}; + + static cmsPluginTagType TagTypePluginSample = { - { cmsPluginMagicNumber, 2060, cmsPluginTagTypeSig, (cmsPluginBase*) &HiddenTagPluginSample}, + { cmsPluginMagicNumber, 2060, cmsPluginTagTypeSig, (cmsPluginBase*) &HiddenTagPluginSample2}, { SigIntType, Type_int_Read, Type_int_Write, Type_int_Dup, Type_int_Free, NULL } }; @@ -817,6 +826,7 @@ cmsInt32Number CheckTagTypePlugin(void) cmsContext cpy2 = NULL; cmsHPROFILE h = NULL; cmsUInt32Number myTag = 1234; + cmsUInt32Number myTag32 = 5678; cmsUInt32Number rc = 0; char* data = NULL; cmsUInt32Number *ptr = NULL; @@ -844,6 +854,12 @@ cmsInt32Number CheckTagTypePlugin(void) goto Error; } + if (!cmsWriteTag(h, SigInt32, &myTag32)) { + Fail("Plug-in failed"); + goto Error; + } + + rc = cmsSaveProfileToMem(h, NULL, &clen); if (!rc) { Fail("Fetch mem size failed"); @@ -880,6 +896,14 @@ cmsInt32Number CheckTagTypePlugin(void) goto Error; } + ptr = (cmsUInt32Number*)cmsReadTag(h, SigInt32); + if (ptr != NULL) { + + Fail("read tag/context switching failed"); + goto Error; + } + + cmsCloseProfile(h); ResetFatalError(); @@ -900,6 +924,15 @@ cmsInt32Number CheckTagTypePlugin(void) rc = (*ptr == 1234); + ptr = (cmsUInt32Number*)cmsReadTag(h, SigInt32); + if (ptr == NULL) { + + Fail("read tag/context switching failed (2)"); + goto Error; + } + + rc &= (*ptr == 5678); + cmsCloseProfile(h); cmsDeleteContext(cpy2);