~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Source/FreeImage/PluginMNG.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "Utilities.h"
24
24
 
25
25
#include "../LibMNG/libmng.h"
 
26
#include "../LibMNG/libmng_data.h"
 
27
 
 
28
// ==========================================================
 
29
// Plugin Interface
 
30
// ==========================================================
 
31
 
 
32
static int s_format_id;
26
33
 
27
34
// ----------------------------------------------------------
28
35
//   Constants + headers
75
82
 
76
83
mng_bool
77
84
mymngprocessheader(mng_handle mng, mng_uint32 width, mng_uint32 height) {
78
 
        // allocate a bitmap with the given dimensions
79
 
 
80
 
        ((mngstuff *)mng_get_userdata(mng))->bitmap = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
81
 
 
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);
83
87
 
84
88
#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB
85
 
        mng_set_canvasstyle(mng, MNG_CANVAS_RGB8);
 
89
        if(bHasAlpha) {
 
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);
 
95
        } else {
 
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);
 
101
        }
86
102
#else
87
 
        mng_set_canvasstyle(mng, MNG_CANVAS_BGR8);
88
 
#endif
 
103
        if(bHasAlpha) {
 
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);
 
109
        } else {
 
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);
 
115
        }
 
116
#endif // FREEIMAGE_COLORORDER_RGB
89
117
 
90
 
        return MNG_TRUE;
 
118
        return client_data->bitmap ? MNG_TRUE : MNG_FALSE;
91
119
}
92
120
 
93
121
mng_ptr
115
143
mng_bool
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) {
117
145
        char msg[256];
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
120
148
                return MNG_TRUE;
 
149
        }
121
150
        if(text) {
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);
124
153
        } else {
125
154
                sprintf(msg, "Error %d reported by libmng", code);
126
155
        }
127
 
        throw (const char *)msg;
128
 
        //return MNG_TRUE; // not really neccessary but keeps VC5 happy
 
156
        FreeImage_OutputMessageProc(s_format_id, msg);
 
157
        return MNG_FALSE;
129
158
}
130
159
 
131
160
// ==========================================================
132
 
// Plugin Interface
133
 
// ==========================================================
134
 
 
135
 
static int s_format_id;
136
 
 
137
 
// ==========================================================
138
161
// Plugin Implementation
139
162
// ==========================================================
140
163
 
193
216
 
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;
 
220
 
196
221
        if (handle != NULL) {
197
222
                try {
198
223
                        // allocate our stream data structure
199
 
 
200
224
                        mngstuff *mymng = (mngstuff *)data;
201
225
 
202
226
                        // set up the mng decoder for our stream
203
 
 
204
 
                        mng_handle mng = mng_initialize(mymng, mymngalloc, mymngfree, MNG_NULL);
205
 
 
206
 
                        if (mng == MNG_NULL)
 
227
                        hmng = mng_initialize(mymng, mymngalloc, mymngfree, MNG_NULL);
 
228
 
 
229
                        if (hmng == MNG_NULL) {
207
230
                                throw "could not initialize libmng";                    
 
231
                        }
 
232
                        
 
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);
208
245
 
209
246
                        // set the callbacks
210
 
 
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);
220
 
 
 
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);
 
256
        
221
257
                        // read in the bitmap
 
258
                        mng_readdisplay(hmng);
222
259
 
223
 
                        mng_readdisplay(mng);
 
260
                        // read all bitmaps
 
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))
 
266
                                        break;
 
267
                        }
224
268
 
225
269
                        // temp store the newly created bitmap
226
 
 
227
270
                        FIBITMAP *bitmap = mymng->bitmap;
228
271
 
229
272
                        // cleanup and return the temp stored bitmap
230
 
 
231
 
                        mng_cleanup(&mng);
 
273
                        mng_cleanup(&hmng);
232
274
 
233
275
                        return bitmap;
 
276
 
234
277
                } catch (const char *message) {
 
278
                        FIBITMAP *bitmap = ((mngstuff *)mng_get_userdata(hmng))->bitmap;
 
279
                        if(bitmap) {
 
280
                                FreeImage_Unload(bitmap);
 
281
                        }
 
282
                        mng_cleanup(&hmng);
235
283
                        FreeImage_OutputMessageProc(s_format_id, message);
236
284
                }
237
285
        }