You can check if a file is has a certain format by reading the first few bytes. 
FLTK does that for jpeg and all other image files. Take a look at the source of 
Fl.jpeg.Image.

If you want to know if a jpeg image is in RGB, you need to read tje entire jpeg 
header. Again, FLTK does that using libjpeg. You can see how it's done in the 
same source code.

 -Matthias

Sent from my relatively smart phone.



jseb <gmane2...@finiderire.com> schrieb:

>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
>fltk@easysw.com
>http://lists.easysw.com/mailman/listinfo/fltk
_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to