// 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!"); }
// 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; }
// Somebody wants our selection long ShutterBug::onClipboardRequest(FXObject* sender,FXSelector sel,void* ptr){ FXEvent *event=(FXEvent*)ptr; FXuchar *pointer; FXuval length; FXTRACE((1,"%s::onClipboardRequest \n",getClassName())); // Try handling it in base class first if(FXShell::onClipboardRequest(sender,sel,ptr)) return 1; if(clipbuffer){ // One of the supported image types? if(event->target==dndTypes[0] || event->target==dndTypes[1] || event->target==dndTypes[2] || event->target==dndTypes[3] || event->target==dndTypes[4] || event->target==dndTypes[5] || event->target==dndTypes[6]){ FXMemoryStream ms; // Open memory stream ms.open(FXStreamSave,NULL,0); // Render image to memory stream if(event->target==dndTypes[0]){ FXTRACE((1,"Request for bmpType\n")); fxsaveBMP(ms,clipbuffer,clipwidth,clipheight); } else if(event->target==dndTypes[1]){ FXTRACE((1,"Request for gifType\n")); fxsaveGIF(ms,clipbuffer,clipwidth,clipheight); } else if(event->target==dndTypes[2]){ FXTRACE((1,"Request for xpmType\n")); fxsaveXPM(ms,clipbuffer,clipwidth,clipheight); } else if(event->target==dndTypes[3]){ FXTRACE((1,"Request for ppmType\n")); fxsavePPM(ms,clipbuffer,clipwidth,clipheight); } else if(event->target==dndTypes[4]){ FXTRACE((1,"Request for jpgType\n")); fxsaveJPG(ms,clipbuffer,clipwidth,clipheight,75); } else if(event->target==dndTypes[5]){ FXTRACE((1,"Request for pngType\n")); fxsavePNG(ms,clipbuffer,clipwidth,clipheight); } else if(event->target==dndTypes[6]){ FXTRACE((1,"Request for tifType\n")); fxsaveTIF(ms,clipbuffer,clipwidth,clipheight,0); } #ifdef WIN32 // else if(event->target==imageType){ // FXTRACE((1,"Request for imageType\n")); // fxsaveBMP(ms,chart->getData(),chart->getWidth(),chart->getHeight()); // } #endif // Grab buffered image ms.takeBuffer(pointer,length); // Close memory stream ms.close(); // Set DND data setDNDData(FROM_CLIPBOARD,event->target,pointer,length); return 1; } } return 0; }