< prev index next >

src/share/native/sun/java2d/cmm/lcms/cmstypes.c

Print this page
rev 12531 : 8171261: Stability fixes for lcms
Reviewed-by: serb, vadim, mschoene
rev 12551 : 8183028: Improve CMS header processing
Reviewed-by: serb, rhalade, mschoene
rev 12553 : 8184937: LCMS error 13: Couldn't link the profiles
Reviewed-by: prr
Contributed-by: sreeprakash.s@oracle.com


1467 
1468     mlu = cmsMLUalloc(self ->ContextID, Count);
1469     if (mlu == NULL) return NULL;
1470 
1471     mlu ->UsedEntries = Count;
1472 
1473     SizeOfHeader = 12 * Count + sizeof(_cmsTagBase);
1474     LargestPosition = 0;
1475 
1476     for (i=0; i < Count; i++) {
1477 
1478         if (!_cmsReadUInt16Number(io, &mlu ->Entries[i].Language)) goto Error;
1479         if (!_cmsReadUInt16Number(io, &mlu ->Entries[i].Country))  goto Error;
1480 
1481         // Now deal with Len and offset.
1482         if (!_cmsReadUInt32Number(io, &Len)) goto Error;
1483         if (!_cmsReadUInt32Number(io, &Offset)) goto Error;
1484 
1485         // Check for overflow
1486         if (Offset < (SizeOfHeader + 8)) goto Error;

1487 
1488         // True begin of the string
1489         BeginOfThisString = Offset - SizeOfHeader - 8;
1490 
1491         // Ajust to wchar_t elements
1492         mlu ->Entries[i].Len = (Len * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
1493         mlu ->Entries[i].StrW = (BeginOfThisString * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
1494 
1495         // To guess maximum size, add offset + len
1496         EndOfThisString = BeginOfThisString + Len;
1497         if (EndOfThisString > LargestPosition)
1498             LargestPosition = EndOfThisString;
1499     }
1500 
1501     // Now read the remaining of tag and fill all strings. Substract the directory
1502     SizeOfTag   = (LargestPosition * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
1503     if (SizeOfTag == 0)
1504     {
1505         Block = NULL;
1506         NumOfWchar = 0;


4435 // This is the main dispatcher for MPE
4436 static
4437 void *Type_MPE_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
4438 {
4439     cmsUInt16Number InputChans, OutputChans;
4440     cmsUInt32Number ElementCount;
4441     cmsPipeline *NewLUT = NULL;
4442     cmsUInt32Number BaseOffset;
4443 
4444     // Get actual position as a basis for element offsets
4445     BaseOffset = io ->Tell(io) - sizeof(_cmsTagBase);
4446 
4447     // Read channels and element count
4448     if (!_cmsReadUInt16Number(io, &InputChans)) return NULL;
4449     if (!_cmsReadUInt16Number(io, &OutputChans)) return NULL;
4450 
4451     // Allocates an empty LUT
4452     NewLUT = cmsPipelineAlloc(self ->ContextID, InputChans, OutputChans);
4453     if (NewLUT == NULL) return NULL;
4454 
4455     if (!_cmsReadUInt32Number(io, &ElementCount)) return NULL;
4456 
4457     if (!ReadPositionTable(self, io, ElementCount, BaseOffset, NewLUT, ReadMPEElem)) {
4458         if (NewLUT != NULL) cmsPipelineFree(NewLUT);
4459         *nItems = 0;
4460         return NULL;
4461     }
4462 
4463     // Success
4464     *nItems = 1;
4465     return NewLUT;






4466 
4467     cmsUNUSED_PARAMETER(SizeOfTag);
4468 }
4469 
4470 
4471 
4472 // This one is a liitle bit more complex, so we don't use position tables this time.
4473 static
4474 cmsBool Type_MPE_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
4475 {
4476     cmsUInt32Number i, BaseOffset, DirectoryPos, CurrentPos;
4477     int inputChan, outputChan;
4478     cmsUInt32Number ElemCount;
4479     cmsUInt32Number *ElementOffsets = NULL, *ElementSizes = NULL, Before;
4480     cmsStageSignature ElementSig;
4481     cmsPipeline* Lut = (cmsPipeline*) Ptr;
4482     cmsStage* Elem = Lut ->Elements;
4483     cmsTagTypeHandler* TypeHandler;
4484     _cmsTagTypePluginChunkType* MPETypePluginChunk  = ( _cmsTagTypePluginChunkType*) _cmsContextGetClientChunk(self->ContextID, MPEPlugin);
4485 




1467 
1468     mlu = cmsMLUalloc(self ->ContextID, Count);
1469     if (mlu == NULL) return NULL;
1470 
1471     mlu ->UsedEntries = Count;
1472 
1473     SizeOfHeader = 12 * Count + sizeof(_cmsTagBase);
1474     LargestPosition = 0;
1475 
1476     for (i=0; i < Count; i++) {
1477 
1478         if (!_cmsReadUInt16Number(io, &mlu ->Entries[i].Language)) goto Error;
1479         if (!_cmsReadUInt16Number(io, &mlu ->Entries[i].Country))  goto Error;
1480 
1481         // Now deal with Len and offset.
1482         if (!_cmsReadUInt32Number(io, &Len)) goto Error;
1483         if (!_cmsReadUInt32Number(io, &Offset)) goto Error;
1484 
1485         // Check for overflow
1486         if (Offset < (SizeOfHeader + 8)) goto Error;
1487         if (((Offset + Len) < Len) || ((Offset + Len) > SizeOfTag + 8)) goto Error;
1488 
1489         // True begin of the string
1490         BeginOfThisString = Offset - SizeOfHeader - 8;
1491 
1492         // Ajust to wchar_t elements
1493         mlu ->Entries[i].Len = (Len * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
1494         mlu ->Entries[i].StrW = (BeginOfThisString * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
1495 
1496         // To guess maximum size, add offset + len
1497         EndOfThisString = BeginOfThisString + Len;
1498         if (EndOfThisString > LargestPosition)
1499             LargestPosition = EndOfThisString;
1500     }
1501 
1502     // Now read the remaining of tag and fill all strings. Substract the directory
1503     SizeOfTag   = (LargestPosition * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
1504     if (SizeOfTag == 0)
1505     {
1506         Block = NULL;
1507         NumOfWchar = 0;


4436 // This is the main dispatcher for MPE
4437 static
4438 void *Type_MPE_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsUInt32Number* nItems, cmsUInt32Number SizeOfTag)
4439 {
4440     cmsUInt16Number InputChans, OutputChans;
4441     cmsUInt32Number ElementCount;
4442     cmsPipeline *NewLUT = NULL;
4443     cmsUInt32Number BaseOffset;
4444 
4445     // Get actual position as a basis for element offsets
4446     BaseOffset = io ->Tell(io) - sizeof(_cmsTagBase);
4447 
4448     // Read channels and element count
4449     if (!_cmsReadUInt16Number(io, &InputChans)) return NULL;
4450     if (!_cmsReadUInt16Number(io, &OutputChans)) return NULL;
4451 
4452     // Allocates an empty LUT
4453     NewLUT = cmsPipelineAlloc(self ->ContextID, InputChans, OutputChans);
4454     if (NewLUT == NULL) return NULL;
4455 
4456     if (!_cmsReadUInt32Number(io, &ElementCount)) goto Error;
4457     if (!ReadPositionTable(self, io, ElementCount, BaseOffset, NewLUT, ReadMPEElem)) goto Error;





4458 
4459     // Success
4460     *nItems = 1;
4461     return NewLUT;
4462 
4463     // Error
4464 Error:
4465     if (NewLUT != NULL) cmsPipelineFree(NewLUT);
4466     *nItems = 0;
4467     return NULL;
4468 
4469     cmsUNUSED_PARAMETER(SizeOfTag);
4470 }
4471 
4472 
4473 
4474 // This one is a liitle bit more complex, so we don't use position tables this time.
4475 static
4476 cmsBool Type_MPE_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
4477 {
4478     cmsUInt32Number i, BaseOffset, DirectoryPos, CurrentPos;
4479     int inputChan, outputChan;
4480     cmsUInt32Number ElemCount;
4481     cmsUInt32Number *ElementOffsets = NULL, *ElementSizes = NULL, Before;
4482     cmsStageSignature ElementSig;
4483     cmsPipeline* Lut = (cmsPipeline*) Ptr;
4484     cmsStage* Elem = Lut ->Elements;
4485     cmsTagTypeHandler* TypeHandler;
4486     _cmsTagTypePluginChunkType* MPETypePluginChunk  = ( _cmsTagTypePluginChunkType*) _cmsContextGetClientChunk(self->ContextID, MPEPlugin);
4487 


< prev index next >