Coverage Report

Created: 2025-06-22 06:41

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