LPLCMSICCPROFILE _cmsCreateProfileFromMemPlaceholder(LPVOID MemPtr, DWORD dwSize) { LPLCMSICCPROFILE NewIcc; LPVOID ICCfile = MemoryOpen((LPBYTE) MemPtr, (size_t) dwSize, 'r'); if (ICCfile == NULL) { cmsSignalError(LCMS_ERRC_ABORTED, "Couldn't allocate %ld bytes for profile", dwSize); return NULL; } NewIcc = (LPLCMSICCPROFILE) _cmsCreateProfilePlaceholder(); if (NewIcc == NULL) return NULL; NewIcc -> PhysicalFile[0] = 0; NewIcc ->stream = ICCfile; NewIcc ->Read = MemoryRead; NewIcc ->Seek = MemorySeek; NewIcc ->Tell = MemoryTell; NewIcc ->Close = MemoryClose; NewIcc ->Grow = MemoryGrow; NewIcc ->Write = MemoryWrite; NewIcc ->IsWrite = FALSE; return NewIcc; }
void _cmsSetSaveToMemory(LPLCMSICCPROFILE Icc, LPVOID MemPtr, size_t dwSize) { if (MemPtr == NULL) { Icc ->stream = NULL; } else { Icc ->stream = (FILEMEM*) MemoryOpen((LPBYTE) MemPtr, dwSize, 'w'); if (Icc ->stream == NULL) cmsSignalError(LCMS_ERRC_ABORTED, "Couldn't write to memory"); } Icc ->Write = MemoryWrite; Icc ->Close = MemoryClose; }
MemoryStream* StreamCreateFromMemory(Allocator* alloc, uint64 size) { MemoryStream* ms = Allocate(alloc, MemoryStream); if( !ms ) return nullptr; StreamMemoryInit(ms); if( !MemoryOpen(ms) ) { Deallocate(ms); return nullptr; } MemoryResize(ms, size); return ms; }