63 // In this way, is easier to add support for new storage media. 64 65 // NULL stream, for taking care of used space ------------------------------------- 66 67 // NULL IOhandler basically does nothing but keep track on how many bytes have been 68 // written. This is handy when creating profiles, where the file size is needed in the 69 // header. Then, whole profile is serialized across NULL IOhandler and a second pass 70 // writes the bytes to the pertinent IOhandler. 71 72 typedef struct { 73 cmsUInt32Number Pointer; // Points to current location 74 } FILENULL; 75 76 static 77 cmsUInt32Number NULLRead(cmsIOHANDLER* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count) 78 { 79 FILENULL* ResData = (FILENULL*) iohandler ->stream; 80 81 cmsUInt32Number len = size * count; 82 ResData -> Pointer += len; 83 return count; 84 85 cmsUNUSED_PARAMETER(Buffer); 86 } 87 88 static 89 cmsBool NULLSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset) 90 { 91 FILENULL* ResData = (FILENULL*) iohandler ->stream; 92 93 ResData ->Pointer = offset; 94 return TRUE; 95 } 96 97 static 98 cmsUInt32Number NULLTell(cmsIOHANDLER* iohandler) 99 { 100 FILENULL* ResData = (FILENULL*) iohandler ->stream; 101 return ResData -> Pointer; 102 } 103 104 static 105 cmsBool NULLWrite(cmsIOHANDLER* iohandler, cmsUInt32Number size, const void *Ptr) 106 { 107 FILENULL* ResData = (FILENULL*) iohandler ->stream; 108 109 ResData ->Pointer += size; 110 if (ResData ->Pointer > iohandler->UsedSpace) 111 iohandler->UsedSpace = ResData ->Pointer; 112 113 return TRUE; 114 115 cmsUNUSED_PARAMETER(Ptr); 116 } 117 118 static 119 cmsBool NULLClose(cmsIOHANDLER* iohandler) 120 { 121 FILENULL* ResData = (FILENULL*) iohandler ->stream; 122 123 _cmsFree(iohandler ->ContextID, ResData); 124 _cmsFree(iohandler ->ContextID, iohandler); 125 return TRUE; 126 } 127 128 // The NULL IOhandler creator 129 cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromNULL(cmsContext ContextID) 130 { 131 struct _cms_io_handler* iohandler = NULL; 132 FILENULL* fm = NULL; 133 134 iohandler = (struct _cms_io_handler*) _cmsMallocZero(ContextID, sizeof(struct _cms_io_handler)); 135 if (iohandler == NULL) return NULL; | 63 // In this way, is easier to add support for new storage media. 64 65 // NULL stream, for taking care of used space ------------------------------------- 66 67 // NULL IOhandler basically does nothing but keep track on how many bytes have been 68 // written. This is handy when creating profiles, where the file size is needed in the 69 // header. Then, whole profile is serialized across NULL IOhandler and a second pass 70 // writes the bytes to the pertinent IOhandler. 71 72 typedef struct { 73 cmsUInt32Number Pointer; // Points to current location 74 } FILENULL; 75 76 static 77 cmsUInt32Number NULLRead(cmsIOHANDLER* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count) 78 { 79 FILENULL* ResData = (FILENULL*) iohandler ->stream; 80 81 cmsUInt32Number len = size * count; 82 ResData -> Pointer += len; 83 cmsUNUSED_PARAMETER(Buffer); 84 85 return count; 86 87 } 88 89 static 90 cmsBool NULLSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset) 91 { 92 FILENULL* ResData = (FILENULL*) iohandler ->stream; 93 94 ResData ->Pointer = offset; 95 return TRUE; 96 } 97 98 static 99 cmsUInt32Number NULLTell(cmsIOHANDLER* iohandler) 100 { 101 FILENULL* ResData = (FILENULL*) iohandler ->stream; 102 return ResData -> Pointer; 103 } 104 105 static 106 cmsBool NULLWrite(cmsIOHANDLER* iohandler, cmsUInt32Number size, const void *Ptr) 107 { 108 FILENULL* ResData = (FILENULL*) iohandler ->stream; 109 110 ResData ->Pointer += size; 111 if (ResData ->Pointer > iohandler->UsedSpace) 112 iohandler->UsedSpace = ResData ->Pointer; 113 114 cmsUNUSED_PARAMETER(Ptr); 115 116 return TRUE; 117 118 } 119 120 static 121 cmsBool NULLClose(cmsIOHANDLER* iohandler) 122 { 123 FILENULL* ResData = (FILENULL*) iohandler ->stream; 124 125 _cmsFree(iohandler ->ContextID, ResData); 126 _cmsFree(iohandler ->ContextID, iohandler); 127 return TRUE; 128 } 129 130 // The NULL IOhandler creator 131 cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromNULL(cmsContext ContextID) 132 { 133 struct _cms_io_handler* iohandler = NULL; 134 FILENULL* fm = NULL; 135 136 iohandler = (struct _cms_io_handler*) _cmsMallocZero(ContextID, sizeof(struct _cms_io_handler)); 137 if (iohandler == NULL) return NULL; |