77
84
mymngprocessheader(mng_handle mng, mng_uint32 width, mng_uint32 height) {
78
// allocate a bitmap with the given dimensions
80
((mngstuff *)mng_get_userdata(mng))->bitmap = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
82
// tell the mng decoder about our bit-depth choice
85
mngstuff *client_data = (mngstuff *)mng_get_userdata(mng);
86
BYTE bHasAlpha = mng_get_alphadepth(mng);
84
88
#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB
85
mng_set_canvasstyle(mng, MNG_CANVAS_RGB8);
90
// allocate a bitmap with the given dimensions
91
FIBITMAP *bitmap = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
92
client_data->bitmap = bitmap;
93
// tell the mng decoder about our bit-depth choice
94
mng_set_canvasstyle(mng, MNG_CANVAS_RGBA8);
96
// allocate a bitmap with the given dimensions
97
FIBITMAP *bitmap = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
98
client_data->bitmap = bitmap;
99
// tell the mng decoder about our bit-depth choice
100
mng_set_canvasstyle(mng, MNG_CANVAS_RGB8);
87
mng_set_canvasstyle(mng, MNG_CANVAS_BGR8);
104
// allocate a bitmap with the given dimensions
105
FIBITMAP *bitmap = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
106
client_data->bitmap = bitmap;
107
// tell the mng decoder about our bit-depth choice
108
mng_set_canvasstyle(mng, MNG_CANVAS_BGRA8);
110
// allocate a bitmap with the given dimensions
111
FIBITMAP *bitmap = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
112
client_data->bitmap = bitmap;
113
// tell the mng decoder about our bit-depth choice
114
mng_set_canvasstyle(mng, MNG_CANVAS_BGR8);
116
#endif // FREEIMAGE_COLORORDER_RGB
118
return client_data->bitmap ? MNG_TRUE : MNG_FALSE;
116
144
mymngerror(mng_handle mng, mng_int32 code, mng_int8 severity, mng_chunkid chunktype, mng_uint32 chunkseq, mng_int32 extra1, mng_int32 extra2, mng_pchar text) {
118
if((code == MNG_SEQUENCEERROR) && (chunktype == MNG_UINT_TERM))
146
if((code == MNG_SEQUENCEERROR) && (chunktype == MNG_UINT_TERM)) {
119
147
// ignore sequence error for TERM
122
151
// text can be null depending on compiler options
123
152
sprintf(msg, "Error reported by libmng (%d)\r\n\r\n%s", code, text);
125
154
sprintf(msg, "Error %d reported by libmng", code);
127
throw (const char *)msg;
128
//return MNG_TRUE; // not really neccessary but keeps VC5 happy
156
FreeImage_OutputMessageProc(s_format_id, msg);
131
160
// ==========================================================
133
// ==========================================================
135
static int s_format_id;
137
// ==========================================================
138
161
// Plugin Implementation
139
162
// ==========================================================
194
217
static FIBITMAP * DLL_CALLCONV
195
218
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
219
mng_handle hmng = NULL;
196
221
if (handle != NULL) {
198
223
// allocate our stream data structure
200
224
mngstuff *mymng = (mngstuff *)data;
202
226
// set up the mng decoder for our stream
204
mng_handle mng = mng_initialize(mymng, mymngalloc, mymngfree, MNG_NULL);
227
hmng = mng_initialize(mymng, mymngalloc, mymngfree, MNG_NULL);
229
if (hmng == MNG_NULL) {
207
230
throw "could not initialize libmng";
233
// set the colorprofile, lcms uses this
234
mng_set_srgb(hmng, MNG_TRUE );
235
// set white as background color
236
WORD wRed, wGreen, wBlue;
237
wRed = wGreen = wBlue = (255 << 8) + 255;
238
mng_set_bgcolor(hmng, wRed, wGreen, wBlue);
239
// if PNG Background is available, use it
240
mng_set_usebkgd(hmng, MNG_TRUE );
241
// no need to store chunks
242
mng_set_storechunks(hmng, MNG_FALSE);
243
// no need to wait: straight reading
244
mng_set_suspensionmode(hmng, MNG_FALSE);
209
246
// set the callbacks
211
mng_setcb_errorproc(mng, mymngerror);
212
mng_setcb_openstream(mng, mymngopenstream);
213
mng_setcb_closestream(mng, mymngclosestream);
214
mng_setcb_readdata(mng, mymngreadstream);
215
mng_setcb_processheader(mng, mymngprocessheader);
216
mng_setcb_getcanvasline(mng, mymnggetcanvasline);
217
mng_setcb_refresh(mng, mymngrefresh);
218
mng_setcb_gettickcount(mng, mymnggetticks);
219
mng_setcb_settimer(mng, mymngsettimer);
247
mng_setcb_errorproc(hmng, mymngerror);
248
mng_setcb_openstream(hmng, mymngopenstream);
249
mng_setcb_closestream(hmng, mymngclosestream);
250
mng_setcb_readdata(hmng, mymngreadstream);
251
mng_setcb_processheader(hmng, mymngprocessheader);
252
mng_setcb_getcanvasline(hmng, mymnggetcanvasline);
253
mng_setcb_refresh(hmng, mymngrefresh);
254
mng_setcb_gettickcount(hmng, mymnggetticks);
255
mng_setcb_settimer(hmng, mymngsettimer);
221
257
// read in the bitmap
258
mng_readdisplay(hmng);
223
mng_readdisplay(mng);
261
int retval = MNG_NOERROR;
262
mng_datap pData = (mng_datap)hmng;
263
while(pData->bReading) {
264
retval = mng_display_resume(hmng);
265
if((retval == MNG_NEEDTIMERWAIT) || (retval == MNG_FUNCTIONINVALID))
225
269
// temp store the newly created bitmap
227
270
FIBITMAP *bitmap = mymng->bitmap;
229
272
// cleanup and return the temp stored bitmap
234
277
} catch (const char *message) {
278
FIBITMAP *bitmap = ((mngstuff *)mng_get_userdata(hmng))->bitmap;
280
FreeImage_Unload(bitmap);
235
283
FreeImage_OutputMessageProc(s_format_id, message);