Commits

shuerhaaken committed d82e888

more image tests and resulting fixes

Comments (0)

Files changed (13)

libtaginfo/apetaginfo.cc

 #define ARTIST_LABELS               "ARTIST_LABELS"
 
 #define APE_TAG_COVER_ART_OTHER             "COVER ART (OTHER)"
-#define APE_TAG_COVER_ART_ICON	            "COVER ART (ICON)"
+#define APE_TAG_COVER_ART_ICON              "COVER ART (ICON)"
 #define APE_TAG_COVER_ART_OTHER_ICON        "COVER ART (OTHER ICON)"
 #define APE_TAG_COVER_ART_FRONT             "COVER ART (FRONT)"
 #define APE_TAG_COVER_ART_BACK              "COVER ART (BACK)"
 
 
 
-void check_ape_label_frame(TagLib::APE::Tag * apetag, const char * description, const String &value) {
-    if(apetag->itemListMap().contains(description))
-        apetag->removeItem(description);
-    if(!value.isEmpty()) {
-            apetag->addValue(description, value);
-    }
+void set_item(TagLib::APE::Tag * apetag, const char * key, const String &value, bool replace = true) {
+    apetag->removeItem(key);
+    if(!value.isEmpty())
+        apetag->addValue(key, value, replace);
 }
 
-
-void get_ape_item_image(const TagLib::APE::Item &item, Image *& image) {
+void extract_image(const TagLib::APE::Item &image_item, Image *& image) {
     image->image_file_type = IMAGE_FILE_TYPE_UNKNOWN;
-    if(item.type() == TagLib::APE::Item::Binary) {
-        TagLib::ByteVector CoverData = item.binaryData();
+    image->description = NULL; // description not supported in APE tags!
+    if(image_item.type() == TagLib::APE::Item::Binary) {
+        TagLib::ByteVector CoverData = image_item.binaryData();
         if(CoverData.size() > 0) {
             image->data_length = CoverData.size();
             image->data = new char[image->data_length];
 }
 
 String image_type_to_ape_image_name(const ImageType& image_type) {
-    String itp;
     switch(image_type) {
         case IMAGE_TYPE_COVER_FRONT :
-            itp = APE_TAG_COVER_ART_FRONT;
-            break;
+            return APE_TAG_COVER_ART_FRONT;
         case IMAGE_TYPE_COVER_BACK :
-            itp = APE_TAG_COVER_ART_BACK;
-            break;
+            return APE_TAG_COVER_ART_BACK;
         case IMAGE_TYPE_OTHER :
-            itp = APE_TAG_COVER_ART_OTHER;
-            break;
+            return APE_TAG_COVER_ART_OTHER;
         case IMAGE_TYPE_FILE_ICON :
-            itp = APE_TAG_COVER_ART_ICON;
-            break;
+            return APE_TAG_COVER_ART_ICON;
         case IMAGE_TYPE_OTHER_FILE_ICON :
-            itp = APE_TAG_COVER_ART_OTHER_ICON;
-            break;
+            return APE_TAG_COVER_ART_OTHER_ICON;
         case IMAGE_TYPE_LEAFLET_PAGE :
-            itp = APE_TAG_COVER_ART_LEAFLET;
-            break;
+            return APE_TAG_COVER_ART_LEAFLET;
         case IMAGE_TYPE_MEDIA  :
-            itp = APE_TAG_COVER_ART_MEDIA;
-            break;
+            return APE_TAG_COVER_ART_MEDIA;
         case IMAGE_TYPE_LEAD_ARTIST :
-            itp = APE_TAG_COVER_ART_LEAD;
-            break;
+            return APE_TAG_COVER_ART_LEAD;
         case IMAGE_TYPE_ARTIST :
-            itp = APE_TAG_COVER_ART_ARTIST;
-            break;
+            return APE_TAG_COVER_ART_ARTIST;
         case IMAGE_TYPE_CONDUCTOR :
-            itp = APE_TAG_COVER_ART_CONDUCTOR;
-            break;
+            return APE_TAG_COVER_ART_CONDUCTOR;
         case IMAGE_TYPE_BAND :
-            itp = APE_TAG_COVER_ART_BAND;
-            break;
+            return APE_TAG_COVER_ART_BAND;
         case IMAGE_TYPE_COMPOSER :
-            itp = APE_TAG_COVER_ART_COMPOSER;
-            break;
+            return APE_TAG_COVER_ART_COMPOSER;
         case IMAGE_TYPE_LYRICIST :
-            itp = APE_TAG_COVER_ART_LYRICIST;
-            break;
+            return APE_TAG_COVER_ART_LYRICIST;
         case IMAGE_TYPE_RECORDING_LOCATION :
-            itp = APE_TAG_COVER_ART_STUDIO;
-            break;
+            return APE_TAG_COVER_ART_STUDIO;
         case IMAGE_TYPE_DURING_RECORDING :
-            itp = APE_TAG_COVER_ART_RECORDING;
-            break;
+            return APE_TAG_COVER_ART_RECORDING;
         case IMAGE_TYPE_DURING_PERFORMANCE :
-            itp = APE_TAG_COVER_ART_PERFORMANCE;;
-            break;
+            return APE_TAG_COVER_ART_PERFORMANCE;;
         case IMAGE_TYPE_MOVIESCREENCAPTURE :
-            itp = APE_TAG_COVER_ART_MOVIE_SCENE;;
-            break;
+            return APE_TAG_COVER_ART_MOVIE_SCENE;;
         case IMAGE_TYPE_COLOURED_FISH :
-            itp = APE_TAG_COVER_ART_COLORED_FISH;
-            break;
+            return APE_TAG_COVER_ART_COLORED_FISH;
         case IMAGE_TYPE_ILLUSTRATION :
-            itp = APE_TAG_COVER_ART_ILLUSTRATION;
-            break;
+            return APE_TAG_COVER_ART_ILLUSTRATION;
         case IMAGE_TYPE_ARTIST_LOGO :
-            itp = APE_TAG_COVER_ART_BAND_LOGO;
-            break;
+            return APE_TAG_COVER_ART_BAND_LOGO;
         case IMAGE_TYPE_PUBLISHER_LOGO :
-            itp = APE_TAG_COVER_ART_PUBLISHER_LOGO;
-            break;
+            return APE_TAG_COVER_ART_PUBLISHER_LOGO;
         default:
-            itp = APE_TAG_COVER_ART_OTHER;
-            break;
+            return APE_TAG_COVER_ART_OTHER;
     }
-    return itp;
 }
 
 ImageType ape_image_type_to_image_type(const String &nme) {
-
-    ImageType itp;
-    if(nme == APE_TAG_COVER_ART_OTHER)
-        itp = IMAGE_TYPE_OTHER;
+    if(nme == APE_TAG_COVER_ART_FRONT)
+        return IMAGE_TYPE_COVER_FRONT;
+    else if(nme == APE_TAG_COVER_ART_OTHER)
+        return IMAGE_TYPE_OTHER;
+    else if(nme == APE_TAG_COVER_ART_BACK)
+        return IMAGE_TYPE_COVER_BACK;
     else if(nme == APE_TAG_COVER_ART_ICON)
-        itp = IMAGE_TYPE_FILE_ICON;
+        return IMAGE_TYPE_FILE_ICON;
     else if(nme == APE_TAG_COVER_ART_OTHER_ICON)
-        itp = IMAGE_TYPE_OTHER_FILE_ICON;
-    else if(nme == APE_TAG_COVER_ART_FRONT)
-        itp = IMAGE_TYPE_COVER_FRONT;
-    else if(nme == APE_TAG_COVER_ART_BACK)
-        itp = IMAGE_TYPE_COVER_BACK;
+        return IMAGE_TYPE_OTHER_FILE_ICON;
     else if(nme == APE_TAG_COVER_ART_LEAFLET)
-        itp = IMAGE_TYPE_LEAFLET_PAGE;
+        return IMAGE_TYPE_LEAFLET_PAGE;
     else if(nme == APE_TAG_COVER_ART_MEDIA)
-        itp = IMAGE_TYPE_MEDIA;
+        return IMAGE_TYPE_MEDIA;
     else if(nme == APE_TAG_COVER_ART_LEAD)
-        itp = IMAGE_TYPE_LEAD_ARTIST;
+        return IMAGE_TYPE_LEAD_ARTIST;
     else if(nme == APE_TAG_COVER_ART_ARTIST)
-        itp = IMAGE_TYPE_ARTIST;
+        return IMAGE_TYPE_ARTIST;
     else if(nme == APE_TAG_COVER_ART_CONDUCTOR)
-        itp = IMAGE_TYPE_CONDUCTOR;
+        return IMAGE_TYPE_CONDUCTOR;
     else if(nme == APE_TAG_COVER_ART_BAND)
-        itp = IMAGE_TYPE_BAND;
+        return IMAGE_TYPE_BAND;
     else if(nme == APE_TAG_COVER_ART_COMPOSER)
-        itp = IMAGE_TYPE_COMPOSER;
+        return IMAGE_TYPE_COMPOSER;
     else if(nme == APE_TAG_COVER_ART_LYRICIST)
-        itp = IMAGE_TYPE_LYRICIST;
+        return IMAGE_TYPE_LYRICIST;
     else if(nme == APE_TAG_COVER_ART_STUDIO)
-        itp = IMAGE_TYPE_RECORDING_LOCATION;
+        return IMAGE_TYPE_RECORDING_LOCATION;
     else if(nme == APE_TAG_COVER_ART_RECORDING)
-        itp = IMAGE_TYPE_DURING_RECORDING;
+        return IMAGE_TYPE_DURING_RECORDING;
     else if(nme == APE_TAG_COVER_ART_PERFORMANCE)
-        itp = IMAGE_TYPE_DURING_PERFORMANCE;
+        return IMAGE_TYPE_DURING_PERFORMANCE;
     else if(nme == APE_TAG_COVER_ART_MOVIE_SCENE)
-        itp = IMAGE_TYPE_MOVIESCREENCAPTURE;
+        return IMAGE_TYPE_MOVIESCREENCAPTURE;
     else if(nme == APE_TAG_COVER_ART_COLORED_FISH)
-        itp = IMAGE_TYPE_COLOURED_FISH;
+        return IMAGE_TYPE_COLOURED_FISH;
     else if(nme == APE_TAG_COVER_ART_ILLUSTRATION)
-        itp = IMAGE_TYPE_ILLUSTRATION;
+        return IMAGE_TYPE_ILLUSTRATION;
     else if(nme == APE_TAG_COVER_ART_BAND_LOGO)
-        itp = IMAGE_TYPE_ARTIST_LOGO;
+        return IMAGE_TYPE_ARTIST_LOGO;
     else if(nme == APE_TAG_COVER_ART_PUBLISHER_LOGO)
-        itp = IMAGE_TYPE_PUBLISHER_LOGO;
+        return IMAGE_TYPE_PUBLISHER_LOGO;
     else
-        itp = IMAGE_TYPE_OTHER;
-
-    return itp;
+        return IMAGE_TYPE_OTHER;
 }
 
 
             }
             APE::ItemListMap map = taglib_apetag->itemListMap();
             for(APE::ItemListMap::ConstIterator it = map.begin(); it != map.end(); ++it) {
-                if(true ||
-                   it->first == APE_TAG_COVER_ART_OTHER          ||
+                if(it->first == APE_TAG_COVER_ART_OTHER          ||
                    it->first == APE_TAG_COVER_ART_ICON	         ||
                    it->first == APE_TAG_COVER_ART_OTHER_ICON     ||
                    it->first == APE_TAG_COVER_ART_FRONT          ||
                    it->first == APE_TAG_COVER_ART_COLORED_FISH   ||
                    it->first == APE_TAG_COVER_ART_ILLUSTRATION   ||
                    it->first == APE_TAG_COVER_ART_BAND_LOGO      ||
-                   it->first == APE_TAG_COVER_ART_PUBLISHER_LOGO ||
-                   true) {
+                   it->first == APE_TAG_COVER_ART_PUBLISHER_LOGO   ) {
                     has_image = true;
                 }
             }
     if(taglib_apetag) {
         if(changedflag) {
             if(changedflag & CHANGED_COMPOSER_TAG)
-                taglib_apetag->addValue(APE_TAG_COMPOSER, composer, true);
+                set_item(taglib_apetag, APE_TAG_COMPOSER, composer, true);
             if(changedflag & CHANGED_COPYRIGHT_TAG)
-                taglib_apetag->addValue(APE_TAG_COPYRIGHT, copyright, true);
+                set_item(taglib_apetag, APE_TAG_COPYRIGHT, copyright, true);
             if(changedflag & CHANGED_ORIGINALARTIST_TAG)
-                taglib_apetag->addValue(APE_TAG_ORIGINALARTIST, original_artist, true);
+                set_item(taglib_apetag, APE_TAG_ORIGINALARTIST, original_artist, true);
             if(changedflag & CHANGED_ENCODER_TAG)
-                taglib_apetag->addValue(APE_TAG_ENCODER, encoder, true);
+                set_item(taglib_apetag, APE_TAG_ENCODER, encoder, true);
             if(changedflag & CHANGED_HOMEPAGE_TAG)
-                taglib_apetag->addValue(APE_TAG_HOMEPAGE, homepage, true);
+                set_item(taglib_apetag, APE_TAG_HOMEPAGE, homepage, true);
             if(changedflag & CHANGED_TRACK_NUMBER) {
                 if(!(changedflag & CHANGED_TRACK_COUNT)) {
                     // prevent overwrite in save_base_tags()
                 }
             }
             if(changedflag & CHANGED_DATA_ALBUMARTIST)
-                    taglib_apetag->addValue(APE_TAG_ALBUMARTIST, album_artist, true);
+                set_item(taglib_apetag, APE_TAG_ALBUMARTIST, album_artist, true);
             
-            if(changedflag & CHANGED_DATA_RATING) {
+            if(changedflag & CHANGED_DATA_RATING)
                 taglib_apetag->addValue(APE_TAG_RATING, format("%u", rating_to_popularity(rating)), true);
-            }
-            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
+            
+            if(changedflag & CHANGED_DATA_PLAYCOUNT)
                 taglib_apetag->addValue(APE_TAG_PLAYCNT, format("%u", playcount), true);
-            }
+            
             if(changedflag & CHANGED_TRACK_LABELS)
-                check_ape_label_frame(taglib_apetag, TRACK_LABELS,  track_labels_string);
+                set_item(taglib_apetag, TRACK_LABELS, track_labels_string, true);
             if(changedflag & CHANGED_ARTIST_LABELS)
-                check_ape_label_frame(taglib_apetag, ARTIST_LABELS, artist_labels_string);
+                set_item(taglib_apetag, ARTIST_LABELS, artist_labels_string, true);
             if(changedflag & CHANGED_ALBUM_LABELS)
-                check_ape_label_frame(taglib_apetag, ALBUM_LABELS,  album_labels_string);
+                set_item(taglib_apetag, ALBUM_LABELS, album_labels_string, true);
             save_base_tags((TagLib::Tag *)taglib_apetag);
         }
     }
             int i = 0;
             APE::ItemListMap map = taglib_apetag->itemListMap();
             for(APE::ItemListMap::ConstIterator it = map.begin(); it != map.end(); ++it) {
-                if(true ||
-                   it->first == APE_TAG_COVER_ART_OTHER          ||
+                if(it->first == APE_TAG_COVER_ART_OTHER          ||
                    it->first == APE_TAG_COVER_ART_ICON	         ||
                    it->first == APE_TAG_COVER_ART_OTHER_ICON     ||
                    it->first == APE_TAG_COVER_ART_FRONT          ||
                    it->first == APE_TAG_COVER_ART_COLORED_FISH   ||
                    it->first == APE_TAG_COVER_ART_ILLUSTRATION   ||
                    it->first == APE_TAG_COVER_ART_BAND_LOGO      ||
-                   it->first == APE_TAG_COVER_ART_PUBLISHER_LOGO ||
-                   true) {
+                   it->first == APE_TAG_COVER_ART_PUBLISHER_LOGO   ) {
                     image = new Image();
-                    get_ape_item_image(it->second, image);
+                    extract_image(it->second, image);
                     if(image->data && image->data_length > 0) {
-                        image->image_type = ape_image_type_to_image_type(it->first);
+                        String apetype = String(it->first);
+                        image->image_type = ape_image_type_to_image_type(apetype);
                         imageList.prepend(image);
                         i++;
                     }
                     }
                }
             }
-            if(0 < i) {
-                images = new Image*[i];
+            if(0 < imageList.size()) {
+                images = new Image*[imageList.size()];
+                int ii = 0;
                 for(List<Image *>::Iterator it = imageList.begin(); it != imageList.end(); ++it) {
-                    images[image_count] = (*it);
+                    images[ii] = (*it);
+                    ii++;
                 }
-                image_count = i;
+                image_count = imageList.size();
                 return images;
             }
         }
 
 void ApeTagInfo::set_images(const Image ** images, const int image_count) {
     if(taglib_apetag) {
-        APE::ItemListMap listmap = taglib_apetag->itemListMap();
-        
         taglib_apetag->removeItem(APE_TAG_COVER_ART_OTHER);
         taglib_apetag->removeItem(APE_TAG_COVER_ART_ICON);
         taglib_apetag->removeItem(APE_TAG_COVER_ART_OTHER_ICON);
         taglib_apetag->removeItem(APE_TAG_COVER_ART_ILLUSTRATION);
         taglib_apetag->removeItem(APE_TAG_COVER_ART_BAND_LOGO);
         taglib_apetag->removeItem(APE_TAG_COVER_ART_PUBLISHER_LOGO);
-                
+        
         for(int p = 0; p < image_count; p++) {
             if(!images[p]->data || images[p]->data_length == 0)
                 continue;
 
 
 String ApeTagInfo::get_lyrics(void) const {
-    if(taglib_apetag->itemListMap().contains(APE_TAG_LYRICS)) {
+    if(taglib_apetag->itemListMap().contains(APE_TAG_LYRICS))
         return taglib_apetag->itemListMap()[APE_TAG_LYRICS].toStringList().front();
-    }
     return String();
 }
 

libtaginfo/asfinfo.cc

 }
 
 ImageType get_image_type_from_pic_type(const ASF::Picture::Type& tpe) {
-    ImageType itp = IMAGE_TYPE_OTHER;
     switch(tpe) {
         case ASF::Picture::FrontCover :
-            itp = IMAGE_TYPE_COVER_FRONT;
-            break;
+            return IMAGE_TYPE_COVER_FRONT;
         case ASF::Picture::BackCover :
-            itp = IMAGE_TYPE_COVER_BACK;
-            break;
+            return IMAGE_TYPE_COVER_BACK;
         case ASF::Picture::Other :
-            itp = IMAGE_TYPE_OTHER;
-            break;
+            return IMAGE_TYPE_OTHER;
         case ASF::Picture::FileIcon :
-            itp = IMAGE_TYPE_FILE_ICON;
-            break;
+            return IMAGE_TYPE_FILE_ICON;
         case ASF::Picture::OtherFileIcon :
-            itp = IMAGE_TYPE_OTHER_FILE_ICON;
-            break;
+            return IMAGE_TYPE_OTHER_FILE_ICON;
         case ASF::Picture::LeafletPage :
-            itp = IMAGE_TYPE_LEAFLET_PAGE;
-            break;
+            return IMAGE_TYPE_LEAFLET_PAGE;
         case ASF::Picture::Media :
-            itp = IMAGE_TYPE_MEDIA;
-            break;
+            return IMAGE_TYPE_MEDIA;
         case ASF::Picture::LeadArtist :
-            itp = IMAGE_TYPE_LEAD_ARTIST;
-            break;
+            return IMAGE_TYPE_LEAD_ARTIST;
         case ASF::Picture::Artist :
-            itp = IMAGE_TYPE_ARTIST;
-            break;
+            return IMAGE_TYPE_ARTIST;
         case ASF::Picture::Conductor :
-            itp = IMAGE_TYPE_CONDUCTOR;
-            break;
+            return IMAGE_TYPE_CONDUCTOR;
         case ASF::Picture::Band :
-            itp = IMAGE_TYPE_BAND;
-            break;
+            return IMAGE_TYPE_BAND;
         case ASF::Picture::Composer :
-            itp = IMAGE_TYPE_COMPOSER;
-            break;
+            return IMAGE_TYPE_COMPOSER;
         case ASF::Picture::Lyricist :
-            itp = IMAGE_TYPE_LYRICIST;
-            break;
+            return IMAGE_TYPE_LYRICIST;
         case ASF::Picture::RecordingLocation :
-            itp = IMAGE_TYPE_RECORDING_LOCATION;
-            break;
+            return IMAGE_TYPE_RECORDING_LOCATION;
         case ASF::Picture::DuringRecording :
-            itp = IMAGE_TYPE_DURING_RECORDING;
-            break;
+            return IMAGE_TYPE_DURING_RECORDING;
         case ASF::Picture::DuringPerformance :
-            itp = IMAGE_TYPE_DURING_PERFORMANCE;
-            break;
+            return IMAGE_TYPE_DURING_PERFORMANCE;
         case ASF::Picture::MovieScreenCapture :
-            itp = IMAGE_TYPE_MOVIESCREENCAPTURE;
-            break;
+            return IMAGE_TYPE_MOVIESCREENCAPTURE;
         case ASF::Picture::ColouredFish :
-            itp = IMAGE_TYPE_COLOURED_FISH;
-            break;
+            return IMAGE_TYPE_COLOURED_FISH;
         case ASF::Picture::Illustration :
-            itp = IMAGE_TYPE_ILLUSTRATION;
-            break;
+            return IMAGE_TYPE_ILLUSTRATION;
         case ASF::Picture::BandLogo :
-            itp = IMAGE_TYPE_ARTIST_LOGO;
-            break;
+            return IMAGE_TYPE_ARTIST_LOGO;
         case ASF::Picture::PublisherLogo :
-            itp = IMAGE_TYPE_PUBLISHER_LOGO;
-            break;
+            return IMAGE_TYPE_PUBLISHER_LOGO;
         default:
-            itp = IMAGE_TYPE_OTHER;
-            break;
+            return IMAGE_TYPE_OTHER;
     }
-    return itp;
 }
 
 ASF::Picture::Type image_type_to_picture_type(const ImageType& image_type) {
-    ASF::Picture::Type itp;
     switch(image_type) {
         case IMAGE_TYPE_COVER_FRONT :
-            itp = ASF::Picture::FrontCover;
-            break;
+            return ASF::Picture::FrontCover;
         case IMAGE_TYPE_COVER_BACK :
-            itp = ASF::Picture::BackCover;
-            break;
+            return ASF::Picture::BackCover;
         case IMAGE_TYPE_OTHER :
-            itp = ASF::Picture::Other;
-            break;
+            return ASF::Picture::Other;
         case IMAGE_TYPE_FILE_ICON :
-            itp = ASF::Picture::FileIcon;
-            break;
+            return ASF::Picture::FileIcon;
         case IMAGE_TYPE_OTHER_FILE_ICON :
-            itp = ASF::Picture::OtherFileIcon;
-            break;
+            return ASF::Picture::OtherFileIcon;
         case IMAGE_TYPE_LEAFLET_PAGE :
-            itp = ASF::Picture::LeafletPage;
-            break;
+            return ASF::Picture::LeafletPage;
         case IMAGE_TYPE_MEDIA  :
-            itp = ASF::Picture::Media;
-            break;
+            return ASF::Picture::Media;
         case IMAGE_TYPE_LEAD_ARTIST :
-            itp = ASF::Picture::LeadArtist;
-            break;
+            return ASF::Picture::LeadArtist;
         case IMAGE_TYPE_ARTIST :
-            itp = ASF::Picture::Artist;
-            break;
+            return ASF::Picture::Artist;
         case IMAGE_TYPE_CONDUCTOR :
-            itp = ASF::Picture::Conductor;
-            break;
+            return ASF::Picture::Conductor;
         case IMAGE_TYPE_BAND :
-            itp = ASF::Picture::Band;
-            break;
+            return ASF::Picture::Band;
         case IMAGE_TYPE_COMPOSER :
-            itp = ASF::Picture::Composer;
-            break;
+            return ASF::Picture::Composer;
         case IMAGE_TYPE_LYRICIST :
-            itp = ASF::Picture::Lyricist;
-            break;
+            return ASF::Picture::Lyricist;
         case IMAGE_TYPE_RECORDING_LOCATION :
-            itp = ASF::Picture::RecordingLocation;
-            break;
+            return ASF::Picture::RecordingLocation;
         case IMAGE_TYPE_DURING_RECORDING :
-            itp = ASF::Picture::DuringRecording;
-            break;
+            return ASF::Picture::DuringRecording;
         case IMAGE_TYPE_DURING_PERFORMANCE :
-            itp = ASF::Picture::DuringPerformance;
-            break;
+            return ASF::Picture::DuringPerformance;
         case IMAGE_TYPE_MOVIESCREENCAPTURE :
-            itp = ASF::Picture::MovieScreenCapture;
-            break;
+            return ASF::Picture::MovieScreenCapture;
         case IMAGE_TYPE_COLOURED_FISH :
-            itp = ASF::Picture::ColouredFish;
-            break;
+            return ASF::Picture::ColouredFish;
         case IMAGE_TYPE_ILLUSTRATION :
-            itp = ASF::Picture::Illustration;
-            break;
+            return ASF::Picture::Illustration;
         case IMAGE_TYPE_ARTIST_LOGO :
-            itp = ASF::Picture::BandLogo;
-            break;
+            return ASF::Picture::BandLogo;
         case IMAGE_TYPE_PUBLISHER_LOGO :
-            itp = ASF::Picture::PublisherLogo;
-            break;
+            return ASF::Picture::PublisherLogo;
         default:
-            itp = ASF::Picture::Other;
-            break;
+            return ASF::Picture::Other;
     }
 }
 
             ASF::AttributeList list = asf_tag->attributeListMap()[ PICTURE_FLAG ];
             if(0 >= list.size())
                 return NULL;
-            int i = 0;
+            int i = list.size() - 1;
             images = new Image*[list.size()];
-            for(ASF::AttributeList::ConstIterator it = list.begin(); it != list.end(); it++) {
-                //ASF::Attribute attr = (*it);
+            ASF::AttributeList::ConstIterator it = list.end();
+            for(ASF::AttributeList::ConstIterator it = list.begin(); it != list.end() ; it++) {
                 ASF::Picture pict = (*it).toPicture();
-                if(!pict.isValid())
-                    continue;
-                ByteVector pict_data = pict.picture();
-                Image * image = new Image();
-                if(pict_data.size() > 0) {
-                    image->data_length = pict_data.size();
-                    image->data = new char[image->data_length];
-                    memcpy(image->data, pict_data.data(), pict_data.size());
-                    
-                    String mimetype = pict.mimeType();
-                    if(mimetype.find("/jpeg") != -1 || mimetype.find("/jpg") != -1)
-                        image->image_file_type = IMAGE_FILE_TYPE_JPEG;
-                    else if(mimetype.find("/png") != -1)
-                        image->image_file_type = IMAGE_FILE_TYPE_PNG;
-                    else if(mimetype.find("/bmp") != -1)
-                        image->image_file_type = IMAGE_FILE_TYPE_BMP;
-                    else if(mimetype.find("/gif") != -1)
-                        image->image_file_type = IMAGE_FILE_TYPE_GIF;
-                    
-                    image->image_type = get_image_type_from_pic_type(pict.type()); 
-                                        
-                    if(image->data && image->data_length > 0) {
+                if(pict.isValid()) {
+                    ByteVector pict_data = pict.picture();
+                    Image * image = new Image();
+                    if(pict_data.size() > 0) {
+                        image->data_length = pict_data.size();
+                        image->data = new char[image->data_length];
+                        memcpy(image->data, pict_data.data(), pict_data.size());
+                        
+                        String mimetype = pict.mimeType();
+                        if(mimetype.find("/jpeg") != -1 || mimetype.find("/jpg") != -1)
+                            image->image_file_type = IMAGE_FILE_TYPE_JPEG;
+                        else if(mimetype.find("/png") != -1)
+                            image->image_file_type = IMAGE_FILE_TYPE_PNG;
+                        else if(mimetype.find("/bmp") != -1)
+                            image->image_file_type = IMAGE_FILE_TYPE_BMP;
+                        else if(mimetype.find("/gif") != -1)
+                            image->image_file_type = IMAGE_FILE_TYPE_GIF;
+                        
+                        image->image_type  = get_image_type_from_pic_type(pict.type()); 
+                        const char * cstr = pict.description().toCString(false);
+                        if(cstr)
+                            image->description = ::strdup(cstr);
                         images[i] = image;
-                        image_count++;
-                        i++;
-                    }
-                    else {
-                        delete image;
+                        i--;
                     }
                 }
-            }
+            } 
+            image_count = list.size();
             return images;
         }
     }
             
             ByteVector ImgData = ByteVector((TagLib::uint) image->data_length);
             memcpy(ImgData.data(), image->data, image->data_length);
-            
+            if(image->description) {
+                String desc = String(image->description);
+                picture.setDescription(desc);
+            }
             picture.setPicture(ImgData);
+cout << " image types " << image_type_to_picture_type(image->image_type) << " " << image->image_type << endl;
             picture.setType(image_type_to_picture_type(image->image_type));
             ASF::Attribute attr = ASF::Attribute(picture);
             asf_tag->addAttribute(PICTURE_FLAG, attr);

libtaginfo/flacinfo.cc

 }
 
 ImageType flac_image_type_to_image_type(const FLAC::Picture::Type &tpe) {
-    ImageType itp;
     switch(tpe) {
         case FLAC::Picture::FrontCover:
-            itp = IMAGE_TYPE_COVER_FRONT;
-            break;
+            return IMAGE_TYPE_COVER_FRONT;
         case FLAC::Picture::BackCover:
-            itp = IMAGE_TYPE_COVER_BACK;
-            break;
+            return IMAGE_TYPE_COVER_BACK;
         case FLAC::Picture::Other:
-            itp = IMAGE_TYPE_OTHER;
-            break;
+            return IMAGE_TYPE_OTHER;
         case FLAC::Picture::FileIcon:
-            itp = IMAGE_TYPE_FILE_ICON;
-            break;
+            return IMAGE_TYPE_FILE_ICON;
         case FLAC::Picture::OtherFileIcon:
-            itp = IMAGE_TYPE_OTHER_FILE_ICON;
-            break;
+            return IMAGE_TYPE_OTHER_FILE_ICON;
         case FLAC::Picture::LeafletPage:
-            itp = IMAGE_TYPE_LEAFLET_PAGE;
-            break;
+            return IMAGE_TYPE_LEAFLET_PAGE;
         case FLAC::Picture::Media:
-            itp = IMAGE_TYPE_MEDIA;
-            break;
+            return IMAGE_TYPE_MEDIA;
         case FLAC::Picture::LeadArtist:
-            itp = IMAGE_TYPE_LEAD_ARTIST;
-            break;
+            return IMAGE_TYPE_LEAD_ARTIST;
         case FLAC::Picture::Artist:
-            itp = IMAGE_TYPE_ARTIST;
-            break;
+            return IMAGE_TYPE_ARTIST;
         case FLAC::Picture::Conductor:
-            itp = IMAGE_TYPE_CONDUCTOR;
-            break;
+            return IMAGE_TYPE_CONDUCTOR;
         case FLAC::Picture::Band:
-            itp = IMAGE_TYPE_BAND;
-            break;
+            return IMAGE_TYPE_BAND;
         case FLAC::Picture::Composer:
-            itp = IMAGE_TYPE_COMPOSER;
-            break;
+            return IMAGE_TYPE_COMPOSER;
         case FLAC::Picture::Lyricist:
-            itp = IMAGE_TYPE_LYRICIST;
-            break;
+            return IMAGE_TYPE_LYRICIST;
         case FLAC::Picture::RecordingLocation:
-            itp = IMAGE_TYPE_RECORDING_LOCATION;
-            break;
+            return IMAGE_TYPE_RECORDING_LOCATION;
         case FLAC::Picture::DuringRecording:
-            itp = IMAGE_TYPE_DURING_RECORDING;
-            break;
+            return IMAGE_TYPE_DURING_RECORDING;
         case FLAC::Picture::DuringPerformance:
-            itp = IMAGE_TYPE_DURING_PERFORMANCE;
-            break;
+            return IMAGE_TYPE_DURING_PERFORMANCE;
         case FLAC::Picture::MovieScreenCapture:
-            itp = IMAGE_TYPE_MOVIESCREENCAPTURE;
-            break;
+            return IMAGE_TYPE_MOVIESCREENCAPTURE;
         case FLAC::Picture::ColouredFish:
-            itp = IMAGE_TYPE_COLOURED_FISH;
-            break;
+            return IMAGE_TYPE_COLOURED_FISH;
         case FLAC::Picture::Illustration:
-            itp = IMAGE_TYPE_ILLUSTRATION;
-            break;
+            return IMAGE_TYPE_ILLUSTRATION;
         case FLAC::Picture::BandLogo:
-            itp = IMAGE_TYPE_ARTIST_LOGO;
-            break;
+            return IMAGE_TYPE_ARTIST_LOGO;
         case FLAC::Picture::PublisherLogo:
-            itp = IMAGE_TYPE_PUBLISHER_LOGO;
-            break;
+            return IMAGE_TYPE_PUBLISHER_LOGO;
         default:
-            itp = IMAGE_TYPE_OTHER;
-            break;
+            return IMAGE_TYPE_OTHER;
     }
-    return itp;    
 }
 
 Image ** FlacInfo::get_images(int &image_count) const {
                 Image * image = new Image();
                 FLAC::Picture * p = (*it);
                 image->image_type = flac_image_type_to_image_type(p->type());
+                image->description = ::strdup(p->description().toCString(false));
                 image->data_length = p->data().size();
                 image->data = new char[image->data_length];
                 memcpy(image->data, p->data().data(), image->data_length);

libtaginfo/mp4info.cc

 
 
 ImageFileType get_image_file_type_from_format(TagLib::MP4::CoverArt::Format format) {
-    ImageFileType ift = IMAGE_FILE_TYPE_UNKNOWN;
     switch(format) {
         case MP4::CoverArt::JPEG:
-            ift = IMAGE_FILE_TYPE_JPEG;
-            break;
+            return IMAGE_FILE_TYPE_JPEG;
         case MP4::CoverArt::PNG:
-            ift = IMAGE_FILE_TYPE_PNG;
-            break;
+            return IMAGE_FILE_TYPE_PNG;
         case MP4::CoverArt::BMP:
-            ift = IMAGE_FILE_TYPE_BMP;
-            break;
+            return IMAGE_FILE_TYPE_BMP;
         case MP4::CoverArt::GIF:
-            ift = IMAGE_FILE_TYPE_GIF;
-            break;
+            return IMAGE_FILE_TYPE_GIF;
         default:
-            break;
+            return IMAGE_FILE_TYPE_UNKNOWN;
     }
-    return ift;
 }
 
 TagLib::MP4::CoverArt::Format get_format_from_image_file_type(ImageFileType image_file_type) {
-    TagLib::MP4::CoverArt::Format format = TagLib::MP4::CoverArt::JPEG;
     switch(image_file_type) {
         case IMAGE_FILE_TYPE_JPEG:
-            format = TagLib::MP4::CoverArt::JPEG;
+            return MP4::CoverArt::JPEG;
             break;
         case IMAGE_FILE_TYPE_PNG:
-            format = TagLib::MP4::CoverArt::PNG;
+            return MP4::CoverArt::PNG;
             break;
         case IMAGE_FILE_TYPE_BMP:
-            format = TagLib::MP4::CoverArt::BMP;
+            return MP4::CoverArt::BMP;
             break;
         case IMAGE_FILE_TYPE_GIF:
-            format = TagLib::MP4::CoverArt::GIF;
+            return MP4::CoverArt::GIF;
             break;
         default:
-            break;
+            return MP4::CoverArt::JPEG;
     }
-    return format;
 }
 
 
             int i = 0;
             for(TagLib::MP4::CoverArtList::Iterator it = covers.begin(); it != covers.end(); it++) {
                 image = new Image();
-                image->image_type = IMAGE_TYPE_COVER_FRONT; // is it possible to distinguish?
+                image->image_type = IMAGE_TYPE_OTHER;
                 image->data_length = it->data().size();
                 image->data = new char[image->data_length];
                 memcpy(image->data, it->data().data(), it->data().size());
                 image->image_file_type = get_image_file_type_from_format(it->format());
                 
                 if(image->data && image->data_length > 0) {
+                    image->description = NULL;
                     images[i] = image;
                     i++;
                 }

libtaginfo/xiphinfo.cc

             }
             if(i < descr_cnt) {
                 description = pic_descr[i];
-                image->description = ::strdup(description.toCString(true));
+                image->description = ::strdup(description.toCString(false));
             }
-
+            
             const char* CoverEncData = pics[i].toCString(false);
             
             string CoverDecData = base64_decode(CoverEncData);

tests/write_ape/main.cc

     std::string val = TESTDIR "samples/sample.ape";
     
     //std::cout << std::endl << "val: " << val << std::endl;
-std::cout << "++1" << std::endl;
     std::string target = "/tmp/out_01.ape";
     
     std::ifstream  src(val.c_str());
     std::ofstream  dst(target.c_str());
     dst << src.rdbuf();
     
-std::cout << "++2" << std::endl;
     info = Info::create(target);
-std::cout << "++3" << std::endl;
     
     StringList labels = StringList();
     labels.append("user label1 äöüé");
     labels.append("user label1 äiiüé");
     
     if( info ) {
-std::cout << "++4" << std::endl;
         info->set_artist("artißt");
         info->set_genre("gen re");
         info->set_composer("cömpozér");
     
     info = Info::create(target);
     if( info ) {
-std::cout << "++5" << std::endl;
         if(info->load()) {
-std::cout << "++6" << std::endl;
             if(info->get_artist() == "artißt" &&
                info->get_genre() == "gen re" &&
                info->get_composer() == "cömpozér" &&

tests/write_image_ape/main.cc

     std::string val   = TESTDIR "samples/sample.ape";
     std::string image = TESTDIR "samples/test.jpg";
     
-    //std::cout << std::endl << "val: " << val << std::endl;
     std::string target = "/tmp/out_01.ape";
-    
+
     std::ifstream  src(val.c_str());
     std::ofstream  dst(target.c_str());
     dst << src.rdbuf();
-    
+    //std::cout << "##1" << std::endl;
     Image * img = new Image();
     img->image_file_type = IMAGE_FILE_TYPE_JPEG;
-    img->image_type      = IMAGE_TYPE_OTHER;
+    img->image_type      = IMAGE_TYPE_COVER_FRONT;
+    // Image description not supported by APE
+    //img->description     = ::strdup(String("Bescräibunk").toCString(false));
     
+    Image * img2 = new Image();
+    img2->image_file_type = IMAGE_FILE_TYPE_JPEG;
+    img2->image_type      = IMAGE_TYPE_COVER_BACK;
+    // Image description not supported by APE
+    //img2->description     = ::strdup(String("Beßcräibunk").toCString(false));
+
     struct stat filestatus;
     stat( image.c_str(), &filestatus );
     //cout << filestatus.st_size << " bytes\n";
     img->data_length = filestatus.st_size;
+    img2->data_length = filestatus.st_size;
     int fd;
     
     fd = open(image.c_str(), O_RDONLY);
         EXIT_FAILURE;
     }
     
-    img->data = (char*)mmap(0, img->data_length, PROT_READ, MAP_SHARED, fd, 0);
-    if(img->data == MAP_FAILED) {
+    img->data  = (char*)mmap(0, img->data_length, PROT_READ, MAP_SHARED, fd, 0);
+    img2->data = (char*)mmap(0, img2->data_length, PROT_READ, MAP_SHARED, fd, 0);
+    if(img->data == MAP_FAILED || img2->data == MAP_FAILED) {
         close(fd);
         perror("Error mmapping the file");
         EXIT_FAILURE;
     
     info = Info::create(target);
     if(info) {
-        Image ** imgs = new Image*[1];
+        Image ** imgs = new Image*[2];
         imgs[0] = img;
-        info->set_images((const Image **)imgs, 1);
+        imgs[1] = img2;
+        info->set_images((const Image **)imgs, 2);
         if(imgs)
             delete [] imgs;
         info->save();
     
     info = Info::create(target);
     Image * read_image;
+    Image * read_image2;
     if(info) {
         if(info->load()) {
             int len = 0;
                 }
                 return EXIT_FAILURE;
             }
-            read_image = images[0];
-            if(!images[0] || !read_image) {
+            read_image  = images[0];
+            read_image2 = images[1];
+            if(!images[0] || !read_image|| !read_image2) {
                 delete info;
                 if(remove(target.c_str()) != 0 ) {
                     if(images)
                     return EXIT_FAILURE;
                 }
             }
+            if(img->image_type != read_image->image_type) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            if(read_image->description != NULL) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            if(read_image2->description != NULL) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            if(img2->image_type != read_image2->image_type) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
             int i;
             for(i = 0; i<img->data_length; i++) {
                 if(img->data[i] != read_image->data[i]) {
                     return EXIT_FAILURE;
                 }
             }
+            for(i = 0; i<img2->data_length; i++) {
+                if(img2->data[i] != read_image2->data[i]) {
+                    if(images)
+                        delete [] images;
+                    return EXIT_FAILURE;
+                }
+            }
             if(images)
                 delete [] images;
             if(remove(target.c_str()) != 0 )
     }
     return EXIT_FAILURE;
 }
+
+

tests/write_image_flac/main.cc

     
     //std::cout << std::endl << "val: " << val << std::endl;
     std::string target = "/tmp/out_01.flac";
+//    std::string val   = TESTDIR "samples/sample_v2_only.mp3";
+//    std::string image = TESTDIR "samples/test.jpg";
+//    
+//    //std::cout << std::endl << "val: " << val << std::endl;
+//    std::string target = "/tmp/out_01.mp3";
     
     std::ifstream  src(val.c_str());
     std::ofstream  dst(target.c_str());
     
     Image * img = new Image();
     img->image_file_type = IMAGE_FILE_TYPE_JPEG;
-    img->image_type      = IMAGE_TYPE_OTHER;
+    img->image_type      = IMAGE_TYPE_COVER_FRONT;
+    img->description     = ::strdup(String("Bescräibunk").toCString(false));
+    
+    Image * img2 = new Image();
+    img2->image_file_type = IMAGE_FILE_TYPE_JPEG;
+    img2->image_type      = IMAGE_TYPE_COVER_BACK;
+    img2->description     = ::strdup(String("Beßcräibunk").toCString(false));
 
     struct stat filestatus;
     stat( image.c_str(), &filestatus );
     //cout << filestatus.st_size << " bytes\n";
     img->data_length = filestatus.st_size;
+    img2->data_length = filestatus.st_size;
     int fd;
+    
     fd = open(image.c_str(), O_RDONLY);
     if (fd == -1) {
         perror("Error opening file for reading");
         EXIT_FAILURE;
     }
     
-    img->data = (char*)mmap(0, img->data_length, PROT_READ, MAP_SHARED, fd, 0);
-    if(img->data == MAP_FAILED) {
+    img->data  = (char*)mmap(0, img->data_length, PROT_READ, MAP_SHARED, fd, 0);
+    img2->data = (char*)mmap(0, img2->data_length, PROT_READ, MAP_SHARED, fd, 0);
+    if(img->data == MAP_FAILED || img2->data == MAP_FAILED) {
         close(fd);
         perror("Error mmapping the file");
         EXIT_FAILURE;
     }
     
+    //std::cout <<  "++1 " << std::endl;
     info = Info::create(target);
     if(info) {
-        Image ** imgs = new Image*[1];
+        Image ** imgs = new Image*[2];
         imgs[0] = img;
-        info->set_images((const Image **)imgs, 1);
+        imgs[1] = img2;
+        info->set_images((const Image **)imgs, 2);
+        if(imgs)
+            delete [] imgs;
         info->save();
     }
     delete info;
     info = NULL;
     
     info = Info::create(target);
-    Image * read_image = NULL;
-    
+    Image * read_image;
+    Image * read_image2;
     if(info) {
         if(info->load()) {
             int len = 0;
                 }
                 return EXIT_FAILURE;
             }
-            read_image = images[0];
-            if(!images[0] || !read_image) {
+            read_image  = images[0];
+            read_image2 = images[1];
+            if(!images[0] || !read_image|| !read_image2) {
                 delete info;
                 if(remove(target.c_str()) != 0 ) {
-                    if(img)
-                        delete img;
+                    if(images)
+                        delete [] images;
                     return EXIT_FAILURE;
                 }
             }
+            if(img->image_type != read_image->image_type) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            String st = String(read_image->description);
+            if(strcmp(img->description, st.toCString(false)) != 0) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            st = String(read_image2->description);
+            if(strcmp(img2->description, st.toCString(false)) != 0) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            if(img2->image_type != read_image2->image_type) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
             int i;
             for(i = 0; i<img->data_length; i++) {
                 if(img->data[i] != read_image->data[i]) {
                     if(images)
                         delete [] images;
-                    if(read_image)
-                        delete read_image;
+                    return EXIT_FAILURE;
+                }
+            }
+            for(i = 0; i<img2->data_length; i++) {
+                if(img2->data[i] != read_image2->data[i]) {
+                    if(images)
+                        delete [] images;
                     return EXIT_FAILURE;
                 }
             }
     return EXIT_FAILURE;
 }
 
+

tests/write_image_mp3/main.cc

     Image * img = new Image();
     img->image_file_type = IMAGE_FILE_TYPE_JPEG;
     img->image_type      = IMAGE_TYPE_COVER_FRONT;
-    img->description     = ::strdup(String("Bescräibunk", String::UTF8).toCString(false));
+    img->description     = ::strdup(String("Bescräibunk").toCString(false));
     
     Image * img2 = new Image();
     img2->image_file_type = IMAGE_FILE_TYPE_JPEG;
     img2->image_type      = IMAGE_TYPE_COVER_BACK;
-    img2->description     = ::strdup(String("Beßcräibunk", String::UTF8).toCString(false));
+    img2->description     = ::strdup(String("Beßcräibunk").toCString(false));
 
     struct stat filestatus;
     stat( image.c_str(), &filestatus );

tests/write_image_mp4/main.cc

     std::string val   = TESTDIR "samples/sample.m4a";
     std::string image = TESTDIR "samples/test.jpg";
     
-    //std::cout << "val: " << val << std::endl;
     std::string target = "/tmp/out_01.m4a";
     
     std::ifstream  src(val.c_str());
     
     Image * img = new Image();
     img->image_file_type = IMAGE_FILE_TYPE_JPEG;
-    img->image_type      = IMAGE_TYPE_OTHER;
+//    img->image_type      = IMAGE_TYPE_COVER_FRONT;
+//    img->description     = ::strdup(String("Bescräibunk").toCString(false));
     
+    Image * img2 = new Image();
+    img2->image_file_type = IMAGE_FILE_TYPE_JPEG;
+//    img2->image_type      = IMAGE_TYPE_COVER_BACK;
+//    img2->description     = ::strdup(String("Beßcräibunk").toCString(false));
+
     struct stat filestatus;
     stat( image.c_str(), &filestatus );
     //cout << filestatus.st_size << " bytes\n";
     img->data_length = filestatus.st_size;
+    img2->data_length = filestatus.st_size;
     int fd;
     
     fd = open(image.c_str(), O_RDONLY);
     if (fd == -1) {
         perror("Error opening file for reading");
-        return EXIT_FAILURE;
+        EXIT_FAILURE;
     }
     
-    img->data = (char*)mmap(0, img->data_length, PROT_READ, MAP_SHARED, fd, 0);
-    if(img->data == MAP_FAILED) {
+    img->data  = (char*)mmap(0, img->data_length, PROT_READ, MAP_SHARED, fd, 0);
+    img2->data = (char*)mmap(0, img2->data_length, PROT_READ, MAP_SHARED, fd, 0);
+    if(img->data == MAP_FAILED || img2->data == MAP_FAILED) {
         close(fd);
         perror("Error mmapping the file");
-        return EXIT_FAILURE;
+        EXIT_FAILURE;
     }
     
     info = Info::create(target);
     if(info) {
-        Image ** imgs = new Image*[1];
+        Image ** imgs = new Image*[2];
         imgs[0] = img;
-        info->set_images((const Image **)imgs, 1);
+        imgs[1] = img2;
+        info->set_images((const Image **)imgs, 2);
         if(imgs)
             delete [] imgs;
         info->save();
     
     info = Info::create(target);
     Image * read_image;
+    Image * read_image2;
     if(info) {
         if(info->load()) {
             int len = 0;
                 }
                 return EXIT_FAILURE;
             }
-            read_image = images[0];
-            if(!images[0] || !read_image) {
+            read_image  = images[0];
+            read_image2 = images[1];
+            if(!images[0] || !read_image|| !read_image2) {
                 delete info;
                 if(remove(target.c_str()) != 0 ) {
                     if(images)
                     return EXIT_FAILURE;
                 }
             }
+            for(i = 0; i<img2->data_length; i++) {
+                if(img2->data[i] != read_image2->data[i]) {
+                    if(images)
+                        delete [] images;
+                    return EXIT_FAILURE;
+                }
+            }
             if(images)
                 delete [] images;
             if(remove(target.c_str()) != 0 )
     }
     return EXIT_FAILURE;
 }
+
+

tests/write_image_ogg/main.cc

     Image * img = new Image();
     img->image_file_type = IMAGE_FILE_TYPE_JPEG;
     img->image_type      = IMAGE_TYPE_OTHER;
-    img->description     = ::strdup(String("Bescräibunk", String::UTF8).toCString(false));
+    img->description     = ::strdup(String("Bescräibunk").toCString(false));
 
     Image * img2 = new Image();
     img2->image_file_type = IMAGE_FILE_TYPE_JPEG;
     img2->image_type      = IMAGE_TYPE_COVER_FRONT;
-    img2->description     = ::strdup(String("Beßcräibunk", String::UTF8).toCString(false));
+    img2->description     = ::strdup(String("Beßcräibunk").toCString(false));
     
     struct stat filestatus;
     stat( image.c_str(), &filestatus );
                     delete read_image;
                 return EXIT_FAILURE;
             }
-            String st = String(read_image->description, String::UTF8);
+            String st = String(read_image->description);
             if(strcmp(img->description, st.toCString(false)) != 0) {
                 if(images)
                     delete [] images;
                     delete read_image;
                 return EXIT_FAILURE;
             }
-            st = String(read_image2->description, String::UTF8);
+            st = String(read_image2->description);
             if(strcmp(img2->description, st.toCString(false)) != 0) {
                 if(images)
                     delete [] images;

tests/write_image_speex/main.cc

     std::string val   = TESTDIR "samples/sample_empty.spx";
     std::string image = TESTDIR "samples/test.jpg";
     
-    //std::cout << std::endl << "val: " << val << std::endl;
     std::string target = "/tmp/out_01.spx";
-    
+    //std::cout << "##1: " << std::endl;
     std::ifstream  src(val.c_str());
     std::ofstream  dst(target.c_str());
     dst << src.rdbuf();
     Image * img = new Image();
     img->image_file_type = IMAGE_FILE_TYPE_JPEG;
     img->image_type      = IMAGE_TYPE_OTHER;
+    img->description     = ::strdup(String("Bescräibunk").toCString(false));
 
+    Image * img2 = new Image();
+    img2->image_file_type = IMAGE_FILE_TYPE_JPEG;
+    img2->image_type      = IMAGE_TYPE_COVER_FRONT;
+    img2->description     = ::strdup(String("Beßcräibunk").toCString(false));
+    
     struct stat filestatus;
     stat( image.c_str(), &filestatus );
     //cout << filestatus.st_size << " bytes\n";
-    img->data_length = filestatus.st_size;
+    img->data_length  = filestatus.st_size;
+    img2->data_length = filestatus.st_size;
     int fd;
     fd = open(image.c_str(), O_RDONLY);
     if (fd == -1) {
     }
     
     img->data = (char*)mmap(0, img->data_length, PROT_READ, MAP_SHARED, fd, 0);
-    if(img->data == MAP_FAILED) {
+    img2->data = (char*)mmap(0, img2->data_length, PROT_READ, MAP_SHARED, fd, 0);
+    if(img->data == MAP_FAILED || img2->data == MAP_FAILED) {
         close(fd);
         perror("Error mmapping the file");
         EXIT_FAILURE;
     
     info = Info::create(target);
     if(info) {
-        Image ** imgs = new Image*[1];
+        Image ** imgs = new Image*[2];
         imgs[0] = img;
-        info->set_images((const Image **)imgs, 1);
+        imgs[1] = img2;
+        info->set_images((const Image **)imgs, 2);
         info->save();
     }
     delete info;
     
     info = Info::create(target);
     Image * read_image = NULL;
+    Image * read_image2 = NULL;
     
     if(info) {
         if(info->load()) {
             int len = 0;
             Image ** images = info->get_images(len);
-            if(!images) {
+            if(!images || len != 2) {
                 delete info;
                 if(remove(target.c_str()) != 0 ) {
                     return EXIT_FAILURE;
                 return EXIT_FAILURE;
             }
             read_image = images[0];
-            if(!images[0] || !read_image) {
+            read_image2 = images[1];
+            if(!images[0] || !read_image|| !read_image2) {
                 delete info;
                 if(remove(target.c_str()) != 0 ) {
                     if(img)
                         delete img;
+                    if(img2)
+                        delete img2;
                     return EXIT_FAILURE;
                 }
             }
             int i;
+            if(img->image_type != read_image->image_type) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            String st = String(read_image->description);
+            if(strcmp(img->description, st.toCString(false)) != 0) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            st = String(read_image2->description);
+            if(strcmp(img2->description, st.toCString(false)) != 0) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            if(img2->image_type != read_image2->image_type) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
             for(i = 0; i<img->data_length; i++) {
                 if(img->data[i] != read_image->data[i]) {
                     if(images)
                     return EXIT_FAILURE;
                 }
             }
+            for(i = 0; i<img2->data_length; i++) {
+                if(img2->data[i] != read_image->data[i]) {
+                    if(images)
+                        delete [] images;
+                    if(read_image2)
+                        delete read_image;
+                    return EXIT_FAILURE;
+                }
+            }
             if(images)
                 delete [] images;
             if(remove(target.c_str()) != 0 )
     return EXIT_FAILURE;
 }
 
+
+

tests/write_image_wma/main.cc

 #include <sys/stat.h>
 
 using namespace TagInfo;
-//using namespace std;
 
-void clean_up(char* map, int size, int fd) {
-    if(munmap(map, size) == -1) {
-        perror("Error un-mmapping the file");
-    }
-    if(fd != 0)
-        close(fd);
-}
 
 int main( void ) {
     Info * info;
     std::string val   = TESTDIR "samples/sample.wma";
     std::string image = TESTDIR "samples/test.jpg";
     
-    //std::cout << std::endl << "val: " << val << std::endl;
     std::string target = "/tmp/out_01.wma";
-    
+    //std::cout << "##1: " << std::endl;
     std::ifstream  src(val.c_str());
     std::ofstream  dst(target.c_str());
     dst << src.rdbuf();
 
     Image * img = new Image();
     img->image_file_type = IMAGE_FILE_TYPE_JPEG;
-    img->image_type      = IMAGE_TYPE_OTHER;
+    img->image_type      = IMAGE_TYPE_ILLUSTRATION;
+    img->description     = ::strdup(String("Bescräibunk").toCString(false));
 
+    Image * img2 = new Image();
+    img2->image_file_type = IMAGE_FILE_TYPE_JPEG;
+    img2->image_type      = IMAGE_TYPE_COVER_FRONT;
+    img2->description     = ::strdup(String("Beßcräibunk").toCString(false));
+    
     struct stat filestatus;
     stat( image.c_str(), &filestatus );
     //cout << filestatus.st_size << " bytes\n";
-    img->data_length = filestatus.st_size;
+    img->data_length  = filestatus.st_size;
+    img2->data_length = filestatus.st_size;
     int fd;
     fd = open(image.c_str(), O_RDONLY);
     if (fd == -1) {
     }
     
     img->data = (char*)mmap(0, img->data_length, PROT_READ, MAP_SHARED, fd, 0);
-    if(img->data == MAP_FAILED) {
+    img2->data = (char*)mmap(0, img2->data_length, PROT_READ, MAP_SHARED, fd, 0);
+    if(img->data == MAP_FAILED || img2->data == MAP_FAILED) {
         close(fd);
         perror("Error mmapping the file");
         EXIT_FAILURE;
     
     info = Info::create(target);
     if(info) {
-        Image ** imgs = new Image*[1];
+        Image ** imgs = new Image*[2];
         imgs[0] = img;
-        info->set_images((const Image **)imgs, 1);
+        imgs[1] = img2;
+        info->set_images((const Image **)imgs, 2);
         info->save();
     }
     delete info;
     
     info = Info::create(target);
     Image * read_image = NULL;
+    Image * read_image2 = NULL;
     
     if(info) {
         if(info->load()) {
             int len = 0;
             Image ** images = info->get_images(len);
-            if(!images) {
+            if(!images || len != 2) {
                 delete info;
                 if(remove(target.c_str()) != 0 ) {
                     return EXIT_FAILURE;
                 return EXIT_FAILURE;
             }
             read_image = images[0];
-            if(!images[0] || !read_image) {
+            read_image2 = images[1];
+            if(!images[0] || !read_image|| !read_image2) {
                 delete info;
                 if(remove(target.c_str()) != 0 ) {
                     if(img)
                         delete img;
+                    if(img2)
+                        delete img2;
                     return EXIT_FAILURE;
                 }
             }
             int i;
+            if(img->image_type != read_image->image_type) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            String st = String(read_image->description);
+            if(strcmp(img->description, st.toCString(false)) != 0) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            st = String(read_image2->description);
+            if(strcmp(img2->description, st.toCString(false)) != 0) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
+            if(img2->image_type != read_image2->image_type) {
+                if(images)
+                    delete [] images;
+                if(read_image)
+                    delete read_image;
+                return EXIT_FAILURE;
+            }
             for(i = 0; i<img->data_length; i++) {
                 if(img->data[i] != read_image->data[i]) {
                     if(images)
                     return EXIT_FAILURE;
                 }
             }
+            for(i = 0; i<img2->data_length; i++) {
+                if(img2->data[i] != read_image->data[i]) {
+                    if(images)
+                        delete [] images;
+                    if(read_image2)
+                        delete read_image;
+                    return EXIT_FAILURE;
+                }
+            }
             if(images)
                 delete [] images;
             if(remove(target.c_str()) != 0 )
     }
     return EXIT_FAILURE;
 }
+
+
+