1 // ==========================================================
2 // JNG 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 JNG_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 BOOL mng_WriteJNG(int format_id, FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int flags);
43
44 // ==========================================================
45 // Plugin Implementation
46 // ==========================================================
47
48 static const char * DLL_CALLCONV
Format()49 Format() {
50 return "JNG";
51 }
52
53 static const char * DLL_CALLCONV
Description()54 Description() {
55 return "JPEG Network Graphics";
56 }
57
58 static const char * DLL_CALLCONV
Extension()59 Extension() {
60 return "jng";
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 "image/x-mng";
71 }
72
73 static BOOL DLL_CALLCONV
Validate(FreeImageIO * io,fi_handle handle)74 Validate(FreeImageIO *io, fi_handle handle) {
75 BYTE jng_signature[8] = { 139, 74, 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, JNG_SIGNATURE_SIZE, handle);
79
80 return (memcmp(jng_signature, signature, JNG_SIGNATURE_SIZE) == 0) ? TRUE : FALSE;
81 }
82
83 static BOOL DLL_CALLCONV
SupportsExportDepth(int depth)84 SupportsExportDepth(int depth) {
85 return (
86 (depth == 8) ||
87 (depth == 24) ||
88 (depth == 32)
89 );
90 }
91
92 static BOOL DLL_CALLCONV
SupportsExportType(FREE_IMAGE_TYPE type)93 SupportsExportType(FREE_IMAGE_TYPE type) {
94 return (type == FIT_BITMAP) ? TRUE : FALSE;
95 }
96
97 static BOOL DLL_CALLCONV
SupportsICCProfiles()98 SupportsICCProfiles() {
99 return TRUE;
100 }
101
102 static BOOL DLL_CALLCONV
SupportsNoPixels()103 SupportsNoPixels() {
104 return TRUE;
105 }
106
107
108 // ----------------------------------------------------------
109
110 static void * DLL_CALLCONV
Open(FreeImageIO * io,fi_handle handle,BOOL read)111 Open(FreeImageIO *io, fi_handle handle, BOOL read) {
112 return NULL;
113 }
114
115 static void DLL_CALLCONV
Close(FreeImageIO * io,fi_handle handle,void * data)116 Close(FreeImageIO *io, fi_handle handle, void *data) {
117 }
118
119 static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO * io,fi_handle handle,int page,int flags,void * data)120 Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
121 long offset = JNG_SIGNATURE_SIZE; // move to skip first 8 bytes of signature
122
123 // check the signature (8 bytes)
124 if(Validate(io, handle) == FALSE) {
125 return NULL;
126 }
127
128 // parse chunks and decode a jng or mng bitmap
129 return mng_ReadChunks(s_format_id, io, handle, offset, flags);
130 }
131
132 static BOOL DLL_CALLCONV
Save(FreeImageIO * io,FIBITMAP * dib,fi_handle handle,int page,int flags,void * data)133 Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
134
135 return mng_WriteJNG(s_format_id, io, dib, handle, flags);
136 }
137
138 // ==========================================================
139 // Init
140 // ==========================================================
141
142 void DLL_CALLCONV
InitJNG(Plugin * plugin,int format_id)143 InitJNG(Plugin *plugin, int format_id) {
144 s_format_id = format_id;
145
146 plugin->format_proc = Format;
147 plugin->description_proc = Description;
148 plugin->extension_proc = Extension;
149 plugin->regexpr_proc = RegExpr;
150 plugin->open_proc = Open;
151 plugin->close_proc = Close;
152 plugin->pagecount_proc = NULL;
153 plugin->pagecapability_proc = NULL;
154 plugin->load_proc = Load;
155 plugin->save_proc = Save;
156 plugin->validate_proc = Validate;
157 plugin->mime_proc = MimeType;
158 plugin->supports_export_bpp_proc = SupportsExportDepth;
159 plugin->supports_export_type_proc = SupportsExportType;
160 plugin->supports_icc_profiles_proc = SupportsICCProfiles;
161 plugin->supports_no_pixels_proc = SupportsNoPixels;
162 }
163