// smell: yellow (the save functions may have additional options, not regarded) // Save file FXbool MFXImageHelper::saveImage(const std::string& file, int width, int height, FXColor* data) { FXString ext = FXPath::extension(file.c_str()); checkSupported(ext); FXFileStream stream; if (!stream.open(file.c_str(), FXStreamSave)) { throw InvalidArgument("Could not open file for writing!"); } if (comparecase(ext, "gif") == 0) { return fxsaveGIF(stream, data, width, height, false /* !!! "fast" */); } else if (comparecase(ext, "bmp") == 0) { return fxsaveBMP(stream, data, width, height); } else if (comparecase(ext, "xpm") == 0) { return fxsaveXPM(stream, data, width, height); } else if (comparecase(ext, "pcx") == 0) { return fxsavePCX(stream, data, width, height); } else if (comparecase(ext, "ico") == 0 || comparecase(ext, "cur") == 0) { return fxsaveICO(stream, data, width, height); } else if (comparecase(ext, "tga") == 0) { return fxsaveTGA(stream, data, width, height); } else if (comparecase(ext, "rgb") == 0) { return fxsaveRGB(stream, data, width, height); } else if (comparecase(ext, "xbm") == 0) { return fxsaveXBM(stream, data, width, height); } else if (comparecase(ext, "png") == 0) { return fxsavePNG(stream, data, width, height); } else if (comparecase(ext, "jpg") == 0 || comparecase(ext, "jpeg") == 0) { return fxsaveJPG(stream, data, width, height, 75); } else if (comparecase(ext, "tif") == 0 || comparecase(ext, "tiff") == 0) { return fxsaveTIF(stream, data, width, height, 0); } throw InvalidArgument("Unknown file extension for image!"); }
// Load a PNG icon from a file in the icon path FXIcon* loadiconfile(FXApp *app, const FXString iconpath, const FXString iconname) { // New PNG icon FXIcon *icon=NULL; icon=new FXPNGIcon(app); if(icon) { // Find icon in the icon directory FXString iconfile=FXPath::search(iconpath,iconname.text()); if(!iconfile.empty()) { FXFileStream str; // Try open the file if(str.open(iconfile,FXStreamLoad)) { // Load it icon->loadPixels(str); // Done str.close(); return icon; } } // Failed, delete the icon fprintf(stderr,_("Error: Failed to load %s icon. Please check your icon path...\n"),iconname.text()); delete icon; } return NULL; }
// Save an image FXbool ShutterBug::saveImage(const FXString& file,FXColor* pixels,FXint w,FXint h){ FXbool ok=false; FXFileStream outfile; if(outfile.open(file,FXStreamSave)){ switch(fileformat){ case TYPE_GIF: ok=fxsaveGIF(outfile,pixels,w,h,quantize); break; case TYPE_BMP: ok=fxsaveBMP(outfile,pixels,w,h); break; case TYPE_XPM: ok=fxsaveXPM(outfile,pixels,w,h,quantize); break; case TYPE_PCX: ok=fxsavePCX(outfile,pixels,w,h); break; case TYPE_RGB: ok=fxsaveRGB(outfile,pixels,w,h); break; case TYPE_XBM: ok=fxsaveXBM(outfile,pixels,w,h); break; case TYPE_TGA: ok=fxsaveTGA(outfile,pixels,w,h); break; case TYPE_PPM: ok=fxsavePPM(outfile,pixels,w,h); break; #ifdef HAVE_PNG_H case TYPE_PNG: ok=fxsavePNG(outfile,pixels,w,h); break; #endif #ifdef HAVE_JPEG_H case TYPE_JPG: ok=fxsaveJPG(outfile,pixels,w,h,75); break; #endif #ifdef HAVE_TIFF_H case TYPE_TIF: ok=fxsaveTIF(outfile,pixels,w,h,0); break; #endif #ifdef HAVE_WEBP_H case TYPE_WBP: ok=fxsaveWEBP(outfile,pixels,w,h,75.0f); break; #endif case TYPE_RAS: ok=fxsaveRAS(outfile,pixels,w,h); break; case TYPE_PS: ok=fxsavePS(outfile,pixels,w,h); break; } outfile.close(); } return ok; }
/** A TGA image loading generic function * * \param filename The filename of the image to load * * \return A pointer to a FXImage structure containing the tga image datas * */ FX::FXImage* RainbruRPG::Gui::Launcher::loadImage(const char* filename){ FX::FXImage* img=new FX::FXTGAImage(getApp(), NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP); if(img){ FXFileStream stream; if(stream.open(filename,FXStreamLoad)){ img->loadPixels(stream); stream.close(); img->create(); } } return img; }
// Load from file FXImage *FXIconSource::loadImageFile(FXApp* app,const FXString& filename,const FXString& type) const { FXImage *image=NULL; FXTRACE((150,"FXIconSource loadImage(%s)\n",filename.text())); if(!filename.empty()){ FXFileStream store; if(store.open(filename,FXStreamLoad,65536)){ if(type.empty()){ image=loadImageStream(app,store,FXPath::extension(filename)); } else{ image=loadImageStream(app,store,type); } store.close(); } } return image; }
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; }
long Foam::viewer::makeSnapshot(FXObject* obj,FXSelector sel,void* ptr) { // Grab the image window FXDrawable* drawable = (FXDrawable *) glviewer_; // Construct and create an FXImage object FXGIFImage snapshot ( getApp(), NULL, 0, drawable->getWidth(), drawable->getHeight() ); snapshot.create(); // Create a window device context and lock it onto the image FXDCWindow dc(&snapshot); // Draw from the widget to this dc.drawArea ( drawable, 0, 0, drawable->getWidth(), drawable->getHeight(), 0, 0 ); // Release lock dc.end(); // Grab pixels from server side back to client side snapshot.restore(); // Save recovered pixels to a file FXFileStream stream; if (stream.open("snapshot.gif", FXStreamSave)) { snapshot.savePixels(stream); stream.close(); } Info << "\nSnapshot written to snapshot.gif\n"; return 1; }
void GMFilterSource::init(GMTrackDatabase * database,GMSourceList & list){ FXFileStream store; // Load from disk if (store.open(GMApp::getDataDirectory()+PATHSEPSTRING+"filters.db",FXStreamLoad)){ FXuint version; FXint nitems; store >> version; if (version==FILTER_DB_V1) { store >> nitems; for (FXint i=0;i<nitems;i++){ GMFilterSource * src = new GMFilterSource(database); src->match.load(store); sources.append(src); } list.append(sources); return; }