PageRenderTime 541ms CodeModel.GetById 532ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/FreeImage/Source/FreeImage/PluginMNG.cpp

https://bitbucket.org/cabalistic/ogredeps/
C++ | 153 lines | 83 code | 33 blank | 37 comment | 3 complexity | c79a17bb4a8767e10d3932f22a48518c MD5 | raw file
  1// ==========================================================
  2// MNG loader
  3//
  4// Design and implementation by
  5// - Herve Drolon (drolon@infonie.fr)
  6//
  7// This file is part of FreeImage 3
  8//
  9// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
 10// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
 11// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
 12// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
 13// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
 14// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
 15// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
 16// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
 17// THIS DISCLAIMER.
 18//
 19// Use at your own risk!
 20// ==========================================================
 21
 22#include "FreeImage.h"
 23#include "Utilities.h"
 24
 25// ==========================================================
 26// Plugin Interface
 27// ==========================================================
 28
 29static int s_format_id;
 30
 31// ----------------------------------------------------------
 32
 33#define MNG_SIGNATURE_SIZE 8	// size of the signature
 34
 35// ----------------------------------------------------------
 36
 37// ----------------------------------------------------------
 38//   mng interface (see MNGHelper.cpp)
 39// ----------------------------------------------------------
 40
 41FIBITMAP* mng_ReadChunks(int format_id, FreeImageIO *io, fi_handle handle, long Offset, int flags = 0);
 42
 43
 44// ==========================================================
 45// Plugin Implementation
 46// ==========================================================
 47
 48static const char * DLL_CALLCONV
 49Format() {
 50	return "MNG";
 51}
 52
 53static const char * DLL_CALLCONV
 54Description() {
 55	return "Multiple-image Network Graphics";
 56}
 57
 58static const char * DLL_CALLCONV
 59Extension() {
 60	return "mng";
 61}
 62
 63static const char * DLL_CALLCONV
 64RegExpr() {
 65	return NULL;
 66}
 67
 68static const char * DLL_CALLCONV
 69MimeType() {
 70	return "video/x-mng";
 71}
 72
 73static BOOL DLL_CALLCONV
 74Validate(FreeImageIO *io, fi_handle handle) {
 75	BYTE mng_signature[8] = { 138, 77, 78, 71, 13, 10, 26, 10 };
 76	BYTE signature[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
 77
 78	io->read_proc(&signature, 1, MNG_SIGNATURE_SIZE, handle);
 79
 80	return (memcmp(mng_signature, signature, MNG_SIGNATURE_SIZE) == 0) ? TRUE : FALSE;
 81}
 82
 83static BOOL DLL_CALLCONV
 84SupportsExportDepth(int depth) {
 85	return FALSE;
 86}
 87
 88static BOOL DLL_CALLCONV 
 89SupportsExportType(FREE_IMAGE_TYPE type) {
 90	return FALSE;
 91}
 92
 93static BOOL DLL_CALLCONV
 94SupportsICCProfiles() {
 95	return TRUE;
 96}
 97
 98static BOOL DLL_CALLCONV
 99SupportsNoPixels() {
100	return FALSE;
101}
102
103
104// ----------------------------------------------------------
105
106static void * DLL_CALLCONV
107Open(FreeImageIO *io, fi_handle handle, BOOL read) {
108	return NULL;
109}
110
111static void DLL_CALLCONV
112Close(FreeImageIO *io, fi_handle handle, void *data) {
113}
114
115static FIBITMAP * DLL_CALLCONV
116Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
117	long offset = MNG_SIGNATURE_SIZE;	// move to skip first 8 bytes of signature
118
119	// check the signature (8 bytes)
120	if(Validate(io, handle) == FALSE) {
121		return NULL;
122	}
123	
124	// parse chunks and decode a jng or mng bitmap
125	return mng_ReadChunks(s_format_id, io, handle, offset, flags);
126}
127
128
129// ==========================================================
130//   Init
131// ==========================================================
132
133void DLL_CALLCONV
134InitMNG(Plugin *plugin, int format_id) {
135	s_format_id = format_id;
136
137	plugin->format_proc = Format;
138	plugin->description_proc = Description;
139	plugin->extension_proc = Extension;
140	plugin->regexpr_proc = RegExpr;
141	plugin->open_proc = Open;
142	plugin->close_proc = Close;
143	plugin->pagecount_proc = NULL;
144	plugin->pagecapability_proc = NULL;
145	plugin->load_proc = Load;
146	plugin->save_proc = NULL;
147	plugin->validate_proc = Validate;
148	plugin->mime_proc = MimeType;
149	plugin->supports_export_bpp_proc = SupportsExportDepth;
150	plugin->supports_export_type_proc = SupportsExportType;
151	plugin->supports_icc_profiles_proc = SupportsICCProfiles;
152	plugin->supports_no_pixels_proc = SupportsNoPixels;
153}