FXImage* MFXImageHelper::loadImage(FXApp* a, const std::string& file) { FXString ext = FXPath::extension(file.c_str()); checkSupported(ext); FXImage* img = NULL; if (comparecase(ext, "gif") == 0) { img = new FXGIFImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "bmp") == 0) { img = new FXBMPImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "xpm") == 0) { img = new FXXPMImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "pcx") == 0) { img = new FXPCXImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "ico") == 0 || comparecase(ext, "cur") == 0) { img = new FXICOImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "tga") == 0) { img = new FXTGAImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "rgb") == 0) { img = new FXRGBImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "xbm") == 0) { img = new FXXBMImage(a, NULL, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "png") == 0) { img = new FXPNGImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "jpg") == 0 || comparecase(ext, "jpeg") == 0) { img = new FXJPGImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else if (comparecase(ext, "tif") == 0 || comparecase(ext, "tiff") == 0) { img = new FXTIFImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP); } else { throw InvalidArgument("Unknown file extension '" + toString(ext.text()) + "' for image '" + file + "'!"); } FXFileStream stream; if (img != NULL && stream.open(file.c_str(), FXStreamLoad)) { a->beginWaitCursor(); img->loadPixels(stream); stream.close(); img->create(); a->endWaitCursor(); } else { delete img; throw InvalidArgument("Loading failed!"); } return img; }
HTML_IMAGE *FOX16_HtmlCtx::getImage(const char *fileName) { GWEN_STRINGLIST *sl; sl=HtmlCtx_GetMediaPaths(_context); if (sl) { GWEN_BUFFER *tbuf; int rv; FXImage *ximg; HTML_IMAGE *img; tbuf=GWEN_Buffer_new(0, 256, 0, 1); rv=GWEN_Directory_FindFileInPaths(sl, fileName, tbuf); if (rv<0) { DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); return NULL; } if (m_iconSource==NULL) m_iconSource=new FXIconSource(FXApp::instance()); ximg=m_iconSource->loadIconFile(GWEN_Buffer_GetStart(tbuf)); if (ximg==NULL) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not load icon [%s]", GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_free(tbuf); return NULL; } ximg->create(); img=HtmlImage_new(); HtmlImage_SetImageName(img, GWEN_Buffer_GetStart(tbuf)); HtmlImage_SetWidth(img, ximg->getWidth()); HtmlImage_SetHeight(img, ximg->getHeight()); GWEN_INHERIT_SETDATA(HTML_IMAGE, FXImage, img, ximg, FOX16_HtmlCtxLinker::freeImageData); GWEN_Buffer_free(tbuf); return img; } else { DBG_ERROR(GWEN_LOGDOMAIN, "No media paths in dialog"); return NULL; } }