static gboolean gtk_mng_view_init_libmng (GtkMngView * mng_view) { FUNCTION_ENTRY(); GtkWidget * widget; g_return_val_if_fail (IS_GTK_MNG_VIEW (mng_view), FALSE); if (mng_view->MNG_handle) mng_cleanup (&mng_view->MNG_handle); mng_view->MNG_handle = mng_initialize (mng_view, mng_malloc_callback, mng_free_callback, MNG_NULL); if (mng_view->MNG_handle == MNG_NULL) { FUNCTION_EXIT(); return FALSE; } mng_set_storechunks(mng_view->MNG_handle, MNG_TRUE); //mng_set_dfltimggamma(mng_view->MNG_handle, 5); //mng_set_displaygamma(mng_view->MNG_handle, 4); if (mng_setcb_openstream (mng_view->MNG_handle, mng_open_stream_callback) != MNG_NOERROR || mng_setcb_closestream (mng_view->MNG_handle, mng_close_stream_callback) != MNG_NOERROR || mng_setcb_readdata (mng_view->MNG_handle, mng_read_data_callback) != MNG_NOERROR || mng_setcb_processheader (mng_view->MNG_handle, mng_process_header_callback) != MNG_NOERROR || mng_setcb_processmend (mng_view->MNG_handle, mng_process_mend_callback) != MNG_NOERROR || mng_setcb_processterm (mng_view->MNG_handle, mng_process_term_callback) != MNG_NOERROR || mng_setcb_settimer (mng_view->MNG_handle, mng_set_timer_callback) != MNG_NOERROR || mng_setcb_gettickcount (mng_view->MNG_handle, mng_get_tickcount_callback) != MNG_NOERROR || mng_setcb_getcanvasline (mng_view->MNG_handle, mng_get_canvas_line_callback) != MNG_NOERROR || mng_setcb_getalphaline (mng_view->MNG_handle, mng_get_alpha_line_callback) != MNG_NOERROR || mng_setcb_refresh (mng_view->MNG_handle, mng_refresh_callback) != MNG_NOERROR) { mng_cleanup (&mng_view->MNG_handle); FUNCTION_EXIT(); return FALSE; } //mng_set_suspensionmode(mng_view->MNG_handle, MNG_TRUE); mng_set_canvasstyle (mng_view->MNG_handle, MNG_CANVAS_RGB8_A8); widget = GTK_WIDGET (mng_view); if (!GTK_WIDGET_REALIZED (widget)) gtk_widget_realize (widget); mng_set_bgcolor (mng_view->MNG_handle, widget->style->bg[GTK_STATE_NORMAL].red, widget->style->bg[GTK_STATE_NORMAL].green, widget->style->bg[GTK_STATE_NORMAL].blue); FUNCTION_EXIT(); return TRUE; }
static FIBITMAP * DLL_CALLCONV Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { mng_handle hmng = NULL; if (handle != NULL) { try { // allocate our stream data structure mngstuff *mymng = (mngstuff *)data; // set up the mng decoder for our stream hmng = mng_initialize(mymng, mymngalloc, mymngfree, MNG_NULL); if (hmng == MNG_NULL) { throw "could not initialize libmng"; } // set the colorprofile, lcms uses this mng_set_srgb(hmng, MNG_TRUE ); // set white as background color WORD wRed, wGreen, wBlue; wRed = wGreen = wBlue = (255 << 8) + 255; mng_set_bgcolor(hmng, wRed, wGreen, wBlue); // if PNG Background is available, use it mng_set_usebkgd(hmng, MNG_TRUE ); // no need to store chunks mng_set_storechunks(hmng, MNG_FALSE); // no need to wait: straight reading mng_set_suspensionmode(hmng, MNG_FALSE); // set the callbacks mng_setcb_errorproc(hmng, mymngerror); mng_setcb_openstream(hmng, mymngopenstream); mng_setcb_closestream(hmng, mymngclosestream); mng_setcb_readdata(hmng, mymngreadstream); mng_setcb_processheader(hmng, mymngprocessheader); mng_setcb_getcanvasline(hmng, mymnggetcanvasline); mng_setcb_refresh(hmng, mymngrefresh); mng_setcb_gettickcount(hmng, mymnggetticks); mng_setcb_settimer(hmng, mymngsettimer); // read in the bitmap mng_readdisplay(hmng); // read all bitmaps int retval = MNG_NOERROR; mng_datap pData = (mng_datap)hmng; while(pData->bReading) { retval = mng_display_resume(hmng); if((retval == MNG_NEEDTIMERWAIT) || (retval == MNG_FUNCTIONINVALID)) break; } // temp store the newly created bitmap FIBITMAP *bitmap = mymng->bitmap; // cleanup and return the temp stored bitmap mng_cleanup(&hmng); return bitmap; } catch (const char *message) { FIBITMAP *bitmap = ((mngstuff *)mng_get_userdata(hmng))->bitmap; if(bitmap) { FreeImage_Unload(bitmap); } mng_cleanup(&hmng); FreeImage_OutputMessageProc(s_format_id, message); } } return NULL; }