[easytag/wip/taglib-mp4-cxx: 5/5] Implement cover art support for MP4



commit 5e5d400c2f1b6398f94291970531efc3cef88594
Author: Santtu Lakkala <inz inz fi>
Date:   Thu Apr 10 08:58:55 2014 +0100

    Implement cover art support for MP4
    
    Adds support for saving cover image into MP4 files, and show the images
    tab for them as well.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701506

 src/easytag.c  |    2 +-
 src/mp4_tag.cc |   51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/src/easytag.c b/src/easytag.c
index 86340e6..92a5def 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -4139,7 +4139,7 @@ void Tag_Area_Display_Controls (ET_File *ETFile)
             gtk_widget_hide(GTK_WIDGET(URLEntry));
             gtk_widget_show (GTK_WIDGET (EncodedByLabel));
             gtk_widget_show (GTK_WIDGET (EncodedByEntry));
-            et_tag_notebook_hide_images_tab (TagNoteBook);
+            et_tag_notebook_show_images_tab (TagNoteBook);
             break;
 #endif
 
diff --git a/src/mp4_tag.cc b/src/mp4_tag.cc
index b619642..b1c5a1f 100644
--- a/src/mp4_tag.cc
+++ b/src/mp4_tag.cc
@@ -180,7 +180,23 @@ gboolean Mp4tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
     /***********
      * Picture *
      ***********/
-    /* FIXME: Add picture support. */
+    const TagLib::MP4::ItemListMap extra_items = tag->itemListMap ();
+
+    if (extra_items.contains ("covr"))
+    {
+        const TagLib::MP4::Item cover = extra_items["covr"];
+        const TagLib::MP4::CoverArt &art = cover.toCoverArtList ().front ();
+
+        FileTag->picture = Picture_Allocate ();
+
+        FileTag->picture->size = art.data ().size ();
+        FileTag->picture->data = (guchar *)g_memdup (art.data ().data (),
+                                                     art.data ().size ());
+    }
+    else
+    {
+        FileTag->picture = NULL;
+    }
 
     return TRUE;
 }
@@ -353,8 +369,39 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
     /***********
      * Picture *
      ***********/
+    TagLib::MP4::ItemListMap &extra_items = tag->itemListMap ();
+
+    if (FileTag->picture)
+    {
+        Picture_Format pf;
+        TagLib::MP4::CoverArt::Format f;
+
+        pf = Picture_Format_From_Data (FileTag->picture);
+
+        switch (pf)
+        {
+            case PICTURE_FORMAT_JPEG:
+                f = TagLib::MP4::CoverArt::JPEG;
+                break;
+            case PICTURE_FORMAT_PNG:
+                f = TagLib::MP4::CoverArt::PNG;
+                break;
+            case PICTURE_FORMAT_GIF:
+                f = TagLib::MP4::CoverArt::GIF;
+                break;
+            default:
+                g_critical ("Unknown format");
+                f = TagLib::MP4::CoverArt::JPEG;
+                break;
+        }
+
+        TagLib::MP4::CoverArt art (f, TagLib::ByteVector((char *)FileTag->picture->data,
+                                                         FileTag->picture->size));
+
+        extra_items.insert ("covr",
+                            TagLib::MP4::Item (TagLib::MP4::CoverArtList ().append (art)));
+    }
 
-    /* FIXME: Add picture support. */
     tag->setProperties (fields);
     success = mp4file.save () ? TRUE : FALSE;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]