Lines Matching refs:IOhandler
32 // memory block or any storage. Each IOhandler provides implementations for read,
38 // NULL IOhandler basically does nothing but keep track on how many bytes have been
40 // header. Then, whole profile is serialized across NULL IOhandler and a second pass
41 // writes the bytes to the pertinent IOhandler.
48 cmsUInt32Number NULLRead(cmsIOHANDLER* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count)
50 FILENULL* ResData = (FILENULL*) iohandler ->stream;
60 cmsBool NULLSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset)
62 FILENULL* ResData = (FILENULL*) iohandler ->stream;
69 cmsUInt32Number NULLTell(cmsIOHANDLER* iohandler)
71 FILENULL* ResData = (FILENULL*) iohandler ->stream;
76 cmsBool NULLWrite(cmsIOHANDLER* iohandler, cmsUInt32Number size, const void *Ptr)
78 FILENULL* ResData = (FILENULL*) iohandler ->stream;
81 if (ResData ->Pointer > iohandler->UsedSpace)
82 iohandler->UsedSpace = ResData ->Pointer;
90 cmsBool NULLClose(cmsIOHANDLER* iohandler)
92 FILENULL* ResData = (FILENULL*) iohandler ->stream;
94 _cmsFree(iohandler ->ContextID, ResData);
95 _cmsFree(iohandler ->ContextID, iohandler);
99 // The NULL IOhandler creator
102 struct _cms_io_handler* iohandler = NULL;
105 iohandler = (struct _cms_io_handler*) _cmsMallocZero(ContextID, sizeof(struct _cms_io_handler));
106 if (iohandler == NULL) return NULL;
113 iohandler ->ContextID = ContextID;
114 iohandler ->stream = (void*) fm;
115 iohandler ->UsedSpace = 0;
116 iohandler ->ReportedSize = 0;
117 iohandler ->PhysicalFile[0] = 0;
119 iohandler ->Read = NULLRead;
120 iohandler ->Seek = NULLSeek;
121 iohandler ->Close = NULLClose;
122 iohandler ->Tell = NULLTell;
123 iohandler ->Write = NULLWrite;
125 return iohandler;
128 if (iohandler) _cmsFree(ContextID, iohandler);
136 // Those functions implements an iohandler which takes a block of memory as storage medium.
147 cmsUInt32Number MemoryRead(struct _cms_io_handler* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count)
149 FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
156 cmsSignalError(iohandler ->ContextID, cmsERROR_READ, "Read from memory error. Got %d bytes, block should be of %d bytes", len, count * size);
170 cmsBool MemorySeek(struct _cms_io_handler* iohandler, cmsUInt32Number offset)
172 FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
175 cmsSignalError(iohandler ->ContextID, cmsERROR_SEEK, "Too few data; probably corrupted profile");
185 cmsUInt32Number MemoryTell(struct _cms_io_handler* iohandler)
187 FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
196 cmsBool MemoryWrite(struct _cms_io_handler* iohandler, cmsUInt32Number size, const void *Ptr)
198 FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
212 if (ResData ->Pointer > iohandler->UsedSpace)
213 iohandler->UsedSpace = ResData ->Pointer;
220 cmsBool MemoryClose(struct _cms_io_handler* iohandler)
222 FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
226 if (ResData ->Block) _cmsFree(iohandler ->ContextID, ResData ->Block);
229 _cmsFree(iohandler ->ContextID, ResData);
230 _cmsFree(iohandler ->ContextID, iohandler);
235 // Create a iohandler for memory block. AccessMode=='r' assumes the iohandler is going to read, and makes
240 cmsIOHANDLER* iohandler = NULL;
245 iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
246 if (iohandler == NULL) return NULL;
263 _cmsFree(ContextID, iohandler);
273 iohandler -> ReportedSize = size;
284 iohandler -> ReportedSize = 0;
292 iohandler ->ContextID = ContextID;
293 iohandler ->stream = (void*) fm;
294 iohandler ->UsedSpace = 0;
295 iohandler ->PhysicalFile[0] = 0;
297 iohandler ->Read = MemoryRead;
298 iohandler ->Seek = MemorySeek;
299 iohandler ->Close = MemoryClose;
300 iohandler ->Tell = MemoryTell;
301 iohandler ->Write = MemoryWrite;
303 return iohandler;
307 if (iohandler) _cmsFree(ContextID, iohandler);
315 cmsUInt32Number FileRead(cmsIOHANDLER* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count)
317 cmsUInt32Number nReaded = (cmsUInt32Number) fread(Buffer, size, count, (FILE*) iohandler->stream);
320 cmsSignalError(iohandler ->ContextID, cmsERROR_FILE, "Read error. Got %d bytes, block should be of %d bytes", nReaded * size, count * size);
329 cmsBool FileSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset)
331 if (fseek((FILE*) iohandler ->stream, (long) offset, SEEK_SET) != 0) {
333 cmsSignalError(iohandler ->ContextID, cmsERROR_FILE, "Seek error; probably corrupted file");
342 cmsUInt32Number FileTell(cmsIOHANDLER* iohandler)
344 return (cmsUInt32Number) ftell((FILE*)iohandler ->stream);
349 cmsBool FileWrite(cmsIOHANDLER* iohandler, cmsUInt32Number size, const void* Buffer)
353 iohandler->UsedSpace += size;
354 return (fwrite(Buffer, size, 1, (FILE*) iohandler->stream) == 1);
359 cmsBool FileClose(cmsIOHANDLER* iohandler)
361 if (fclose((FILE*) iohandler ->stream) != 0) return FALSE;
362 _cmsFree(iohandler ->ContextID, iohandler);
366 // Create a iohandler for disk based files.
369 cmsIOHANDLER* iohandler = NULL;
376 iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
377 if (iohandler == NULL) return NULL;
384 _cmsFree(ContextID, iohandler);
392 _cmsFree(ContextID, iohandler);
397 iohandler -> ReportedSize = (cmsUInt32Number) fileLen;
403 _cmsFree(ContextID, iohandler);
407 iohandler -> ReportedSize = 0;
411 _cmsFree(ContextID, iohandler);
416 iohandler ->ContextID = ContextID;
417 iohandler ->stream = (void*) fm;
418 iohandler ->UsedSpace = 0;
421 strncpy(iohandler -> PhysicalFile, FileName, sizeof(iohandler -> PhysicalFile)-1);
422 iohandler -> PhysicalFile[sizeof(iohandler -> PhysicalFile)-1] = 0;
424 iohandler ->Read = FileRead;
425 iohandler ->Seek = FileSeek;
426 iohandler ->Close = FileClose;
427 iohandler ->Tell = FileTell;
428 iohandler ->Write = FileWrite;
430 return iohandler;
433 // Create a iohandler for stream based files
436 cmsIOHANDLER* iohandler = NULL;
446 iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
447 if (iohandler == NULL) return NULL;
449 iohandler -> ContextID = ContextID;
450 iohandler -> stream = (void*) Stream;
451 iohandler -> UsedSpace = 0;
452 iohandler -> ReportedSize = (cmsUInt32Number) fileSize;
453 iohandler -> PhysicalFile[0] = 0;
455 iohandler ->Read = FileRead;
456 iohandler ->Seek = FileSeek;
457 iohandler ->Close = FileClose;
458 iohandler ->Tell = FileTell;
459 iohandler ->Write = FileWrite;
461 return iohandler;
479 return Icc->IOhandler;
701 cmsIOHANDLER* io = Icc ->IOhandler;
734 if (HeaderSize >= Icc ->IOhandler ->ReportedSize)
735 HeaderSize = Icc ->IOhandler ->ReportedSize;
839 if (!Icc -> IOhandler->Write(Icc->IOhandler, sizeof(cmsICCHeader), &Header)) return FALSE;
850 if (!_cmsWriteUInt32Number(Icc ->IOhandler, Count)) return FALSE;
860 if (!Icc ->IOhandler -> Write(Icc-> IOhandler, sizeof(cmsTagEntry), &Tag)) return FALSE;
1042 // Create profile from IOhandler
1052 NewIcc ->IOhandler = io;
1061 // Create profile from IOhandler
1071 NewIcc ->IOhandler = io;
1097 NewIcc ->IOhandler = cmsOpenIOhandlerFromFile(ContextID, lpFileName, sAccess);
1098 if (NewIcc ->IOhandler == NULL) goto Error;
1131 NewIcc ->IOhandler = cmsOpenIOhandlerFromStream(ContextID, ICCProfile);
1132 if (NewIcc ->IOhandler == NULL) goto Error;
1168 NewIcc ->IOhandler = cmsOpenIOhandlerFromMem(ContextID, (void*) MemPtr, dwSize, "r");
1169 if (NewIcc ->IOhandler == NULL) goto Error;
1194 cmsIOHANDLER* io = Icc ->IOhandler;
1223 if (!FileOrig ->IOhandler->Seek(FileOrig ->IOhandler, TagOffset)) return FALSE;
1228 if (FileOrig ->IOhandler->Read(FileOrig->IOhandler, Mem, TagSize, 1) != 1) return FALSE;
1325 // Low-level save to IOHANDLER. It returns the number of bytes used to
1342 PrevIO = Icc ->IOhandler = cmsOpenIOhandlerFromNULL(ContextID);
1355 // Pass #2 does save to iohandler
1359 Icc ->IOhandler = io;
1464 rc &= cmsSaveProfileToFile(hProfile, Icc ->IOhandler->PhysicalFile);
1485 if (Icc ->IOhandler != NULL) {
1486 rc &= cmsCloseIOhandler(Icc->IOhandler);
1522 cmsIOHANDLER* io = Icc ->IOhandler;
1804 if (!Icc ->IOhandler ->Seek(Icc ->IOhandler, Offset)) goto Error;
1805 if (!Icc ->IOhandler ->Read(Icc ->IOhandler, data, 1, TagSize)) goto Error;
1844 // Now we need to serialize to a memory block: just use a memory iohandler