示例#1
0
// 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!");
}
示例#2
0
// 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;
  }