Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginHDR.cpp view on Meta::CPAN
static const char * DLL_CALLCONV
RegExpr() {
return NULL;
}
static const char * DLL_CALLCONV
MimeType() {
return "image/vnd.radiance";
}
static BOOL DLL_CALLCONV
Validate(FreeImageIO *io, fi_handle handle) {
BYTE hdr_signature[] = { '#', '?' };
BYTE signature[] = { 0, 0 };
io->read_proc(signature, 1, 2, handle);
return (memcmp(hdr_signature, signature, 2) == 0);
}
static BOOL DLL_CALLCONV
SupportsExportDepth(int depth) {
return FALSE;
}
static BOOL DLL_CALLCONV
SupportsExportType(FREE_IMAGE_TYPE type) {
return (type == FIT_RGBF) ? TRUE : FALSE;
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// --------------------------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
FIBITMAP *dib = NULL;
if(!handle) {
return NULL;
}
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
try {
rgbeHeaderInfo header_info;
unsigned width, height;
// Read the header
if(rgbe_ReadHeader(io, handle, &width, &height, &header_info) == FALSE) {
return NULL;
}
// allocate a RGBF image
dib = FreeImage_AllocateHeaderT(header_only, FIT_RGBF, width, height);
if(!dib) {
throw FI_MSG_ERROR_MEMORY;
}
// set the metadata as comments
rgbe_ReadMetadata(dib, &header_info);
if(header_only) {
// header only mode
return dib;
}
// read the image pixels and fill the dib
for(unsigned y = 0; y < height; y++) {
FIRGBF *scanline = (FIRGBF*)FreeImage_GetScanLine(dib, height - 1 - y);
if(!rgbe_ReadPixels_RLE(io, handle, scanline, width, 1)) {
FreeImage_Unload(dib);
return NULL;
}
}
}
catch(const char *text) {
if(dib != NULL) {
FreeImage_Unload(dib);
}
FreeImage_OutputMessageProc(s_format_id, text);
}
return dib;
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
if(!dib) return FALSE;
FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib);
if(src_type != FIT_RGBF) {
FreeImage_OutputMessageProc(s_format_id, "FREE_IMAGE_TYPE: Unable to convert from type %d to type %d.\n No such conversion exists.", src_type, FIT_RGBF);
return FALSE;
}
unsigned width = FreeImage_GetWidth(dib);
unsigned height = FreeImage_GetHeight(dib);
// write the header
rgbeHeaderInfo header_info;
memset(&header_info, 0, sizeof(rgbeHeaderInfo));
// fill the header with correct gamma and exposure
rgbe_WriteMetadata(dib, &header_info);
// fill a comment
sprintf(header_info.comment, "# Made with FreeImage %s", FreeImage_GetVersion());
if(!rgbe_WriteHeader(io, handle, width, height, &header_info)) {
return FALSE;
}
// write each scanline
for(unsigned y = 0; y < height; y++) {
FIRGBF *scanline = (FIRGBF*)FreeImage_GetScanLine(dib, height - 1 - y);
( run in 0.749 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )