< prev index next >
src/share/native/sun/java2d/cmm/lcms/cmsio0.c
Print this page
*** 28,38 ****
// file:
//
//---------------------------------------------------------------------------------
//
// Little Color Management System
! // Copyright (c) 1998-2012 Marti Maria Saguer
//
// 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,
--- 28,38 ----
// file:
//
//---------------------------------------------------------------------------------
//
// Little Color Management System
! // Copyright (c) 1998-2016 Marti Maria Saguer
//
// 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,
*** 351,361 ****
}
return nReaded;
}
! // Postion file pointer in the file
static
cmsBool FileSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset)
{
if (fseek((FILE*) iohandler ->stream, (long) offset, SEEK_SET) != 0) {
--- 351,361 ----
}
return nReaded;
}
! // Position file pointer in the file
static
cmsBool FileSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset)
{
if (fseek((FILE*) iohandler ->stream, (long) offset, SEEK_SET) != 0) {
*** 395,404 ****
--- 395,405 ----
// Create a iohandler for disk based files.
cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromFile(cmsContext ContextID, const char* FileName, const char* AccessMode)
{
cmsIOHANDLER* iohandler = NULL;
FILE* fm = NULL;
+ cmsInt32Number fileLen;
_cmsAssert(FileName != NULL);
_cmsAssert(AccessMode != NULL);
iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
*** 411,421 ****
if (fm == NULL) {
_cmsFree(ContextID, iohandler);
cmsSignalError(ContextID, cmsERROR_FILE, "File '%s' not found", FileName);
return NULL;
}
! iohandler -> ReportedSize = (cmsUInt32Number) cmsfilelength(fm);
break;
case 'w':
fm = fopen(FileName, "wb");
if (fm == NULL) {
--- 412,431 ----
if (fm == NULL) {
_cmsFree(ContextID, iohandler);
cmsSignalError(ContextID, cmsERROR_FILE, "File '%s' not found", FileName);
return NULL;
}
! fileLen = cmsfilelength(fm);
! if (fileLen < 0)
! {
! fclose(fm);
! _cmsFree(ContextID, iohandler);
! cmsSignalError(ContextID, cmsERROR_FILE, "Cannot get size of file '%s'", FileName);
! return NULL;
! }
!
! iohandler -> ReportedSize = (cmsUInt32Number) fileLen;
break;
case 'w':
fm = fopen(FileName, "wb");
if (fm == NULL) {
*** 451,468 ****
// Create a iohandler for stream based files
cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromStream(cmsContext ContextID, FILE* Stream)
{
cmsIOHANDLER* iohandler = NULL;
iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
if (iohandler == NULL) return NULL;
iohandler -> ContextID = ContextID;
iohandler -> stream = (void*) Stream;
iohandler -> UsedSpace = 0;
! iohandler -> ReportedSize = (cmsUInt32Number) cmsfilelength(Stream);
iohandler -> PhysicalFile[0] = 0;
iohandler ->Read = FileRead;
iohandler ->Seek = FileSeek;
iohandler ->Close = FileClose;
--- 461,486 ----
// Create a iohandler for stream based files
cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromStream(cmsContext ContextID, FILE* Stream)
{
cmsIOHANDLER* iohandler = NULL;
+ cmsInt32Number fileSize;
+
+ fileSize = cmsfilelength(Stream);
+ if (fileSize < 0)
+ {
+ cmsSignalError(ContextID, cmsERROR_FILE, "Cannot get size of stream");
+ return NULL;
+ }
iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
if (iohandler == NULL) return NULL;
iohandler -> ContextID = ContextID;
iohandler -> stream = (void*) Stream;
iohandler -> UsedSpace = 0;
! iohandler -> ReportedSize = (cmsUInt32Number) fileSize;
iohandler -> PhysicalFile[0] = 0;
iohandler ->Read = FileRead;
iohandler ->Seek = FileSeek;
iohandler ->Close = FileClose;
*** 650,660 ****
return TRUE;
}
! // Check existance
cmsBool CMSEXPORT cmsIsTag(cmsHPROFILE hProfile, cmsTagSignature sig)
{
_cmsICCPROFILE* Icc = (_cmsICCPROFILE*) (void*) hProfile;
return _cmsSearchTag(Icc, sig, FALSE) >= 0;
}
--- 668,678 ----
return TRUE;
}
! // Check existence
cmsBool CMSEXPORT cmsIsTag(cmsHPROFILE hProfile, cmsTagSignature sig)
{
_cmsICCPROFILE* Icc = (_cmsICCPROFILE*) (void*) hProfile;
return _cmsSearchTag(Icc, sig, FALSE) >= 0;
}
*** 706,716 ****
if (_cmsAdjustEndianess32(Header.magic) != cmsMagicNumber) {
cmsSignalError(Icc ->ContextID, cmsERROR_BAD_SIGNATURE, "not an ICC profile, invalid signature");
return FALSE;
}
! // Adjust endianess of the used parameters
Icc -> DeviceClass = (cmsProfileClassSignature) _cmsAdjustEndianess32(Header.deviceClass);
Icc -> ColorSpace = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Header.colorSpace);
Icc -> PCS = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Header.pcs);
Icc -> RenderingIntent = _cmsAdjustEndianess32(Header.renderingIntent);
--- 724,734 ----
if (_cmsAdjustEndianess32(Header.magic) != cmsMagicNumber) {
cmsSignalError(Icc ->ContextID, cmsERROR_BAD_SIGNATURE, "not an ICC profile, invalid signature");
return FALSE;
}
! // Adjust endianness of the used parameters
Icc -> DeviceClass = (cmsProfileClassSignature) _cmsAdjustEndianess32(Header.deviceClass);
Icc -> ColorSpace = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Header.colorSpace);
Icc -> PCS = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Header.pcs);
Icc -> RenderingIntent = _cmsAdjustEndianess32(Header.renderingIntent);
*** 824,853 ****
// Created by LittleCMS (that's me!)
Header.creator = _cmsAdjustEndianess32(lcmsSignature);
memset(&Header.reserved, 0, sizeof(Header.reserved));
! // Set profile ID. Endianess is always big endian
memmove(&Header.profileID, &Icc ->ProfileID, 16);
// Dump the header
if (!Icc -> IOhandler->Write(Icc->IOhandler, sizeof(cmsICCHeader), &Header)) return FALSE;
// Saves Tag directory
// Get true count
for (i=0; i < Icc -> TagCount; i++) {
! if (Icc ->TagNames[i] != 0)
Count++;
}
// Store number of tags
if (!_cmsWriteUInt32Number(Icc ->IOhandler, Count)) return FALSE;
for (i=0; i < Icc -> TagCount; i++) {
! if (Icc ->TagNames[i] == 0) continue; // It is just a placeholder
Tag.sig = (cmsTagSignature) _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagNames[i]);
Tag.offset = _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagOffsets[i]);
Tag.size = _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagSizes[i]);
--- 842,871 ----
// Created by LittleCMS (that's me!)
Header.creator = _cmsAdjustEndianess32(lcmsSignature);
memset(&Header.reserved, 0, sizeof(Header.reserved));
! // Set profile ID. Endianness is always big endian
memmove(&Header.profileID, &Icc ->ProfileID, 16);
// Dump the header
if (!Icc -> IOhandler->Write(Icc->IOhandler, sizeof(cmsICCHeader), &Header)) return FALSE;
// Saves Tag directory
// Get true count
for (i=0; i < Icc -> TagCount; i++) {
! if (Icc ->TagNames[i] != (cmsTagSignature) 0)
Count++;
}
// Store number of tags
if (!_cmsWriteUInt32Number(Icc ->IOhandler, Count)) return FALSE;
for (i=0; i < Icc -> TagCount; i++) {
! if (Icc ->TagNames[i] == (cmsTagSignature) 0) continue; // It is just a placeholder
Tag.sig = (cmsTagSignature) _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagNames[i]);
Tag.offset = _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagOffsets[i]);
Tag.size = _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagSizes[i]);
*** 1193,1203 ****
cmsFloat64Number Version = cmsGetProfileVersion((cmsHPROFILE) Icc);
cmsTagTypeHandler LocalTypeHandler;
for (i=0; i < Icc -> TagCount; i++) {
! if (Icc ->TagNames[i] == 0) continue;
// Linked tags are not written
if (Icc ->TagLinked[i] != (cmsTagSignature) 0) continue;
Icc -> TagOffsets[i] = Begin = io ->UsedSpace;
--- 1211,1221 ----
cmsFloat64Number Version = cmsGetProfileVersion((cmsHPROFILE) Icc);
cmsTagTypeHandler LocalTypeHandler;
for (i=0; i < Icc -> TagCount; i++) {
! if (Icc ->TagNames[i] == (cmsTagSignature) 0) continue;
// Linked tags are not written
if (Icc ->TagLinked[i] != (cmsTagSignature) 0) continue;
Icc -> TagOffsets[i] = Begin = io ->UsedSpace;
*** 1327,1341 ****
cmsUInt32Number UsedSpace;
cmsContext ContextID;
_cmsAssert(hProfile != NULL);
memmove(&Keep, Icc, sizeof(_cmsICCPROFILE));
ContextID = cmsGetProfileContextID(hProfile);
PrevIO = Icc ->IOhandler = cmsOpenIOhandlerFromNULL(ContextID);
! if (PrevIO == NULL) return 0;
// Pass #1 does compute offsets
if (!_cmsWriteHeader(Icc, 0)) goto Error;
if (!SaveTags(Icc, &Keep)) goto Error;
--- 1345,1363 ----
cmsUInt32Number UsedSpace;
cmsContext ContextID;
_cmsAssert(hProfile != NULL);
+ if (!_cmsLockMutex(Icc->ContextID, Icc->UsrMutex)) return 0;
memmove(&Keep, Icc, sizeof(_cmsICCPROFILE));
ContextID = cmsGetProfileContextID(hProfile);
PrevIO = Icc ->IOhandler = cmsOpenIOhandlerFromNULL(ContextID);
! if (PrevIO == NULL) {
! _cmsUnlockMutex(Icc->ContextID, Icc->UsrMutex);
! return 0;
! }
// Pass #1 does compute offsets
if (!_cmsWriteHeader(Icc, 0)) goto Error;
if (!SaveTags(Icc, &Keep)) goto Error;
*** 1351,1368 ****
if (!_cmsWriteHeader(Icc, UsedSpace)) goto Error;
if (!SaveTags(Icc, &Keep)) goto Error;
}
memmove(Icc, &Keep, sizeof(_cmsICCPROFILE));
! if (!cmsCloseIOhandler(PrevIO)) return 0;
return UsedSpace;
Error:
cmsCloseIOhandler(PrevIO);
memmove(Icc, &Keep, sizeof(_cmsICCPROFILE));
return 0;
}
// Low-level save to disk.
--- 1373,1395 ----
if (!_cmsWriteHeader(Icc, UsedSpace)) goto Error;
if (!SaveTags(Icc, &Keep)) goto Error;
}
memmove(Icc, &Keep, sizeof(_cmsICCPROFILE));
! if (!cmsCloseIOhandler(PrevIO))
! UsedSpace = 0; // As a error marker
!
! _cmsUnlockMutex(Icc->ContextID, Icc->UsrMutex);
return UsedSpace;
Error:
cmsCloseIOhandler(PrevIO);
memmove(Icc, &Keep, sizeof(_cmsICCPROFILE));
+ _cmsUnlockMutex(Icc->ContextID, Icc->UsrMutex);
+
return 0;
}
// Low-level save to disk.
*** 1562,1572 ****
LocalTypeHandler.ContextID = Icc ->ContextID;
LocalTypeHandler.ICCVersion = Icc ->Version;
Icc -> TagPtrs[n] = LocalTypeHandler.ReadPtr(&LocalTypeHandler, io, &ElemCount, TagSize);
! // The tag type is supported, but something wrong happend and we cannot read the tag.
// let know the user about this (although it is just a warning)
if (Icc -> TagPtrs[n] == NULL) {
char String[5];
--- 1589,1599 ----
LocalTypeHandler.ContextID = Icc ->ContextID;
LocalTypeHandler.ICCVersion = Icc ->Version;
Icc -> TagPtrs[n] = LocalTypeHandler.ReadPtr(&LocalTypeHandler, io, &ElemCount, TagSize);
! // The tag type is supported, but something wrong happened and we cannot read the tag.
// let know the user about this (although it is just a warning)
if (Icc -> TagPtrs[n] == NULL) {
char String[5];
*** 1881,1891 ****
Icc ->TagSizes[i] = Size;
_cmsUnlockMutex(Icc->ContextID, Icc ->UsrMutex);
if (Icc->TagPtrs[i] == NULL) {
! Icc->TagNames[i] = 0;
return FALSE;
}
return TRUE;
}
--- 1908,1918 ----
Icc ->TagSizes[i] = Size;
_cmsUnlockMutex(Icc->ContextID, Icc ->UsrMutex);
if (Icc->TagPtrs[i] == NULL) {
! Icc->TagNames[i] = (cmsTagSignature) 0;
return FALSE;
}
return TRUE;
}
< prev index next >