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 
29 static 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 
41 FIBITMAP* mng_ReadChunks(int format_id, FreeImageIO *io, fi_handle handle, long Offset, int flags = 0);
42 
43 
44 // ==========================================================
45 // Plugin Implementation
46 // ==========================================================
47 
48 static const char * DLL_CALLCONV
Format()49 Format() {
50 	return "MNG";
51 }
52 
53 static const char * DLL_CALLCONV
Description()54 Description() {
55 	return "Multiple-image Network Graphics";
56 }
57 
58 static const char * DLL_CALLCONV
Extension()59 Extension() {
60 	return "mng";
61 }
62 
63 static const char * DLL_CALLCONV
RegExpr()64 RegExpr() {
65 	return NULL;
66 }
67 
68 static const char * DLL_CALLCONV
MimeType()69 MimeType() {
70 	return "video/x-mng";
71 }
72 
73 static BOOL DLL_CALLCONV
Validate(FreeImageIO * io,fi_handle handle)74 Validate(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 
83 static BOOL DLL_CALLCONV
SupportsExportDepth(int depth)84 SupportsExportDepth(int depth) {
85 	return FALSE;
86 }
87 
88 static BOOL DLL_CALLCONV
SupportsExportType(FREE_IMAGE_TYPE type)89 SupportsExportType(FREE_IMAGE_TYPE type) {
90 	return FALSE;
91 }
92 
93 static BOOL DLL_CALLCONV
SupportsICCProfiles()94 SupportsICCProfiles() {
95 	return TRUE;
96 }
97 
98 static BOOL DLL_CALLCONV
SupportsNoPixels()99 SupportsNoPixels() {
100 	return FALSE;
101 }
102 
103 
104 // ----------------------------------------------------------
105 
106 static void * DLL_CALLCONV
Open(FreeImageIO * io,fi_handle handle,BOOL read)107 Open(FreeImageIO *io, fi_handle handle, BOOL read) {
108 	return NULL;
109 }
110 
111 static void DLL_CALLCONV
Close(FreeImageIO * io,fi_handle handle,void * data)112 Close(FreeImageIO *io, fi_handle handle, void *data) {
113 }
114 
115 static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO * io,fi_handle handle,int page,int flags,void * data)116 Load(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 
133 void DLL_CALLCONV
InitMNG(Plugin * plugin,int format_id)134 InitMNG(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 }
154