Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginJPEG.cpp view on Meta::CPAN
// 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!
// ==========================================================
#ifdef _MSC_VER
#pragma warning (disable : 4786) // identifier was truncated to 'number' characters
#endif
extern "C" {
#define XMD_H
#undef FAR
#include <setjmp.h>
#include "../LibJPEG/jinclude.h"
#include "../LibJPEG/jpeglib.h"
#include "../LibJPEG/jerror.h"
}
#include "FreeImage.h"
#include "Utilities.h"
#include "../Metadata/FreeImageTag.h"
// ==========================================================
// Plugin Interface
// ==========================================================
static int s_format_id;
// ----------------------------------------------------------
// Constant declarations
// ----------------------------------------------------------
#define INPUT_BUF_SIZE 4096 // choose an efficiently fread'able size
#define OUTPUT_BUF_SIZE 4096 // choose an efficiently fwrite'able size
#define EXIF_MARKER (JPEG_APP0+1) // EXIF marker / Adobe XMP marker
#define ICC_MARKER (JPEG_APP0+2) // ICC profile marker
#define IPTC_MARKER (JPEG_APP0+13) // IPTC marker / BIM marker
#define ICC_HEADER_SIZE 14 // size of non-profile data in APP2
#define MAX_BYTES_IN_MARKER 65533L // maximum data length of a JPEG marker
#define MAX_DATA_BYTES_IN_MARKER 65519L // maximum data length of a JPEG APP2 marker
#define MAX_JFXX_THUMB_SIZE (MAX_BYTES_IN_MARKER - 5 - 1)
#define JFXX_TYPE_JPEG 0x10 // JFIF extension marker: JPEG-compressed thumbnail image
#define JFXX_TYPE_8bit 0x11 // JFIF extension marker: palette thumbnail image
#define JFXX_TYPE_24bit 0x13 // JFIF extension marker: RGB thumbnail image
// ----------------------------------------------------------
// Typedef declarations
// ----------------------------------------------------------
typedef struct tagErrorManager {
/// "public" fields
struct jpeg_error_mgr pub;
/// for return to caller
jmp_buf setjmp_buffer;
} ErrorManager;
typedef struct tagSourceManager {
/// public fields
struct jpeg_source_mgr pub;
/// source stream
fi_handle infile;
FreeImageIO *m_io;
/// start of buffer
JOCTET * buffer;
/// have we gotten any data yet ?
boolean start_of_file;
} SourceManager;
typedef struct tagDestinationManager {
/// public fields
struct jpeg_destination_mgr pub;
/// destination stream
fi_handle outfile;
FreeImageIO *m_io;
/// start of buffer
JOCTET * buffer;
} DestinationManager;
typedef SourceManager* freeimage_src_ptr;
typedef DestinationManager* freeimage_dst_ptr;
typedef ErrorManager* freeimage_error_ptr;
// ----------------------------------------------------------
// Error handling
// ----------------------------------------------------------
/** Fatal errors (print message and exit) */
static inline void
JPEG_EXIT(j_common_ptr cinfo, int code) {
freeimage_error_ptr error_ptr = (freeimage_error_ptr)cinfo->err;
error_ptr->pub.msg_code = code;
error_ptr->pub.error_exit(cinfo);
}
/** Nonfatal errors (we can keep going, but the data is probably corrupt) */
static inline void
JPEG_WARNING(j_common_ptr cinfo, int code) {
freeimage_error_ptr error_ptr = (freeimage_error_ptr)cinfo->err;
error_ptr->pub.msg_code = code;
error_ptr->pub.emit_message(cinfo, -1);
}
/**
Receives control for a fatal error. Information sufficient to
generate the error message has been stored in cinfo->err; call
output_message to display it. Control must NOT return to the caller;
generally this routine will exit() or longjmp() somewhere.
*/
METHODDEF(void)
jpeg_error_exit (j_common_ptr cinfo) {
freeimage_error_ptr error_ptr = (freeimage_error_ptr)cinfo->err;
// always display the message
error_ptr->pub.output_message(cinfo);
// allow JPEG with unknown markers
if(error_ptr->pub.msg_code != JERR_UNKNOWN_MARKER) {
// let the memory manager delete any temp files before we die
jpeg_destroy(cinfo);
// return control to the setjmp point
longjmp(error_ptr->setjmp_buffer, 1);
}
}
/**
Actual output of any JPEG message. Note that this method does not know
how to generate a message, only where to send it.
*/
( run in 0.854 second using v1.01-cache-2.11-cpan-62a16548d74 )