Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginJXR.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// ==========================================================
// Open & Close
// ==========================================================
static void * DLL_CALLCONV
Open(FreeImageIO *io, fi_handle handle, BOOL read) {
WMPStream *pStream = NULL; // stream interface
if(io && handle) {
// allocate the FreeImageIO stream wrapper
FreeImageJXRIO *jxr_io = (FreeImageJXRIO*)malloc(sizeof(FreeImageJXRIO));
if(jxr_io) {
jxr_io->io = io;
jxr_io->handle = handle;
// create a JXR stream wrapper
if(_jxr_io_Create(&pStream, jxr_io) != WMP_errSuccess) {
free(jxr_io);
return NULL;
}
}
}
return pStream;
}
static void DLL_CALLCONV
Close(FreeImageIO *io, fi_handle handle, void *data) {
WMPStream *pStream = (WMPStream*)data;
if(pStream) {
// free the FreeImageIO stream wrapper
FreeImageJXRIO *jxr_io = (FreeImageJXRIO*)pStream->state.pvObj;
free(jxr_io);
// free the JXR stream wrapper
pStream->fMem = TRUE;
_jxr_io_Close(&pStream);
}
}
// ==========================================================
// Load
// ==========================================================
/**
Set decoder parameters
@param pDecoder Decoder handle
@param flags FreeImage load flags
*/
static void
SetDecoderParameters(PKImageDecode *pDecoder, int flags) {
// load image & alpha for formats with alpha
pDecoder->WMP.wmiSCP.uAlphaMode = 2;
// more options to come ...
}
/**
Copy or convert & copy decoded pixels into the dib
@param pDecoder Decoder handle
@param out_guid_format Target guid format
@param dib Output dib
@param width Image width
@param height Image height
@return Returns 0 if successful, returns ERR otherwise
*/
static ERR
CopyPixels(PKImageDecode *pDecoder, PKPixelFormatGUID out_guid_format, FIBITMAP *dib, int width, int height) {
PKFormatConverter *pConverter = NULL; // pixel format converter
ERR error_code = 0; // error code as returned by the interface
BYTE *pb = NULL; // local buffer used for pixel format conversion
// image dimensions
const PKRect rect = {0, 0, width, height};
try {
// get input file pixel format ...
PKPixelFormatGUID in_guid_format;
error_code = pDecoder->GetPixelFormat(pDecoder, &in_guid_format);
JXR_CHECK(error_code);
// is a format conversion needed ?
if(IsEqualGUID(out_guid_format, in_guid_format)) {
// no conversion, load bytes "as is" ...
// get a pointer to dst pixel data
BYTE *dib_bits = FreeImage_GetBits(dib);
// get dst pitch (count of BYTE for stride)
const unsigned cbStride = FreeImage_GetPitch(dib);
// decode and copy bits to dst array
error_code = pDecoder->Copy(pDecoder, &rect, dib_bits, cbStride);
JXR_CHECK(error_code);
}
else {
// we need to use the conversion API ...
// allocate the pixel format converter
error_code = PKCodecFactory_CreateFormatConverter(&pConverter);
JXR_CHECK(error_code);
// set the conversion function
error_code = pConverter->Initialize(pConverter, pDecoder, NULL, out_guid_format);
JXR_CHECK(error_code);
// get the maximum stride
unsigned cbStride = 0;
{
PKPixelInfo pPIFrom;
PKPixelInfo pPITo;
pPIFrom.pGUIDPixFmt = &in_guid_format;
error_code = PixelFormatLookup(&pPIFrom, LOOKUP_FORWARD);
JXR_CHECK(error_code);
pPITo.pGUIDPixFmt = &out_guid_format;
error_code = PixelFormatLookup(&pPITo, LOOKUP_FORWARD);
( run in 1.032 second using v1.01-cache-2.11-cpan-8450f2e95f3 )