Hello,

I wonder how i could detect RGB image format, without loading image in a 
buffer, and then parsing its header.

For the moment, i'm doing this in my classe, which is far from being 
efficient:


Fl_Image * Images::load (std::string filename)
{
   Fl_Image *image = is_image_already_loaded(filename);

   if (!image) {
     image = new Fl_JPEG_Image (filename.c_str());
     if (image->w()) {
       //the image is cached when loading once.
       liste.insert(std::pair<std::string, Fl_Image *>(filename,image) );
     } else {
       delete image;
       image = 0;
     }
   }

   if (!image) {
     image = new Fl_PNG_Image (filename.c_str());
     if (image->w()) {
       liste.insert(std::pair<std::string, Fl_Image *>(filename,image) );
     } else {
       delete image;
       image = 0;
     }
   }

   if (!image) {
     image = new Fl_BMP_Image (filename.c_str());
     if (image->w()) {
       liste.insert(std::pair<std::string, Fl_Image *>(filename,image) );
     } else {
       CRITICAL ("unknwown format for : %s\n",filename.c_str());
       delete image;
       image = 0;
     }
   }

   return image;
}

Of course, i could preload the image in a buffer, and then trying 
Fl_JPEG/PNG/BMP_Image from this buffer.
I could also use a template for the three almost identical load.
As i cache the picture once loaded, i think i don't get a big speed 
penalty, even if i load BMP pictures.

Thank you.
(«premature optimizing is the root of all evil», i know too :) )

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to