Support turbo2.
[vuplus_dvbapp] / lib / gdi / picexif.cpp
index 844673c..1eacc29 100644 (file)
@@ -75,7 +75,6 @@ Cexif::Cexif()
 
 Cexif::~Cexif()
 {
-       //ClearExif();
 }
 
 void Cexif::ClearExif()
@@ -89,15 +88,16 @@ void Cexif::ClearExif()
        }
 }
 
-bool Cexif::DecodeExif(const char *filename)
+bool Cexif::DecodeExif(const char *filename, int Thumb)
 {
+       bool ret = false;
        FILE * hFile = fopen(filename, "r");
-       if(!hFile) return false;
-
+       if(!hFile) return ret;
 
        m_exifinfo = new EXIFINFO;
        memset(m_exifinfo,0,sizeof(EXIFINFO));
        freeinfo = true;
+       m_exifinfo->Thumnailstate = Thumb;
 
        m_szLastError[0]='\0';
        ExifImageWidth = MotorolaOrder = SectionsRead=0;
@@ -107,7 +107,8 @@ bool Cexif::DecodeExif(const char *filename)
        int a = fgetc(hFile);
        strcpy(m_szLastError,"EXIF-Data not found");
 
-       if (a != 0xff || fgetc(hFile) != M_SOI) return false;
+       if (a != 0xff || fgetc(hFile) != M_SOI)
+               goto decode_exif_out_false;
 
        for(;;)
        {
@@ -117,7 +118,8 @@ bool Cexif::DecodeExif(const char *filename)
 
                if (SectionsRead >= MAX_SECTIONS)
                {
-                       strcpy(m_szLastError,"Too many sections in jpg file"); return false;
+                       strcpy(m_szLastError,"Too many sections in jpg file");
+                       goto decode_exif_out_false;
                }
 
                for (a=0;a<7;a++)
@@ -127,13 +129,15 @@ bool Cexif::DecodeExif(const char *filename)
 
                        if (a >= 6)
                        {
-                               strcpy(m_szLastError,"too many padding unsigned chars\n"); return false;
+                               strcpy(m_szLastError,"too many padding unsigned chars\n");
+                               goto decode_exif_out_false;
                        }
                }
 
                if (marker == 0xff)
                {
-                       strcpy(m_szLastError,"too many padding unsigned chars!"); return false;
+                       strcpy(m_szLastError,"too many padding unsigned chars!");
+                       goto decode_exif_out_false;
                }
 
                Sections[SectionsRead].Type = marker;
@@ -145,14 +149,16 @@ bool Cexif::DecodeExif(const char *filename)
 
                if (itemlen < 2)
                {
-                       strcpy(m_szLastError,"invalid marker"); return false;
+                       strcpy(m_szLastError,"invalid marker");
+                       goto decode_exif_out_false;
                }
                Sections[SectionsRead].Size = itemlen;
 
                Data = (unsigned char *)malloc(itemlen);
                if (Data == NULL)
                {
-                       strcpy(m_szLastError,"Could not allocate memory"); return false;
+                       strcpy(m_szLastError,"Could not allocate memory");
+                       goto decode_exif_out_false;
                }
                Sections[SectionsRead].Data = Data;
 
@@ -163,17 +169,18 @@ bool Cexif::DecodeExif(const char *filename)
                got = fread(Data+2, 1, itemlen-2,hFile);
                if (got != itemlen-2)
                {
-                       strcpy(m_szLastError,"Premature end of file?"); return false;
+                       strcpy(m_szLastError,"Premature end of file?");
+                       goto decode_exif_out_false;
                }
                SectionsRead += 1;
 
                switch(marker)
                {
                case M_SOS:
-                       return true;
+                       goto decode_exif_out_true;
                case M_EOI:
                        printf("No image in jpeg!\n");
-                       return false;
+                       goto decode_exif_out_false;
                case M_COM:
                        if (HaveCom)
                        {
@@ -221,8 +228,12 @@ bool Cexif::DecodeExif(const char *filename)
                }
        }
 
+decode_exif_out_true:
+       ret = true;
+
+decode_exif_out_false:
        fclose(hFile);
-       return true;
+       return ret;
 }
 
 bool Cexif::process_EXIF(unsigned char * CharBuf, unsigned int length)
@@ -428,7 +439,7 @@ bool Cexif::ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase,
                        case 6:         strcpy(m_exifinfo->Orientation,"Right-Top"); break;
                        case 7:         strcpy(m_exifinfo->Orientation,"Right-Bottom"); break;
                        case 8:         strcpy(m_exifinfo->Orientation,"Left-Bottom"); break;
-                       default:        strcpy(m_exifinfo->Orientation,"Undefined rotation value");
+                       default:        strcpy(m_exifinfo->Orientation,"Undefined"); break;
                        }
                        break;
                case TAG_EXIF_IMAGELENGTH:
@@ -555,12 +566,16 @@ bool Cexif::ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase,
                ProcessExifDir(SubdirStart, OffsetBase, ExifLength, m_exifinfo, LastExifRefdP);
         }
 
-       if (ThumbnailSize && ThumbnailOffset)
+       if (ThumbnailSize && ThumbnailOffset && m_exifinfo->Thumnailstate)
        {
                if (ThumbnailSize + ThumbnailOffset <= ExifLength)
                {
-                       m_exifinfo->ThumbnailPointer = OffsetBase + ThumbnailOffset;
-                       m_exifinfo->ThumbnailSize = ThumbnailSize;
+                       if(FILE *tf = fopen(THUMBNAILTMPFILE, "w"))
+                       {
+                               fwrite( OffsetBase + ThumbnailOffset, ThumbnailSize, 1, tf);
+                               fclose(tf);
+                               m_exifinfo->Thumnailstate = 2;
+                       }
                }
        }