MFXImageHelper Class Reference

#include <MFXImageHelper.h>


Detailed Description

Definition at line 37 of file MFXImageHelper.h.


Static Public Member Functions

static void checkSupported (FXString ext) throw (InvalidArgument)
static FXImage * loadImage (FXApp *a, const std::string &file)
static FXbool saveImage (const std::string &file, int width, int height, FXColor *data)
static FXbool scalePower2 (FXImage *image)

Member Function Documentation

void MFXImageHelper::checkSupported ( FXString  ext  )  throw (InvalidArgument) [static]

Definition at line 44 of file MFXImageHelper.cpp.

Referenced by loadImage(), and saveImage().

00044                                                                   {
00045     if (comparecase(ext,"png")==0) {
00046         if (!FXPNGImage::supported) {
00047             throw InvalidArgument("Fox was compiled without png support!");
00048         }
00049     } else if (comparecase(ext,"jpg")==0 || comparecase(ext,"jpeg")==0) {
00050         if (!FXJPGImage::supported) {
00051             throw InvalidArgument("Fox was compiled without jpg support!");
00052         }
00053     } else if (comparecase(ext,"tif")==0 || comparecase(ext,"tiff")==0) {
00054         if (!FXTIFImage::supported) {
00055             throw InvalidArgument("Fox was compiled without tif support!");
00056         }
00057     }
00058 }

FXImage * MFXImageHelper::loadImage ( FXApp *  a,
const std::string &  file 
) [static]

Definition at line 62 of file MFXImageHelper.cpp.

References checkSupported().

Referenced by GUISUMOAbstractView::drawDecals().

00062                                                          {
00063     FXString ext=FXPath::extension(file.c_str());
00064     checkSupported(ext);
00065     FXImage *img=NULL;
00066     if (comparecase(ext,"gif")==0) {
00067         img=new FXGIFImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00068     } else if (comparecase(ext,"bmp")==0) {
00069         img=new FXBMPImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00070     } else if (comparecase(ext,"xpm")==0) {
00071         img=new FXXPMImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00072     } else if (comparecase(ext,"pcx")==0) {
00073         img=new FXPCXImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00074     } else if (comparecase(ext,"ico")==0 || comparecase(ext,"cur")==0) {
00075         img=new FXICOImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00076     } else if (comparecase(ext,"tga")==0) {
00077         img=new FXTGAImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00078     } else if (comparecase(ext,"rgb")==0) {
00079         img=new FXRGBImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00080     } else if (comparecase(ext,"xbm")==0) {
00081         img=new FXXBMImage(a,NULL,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00082     } else if (comparecase(ext,"png")==0) {
00083         img=new FXPNGImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00084     } else if (comparecase(ext,"jpg")==0 || comparecase(ext,"jpeg")==0) {
00085         img=new FXJPGImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00086     } else if (comparecase(ext,"tif")==0 || comparecase(ext,"tiff")==0) {
00087         img=new FXTIFImage(a,NULL,IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP);
00088     } else {
00089         throw InvalidArgument("Unknown file extension for image '" + file + "'!");
00090     }
00091 
00092     FXFileStream stream;
00093     if (img != NULL && stream.open(file.c_str(), FXStreamLoad)) {
00094         a->beginWaitCursor();
00095         img->loadPixels(stream);
00096         stream.close();
00097 
00098         img->create();
00099         a->endWaitCursor();
00100     } else {
00101         throw InvalidArgument("Loading failed!");
00102     }
00103     return img;
00104 }

FXbool MFXImageHelper::saveImage ( const std::string &  file,
int  width,
int  height,
FXColor *  data 
) [static]

Definition at line 136 of file MFXImageHelper.cpp.

References checkSupported().

Referenced by GUISUMOAbstractView::checkSnapshots(), and GUISUMOViewParent::onCmdMakeSnapshot().

00137                                                                 {
00138     FXString ext=FXPath::extension(file.c_str());
00139     checkSupported(ext);
00140     FXFileStream stream;
00141     if (!stream.open(file.c_str(), FXStreamSave)) {
00142         throw InvalidArgument("Could not open file for writing!");
00143     }
00144     if (comparecase(ext,"gif")==0) {
00145         return fxsaveGIF(stream, data, width, height, false /* !!! "fast" */);
00146     } else if (comparecase(ext,"bmp")==0) {
00147         return fxsaveBMP(stream, data, width, height);
00148     } else if (comparecase(ext,"xpm")==0) {
00149         return fxsaveXPM(stream, data, width, height);
00150     } else if (comparecase(ext,"pcx")==0) {
00151         return fxsavePCX(stream, data, width, height);
00152     } else if (comparecase(ext,"ico")==0 || comparecase(ext,"cur")==0) {
00153         return fxsaveICO(stream, data, width, height);
00154     } else if (comparecase(ext,"tga")==0) {
00155         return fxsaveTGA(stream, data, width, height);
00156     } else if (comparecase(ext,"rgb")==0) {
00157         return fxsaveRGB(stream, data, width, height);
00158     } else if (comparecase(ext,"xbm")==0) {
00159         return fxsaveXBM(stream, data, width, height);
00160     } else if (comparecase(ext,"png")==0) {
00161         return fxsavePNG(stream, data, width, height);
00162     } else if (comparecase(ext,"jpg")==0 || comparecase(ext,"jpeg")==0) {
00163         return fxsaveJPG(stream, data, width, height, 75);
00164     } else if (comparecase(ext,"tif")==0 || comparecase(ext,"tiff")==0) {
00165         return fxsaveTIF(stream, data, width, height, 0);
00166     }
00167     throw InvalidArgument("Unknown file extension for image!");
00168 }

FXbool MFXImageHelper::scalePower2 ( FXImage *  image  )  [static]

Definition at line 108 of file MFXImageHelper.cpp.

Referenced by GUISUMOAbstractView::drawDecals().

00108                                           {
00109     FXint newHeight;
00110     for (FXint exp = 30; exp >= 0; exp--) {
00111         newHeight = 2 << exp;
00112         if (image->getHeight() & newHeight) break;
00113     }
00114     if (2 * newHeight - image->getHeight() < image->getHeight() - newHeight) {
00115         newHeight *= 2;
00116     }
00117     FXint newWidth;
00118     for (FXint exp = 30; exp >= 0; exp--) {
00119         newWidth = 2 << exp;
00120         if (image->getWidth() & newWidth) break;
00121     }
00122     if (2 * newWidth - image->getWidth() < image->getWidth() - newWidth) {
00123         newWidth *= 2;
00124     }
00125     if (newHeight == image->getHeight() && newWidth == image->getWidth()) {
00126         return false;
00127     }
00128     image->scale(newWidth, newHeight);
00129     return true;
00130 }


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:46 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6