Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

ReadImage.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Array_ReadImage_h
00002 #define Impala_Core_Array_ReadImage_h
00003 
00004 #include "Core/Array/Arrays.h"
00005 #include "Core/Array/ReadPng.h"
00006 #include "Core/Array/ReadJpg.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Array
00013 {
00014 
00015 
00019 template <class ArrayT>
00020 inline void
00021 ReadImageFromMemory(ArrayT*& dst, char *buf, int bufsize)
00022 {
00023     ILOG_VAR(Impala.Core.Array.ReadImageFromMemory);
00024     if (bufsize < 14)
00025     {
00026         ILOG_ERROR("Buffer size too small to identify file: " << bufsize
00027                    << " bytes");
00028         return;
00029     }
00030 
00031     // PNG image (first 8 bytes are always the same)
00032     if (((buf[0] == -119) || (buf[0] == 137)) &&        // 0x89 (signed stuff is... annoying)
00033         (buf[1] == 0x50) &&
00034         (buf[2] == 0x4e) &&
00035         (buf[3] == 0x47) &&
00036         (buf[4] == 0x0d) &&
00037         (buf[5] == 0x0a) &&
00038         (buf[6] == 0x1a) &&
00039         (buf[7] == 0x0a))
00040     {
00041         ReadPngFromMemory(dst, buf, bufsize);
00042         return;
00043     }
00044 
00045     // ordinary JFIF JPEG
00046     if ((buf[0] == -1) &&      // 0xff
00047         (buf[1] == -40) &&     // 0xd8
00048         (buf[2] == -1) &&      // 0xff application marker
00049         //(buf[3] == 0xe0) &&  // application marker
00050         //                     // (this part can be e0..ef or anything?)
00051         (buf[6] == 0x4a) &&    // J
00052         (buf[7] == 0x46) &&    // F
00053         (buf[8] == 0x49) &&    // I
00054         (buf[9] == 0x46) &&    // F
00055         (buf[10] == 0x00))
00056     {
00057         ReadJpgFromMemory(dst, buf, bufsize);
00058         return;
00059     }
00060 
00061     // Exif JPEG ...not tested...
00062     //is the "Exif" part required to be in this exact location?
00063     if ((buf[0] == -1) &&       // 0xff
00064         (buf[1] == -40) &&      // 0xd8
00065         (buf[2] == -1) &&       // 0xff application marker
00066         (buf[3] == -31) &&      // 0xe1 application marker
00067                                 // (this part has to be e1 for exif)
00068         (buf[8] == 0x45) &&     // E
00069         (buf[9] == 0x78) &&     // x
00070         (buf[10] == 0x69) &&    // i
00071         (buf[11] == 0x66) &&    // f
00072         (buf[12] == 0x00) &&    // \0
00073         (buf[13] == 0x00))      // \0
00074     {
00075         ReadJpgFromMemory(dst, buf, bufsize);
00076         return;
00077     }
00078     // Exif JPEG 2nd form: Exif 2 bytes back
00079     //is the "Exif" part required to be in this exact location?
00080     if ((buf[0] == -1) &&       // 0xff
00081         (buf[1] == -40) &&      // 0xd8
00082         (buf[2] == -1) &&       // 0xff application marker
00083         (buf[3] == -31) &&      // 0xe1 application marker
00084                                 // (this part has to be e1 for exif)
00085         (buf[6] == 0x45) &&     // E
00086         (buf[7] == 0x78) &&     // x
00087         (buf[8] == 0x69) &&     // i
00088         (buf[9] == 0x66) &&     // f
00089         (buf[10] == 0x00) &&    // \0
00090         (buf[11] == 0x00))      // \0
00091     {
00092         ReadJpgFromMemory(dst, buf, bufsize);
00093         return;
00094     }
00095 
00096 
00097     ILOG_ERROR("Unknown image file format! " << int(buf[0]) << " " <<
00098                int(buf[1]) << " " << int(buf[2]) << " " << int(buf[3]) << " "
00099                << int(buf[4]) << " " << int(buf[5]) << " " << int(buf[6]) <<
00100                " " << int(buf[7]) << " " << int(buf[8]) << " " << int(buf[9])
00101                << " " << int(buf[10]) << " " << int(buf[11]));
00102 }
00103 
00104 } // namespace Array
00105 } // namespace Core
00106 } // namespace Impala
00107 
00108 #endif

Generated on Fri Mar 19 09:30:53 2010 for ImpalaSrc by  doxygen 1.5.1