Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginEXR.cpp view on Meta::CPAN
// ==========================================================
// EXR Loader and writer
//
// Design and implementation by
// - Hervé Drolon (drolon@infonie.fr)
// - Mihail Naydenov (mnaydenov@users.sourceforge.net)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#include "FreeImage.h"
#include "Utilities.h"
#ifdef _MSC_VER
// OpenEXR has many problems with MSVC warnings (why not just correct them ?), just ignore one of them
#pragma warning (disable : 4800) // ImfVersion.h - 'const int' : forcing value to bool 'true' or 'false' (performance warning)
#endif
#include "../OpenEXR/IlmImf/ImfIO.h"
#include "../OpenEXR/Iex/Iex.h"
#include "../OpenEXR/IlmImf/ImfOutputFile.h"
#include "../OpenEXR/IlmImf/ImfInputFile.h"
#include "../OpenEXR/IlmImf/ImfRgbaFile.h"
#include "../OpenEXR/IlmImf/ImfChannelList.h"
#include "../OpenEXR/IlmImf/ImfRgba.h"
#include "../OpenEXR/IlmImf/ImfArray.h"
#include "../OpenEXR/IlmImf/ImfPreviewImage.h"
#include "../OpenEXR/Half/half.h"
// ==========================================================
// Plugin Interface
// ==========================================================
static int s_format_id;
// ----------------------------------------------------------
/**
FreeImage input stream wrapper
@see Imf_2_2::IStream
*/
class C_IStream : public Imf::IStream {
private:
FreeImageIO *_io;
fi_handle _handle;
public:
C_IStream (FreeImageIO *io, fi_handle handle) :
Imf::IStream(""), _io (io), _handle(handle) {
}
virtual bool read (char c[/*n*/], int n) {
return ((unsigned)n != _io->read_proc(c, 1, n, _handle));
}
virtual Imath::Int64 tellg() {
return _io->tell_proc(_handle);
}
virtual void seekg(Imath::Int64 pos) {
_io->seek_proc(_handle, (unsigned)pos, SEEK_SET);
}
virtual void clear() {
}
};
// ----------------------------------------------------------
/**
FreeImage output stream wrapper
@see Imf_2_2::OStream
*/
class C_OStream : public Imf::OStream {
private:
FreeImageIO *_io;
fi_handle _handle;
public:
C_OStream (FreeImageIO *io, fi_handle handle) :
Imf::OStream(""), _io (io), _handle(handle) {
}
virtual void write(const char c[/*n*/], int n) {
if((unsigned)n != _io->write_proc((void*)&c[0], 1, n, _handle)) {
Iex::throwErrnoExc();
}
}
virtual Imath::Int64 tellp() {
return _io->tell_proc(_handle);
}
virtual void seekp(Imath::Int64 pos) {
_io->seek_proc(_handle, (unsigned)pos, SEEK_SET);
}
};
// ----------------------------------------------------------
// ==========================================================
// Plugin Implementation
// ==========================================================
static const char * DLL_CALLCONV
Format() {
return "EXR";
}
static const char * DLL_CALLCONV
Description() {
return "ILM OpenEXR";
}
static const char * DLL_CALLCONV
Extension() {
return "exr";
}
static const char * DLL_CALLCONV
RegExpr() {
return NULL;
}
static const char * DLL_CALLCONV
MimeType() {
return "image/x-exr";
}
static BOOL DLL_CALLCONV
Validate(FreeImageIO *io, fi_handle handle) {
BYTE exr_signature[] = { 0x76, 0x2F, 0x31, 0x01 };
BYTE signature[] = { 0, 0, 0, 0 };
io->read_proc(signature, 1, 4, handle);
return (memcmp(exr_signature, signature, 4) == 0);
}
( run in 0.498 second using v1.01-cache-2.11-cpan-62a16548d74 )