Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/MemoryIO.cpp view on Meta::CPAN
BOOL DLL_CALLCONV
FreeImage_SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FIMEMORY *stream, int flags) {
if (stream) {
FreeImageIO io;
SetMemoryIO(&io);
FIMEMORYHEADER *mem_header = (FIMEMORYHEADER*)(stream->data);
if(mem_header->delete_me == TRUE) {
return FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)stream, flags);
} else {
// do not save in a user buffer
FreeImage_OutputMessageProc(fif, "Memory buffer is read only");
}
}
return FALSE;
}
// =====================================================================
// Memory stream buffer access
// =====================================================================
BOOL DLL_CALLCONV
FreeImage_AcquireMemory(FIMEMORY *stream, BYTE **data, DWORD *size_in_bytes) {
if (stream) {
FIMEMORYHEADER *mem_header = (FIMEMORYHEADER*)(stream->data);
*data = (BYTE*)mem_header->data;
*size_in_bytes = mem_header->file_length;
return TRUE;
}
return FALSE;
}
// =====================================================================
// Memory stream file type access
// =====================================================================
FREE_IMAGE_FORMAT DLL_CALLCONV
FreeImage_GetFileTypeFromMemory(FIMEMORY *stream, int size) {
FreeImageIO io;
SetMemoryIO(&io);
if (stream != NULL) {
return FreeImage_GetFileTypeFromHandle(&io, (fi_handle)stream, size);
}
return FIF_UNKNOWN;
}
// =====================================================================
// Seeking in Memory stream
// =====================================================================
/**
Moves the memory pointer to a specified location
@param stream Pointer to FIMEMORY structure
@param offset Number of bytes from origin
@param origin Initial position
@return Returns TRUE if successful, returns FALSE otherwise
*/
BOOL DLL_CALLCONV
FreeImage_SeekMemory(FIMEMORY *stream, long offset, int origin) {
FreeImageIO io;
SetMemoryIO(&io);
if (stream != NULL) {
int success = io.seek_proc((fi_handle)stream, offset, origin);
return (success == 0) ? TRUE : FALSE;
}
return FALSE;
}
/**
Gets the current position of a memory pointer
@param stream Target FIMEMORY structure
@return Returns the current file position if successful, -1 otherwise
*/
long DLL_CALLCONV
FreeImage_TellMemory(FIMEMORY *stream) {
FreeImageIO io;
SetMemoryIO(&io);
if (stream != NULL) {
return io.tell_proc((fi_handle)stream);
}
return -1L;
}
// =====================================================================
// Reading or Writing in Memory stream
// =====================================================================
/**
Reads data from a memory stream
@param buffer Storage location for data
@param size Item size in bytes
@param count Maximum number of items to be read
@param stream Pointer to FIMEMORY structure
@return Returns the number of full items actually read, which may be less than count if an error occurs
*/
unsigned DLL_CALLCONV
FreeImage_ReadMemory(void *buffer, unsigned size, unsigned count, FIMEMORY *stream) {
FreeImageIO io;
SetMemoryIO(&io);
if (stream != NULL) {
return io.read_proc(buffer, size, count, stream);
}
return 0;
}
/**
Writes data to a memory stream.
@param buffer Pointer to data to be written
@param size Item size in bytes
@param count Maximum number of items to be written
@param stream Pointer to FIMEMORY structure
@return Returns the number of full items actually written, which may be less than count if an error occurs
*/
unsigned DLL_CALLCONV
FreeImage_WriteMemory(const void *buffer, unsigned size, unsigned count, FIMEMORY *stream) {
if (stream != NULL) {
FreeImageIO io;
SetMemoryIO(&io);
( run in 0.632 second using v1.01-cache-2.11-cpan-5b529ec07f3 )