Commits

shuerhaaken committed bff36f3

add image red/write test for mpc; packaging fixes

  • Participants
  • Parent commits f0e1d7a

Comments (0)

Files changed (16)

 .dirstamp
 libtaginfoconfig.h
 tests/*/test
+package_result
+commit f0e1d7ad2420e891d2a71720c55d95da3c3814e6
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Mon Mar 11 23:24:24 2013 +0100
+
+    add some image read/write tests
+
+commit 9f8707ada4f99017fe84642f1d7df4069c96b725
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 7 16:30:33 2013 +0100
+
+    update packaging data
+
+commit 12cb8087f03f088af92d4491b50fdc33e1de9d15
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 7 14:32:28 2013 +0100
+
+    update project info 4
+
+commit 2f4f045af2d348547abda98cc4a81bb9f601aae3
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 7 14:30:33 2013 +0100
+
+    update project info 3
+
+commit 92e761eab2905a7704262f3f1b8be4c59caba645
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 7 14:15:33 2013 +0100
+
+    update project info 3
+
+commit 732f92571a9db8c9ae03d8964fd3eed57ee7d689
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 7 14:11:21 2013 +0100
+
+    update project info 2
+
+commit 2fa0c925eebf14fd82c9111d1996f21a34695153
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 7 14:09:09 2013 +0100
+
+    update project info
+
+commit c322e5a43f4324091b1590d6fe874bc06202e4af
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 7 13:24:27 2013 +0100
+
+    add dist hook for automatic changelog creation
+
 commit 85506d1fda883f820987e4ddb214b812bec5cb46
 Author: Jörn Magens <shuerhaaken@googlemail.com>
 Date:   Thu Mar 7 11:43:56 2013 +0100
 AC_PREREQ([2.59])
 m4_define(libtaginfo_major_version, 0)
 m4_define(libtaginfo_minor_version, 1)
-m4_define(libtaginfo_micro_version, 3)
+m4_define(libtaginfo_micro_version, 4)
 m4_define(libtaginfo_version, libtaginfo_major_version.libtaginfo_minor_version.libtaginfo_micro_version)
 m4_define([libtaginfo_name], [libtaginfo])
 
 LT_INIT([disable-static])
 
 dnl -------------------------------------------------
-TAGLIB_C_REQUIRED=1.7
+TAGLIB_C_REQUIRED=1.8
 
 PKG_CHECK_MODULES(LIBTAGINFO, \
     taglib >= $TAGLIB_C_REQUIRED)

libtaginfo/ape_common.cc

 #include <string.h>
 #include "taginfo_internal.h"
 
+#define COVER_ART_FRONT         "COVER ART (FRONT)"
+#define COVER_ART_OTHER         "COVER ART (OTHER)"
+#define TAG_LYRICS              "LYRICS"
+#define TAG_LYRICS_UNSYNCED     "UNSYNCED LYRICS"
+
 
 
 void check_ape_label_frame(TagLib::APE::Tag * apetag, const char * description, const String &value) {
 bool get_ape_item_image(const TagLib::APE::Item &item, char*& data, int &data_length, ImageType &image_type) {
     image_type = IMAGE_TYPE_UNKNOWN;
     if(item.type() == TagLib::APE::Item::Binary) {
-        TagLib::ByteVector CoverData = item.value();
+        TagLib::ByteVector CoverData = item.binaryData();
         if(CoverData.size() > 0) {
             data_length = CoverData.size();
             data = new char[data_length];
     data_length = 0;
     
     if(apetag) {
-        if(apetag->itemListMap().contains("Cover Art (front)")) {
-            return get_ape_item_image(apetag->itemListMap()[ "Cover Art (front)" ],
+        //for(APE::ItemListMap::ConstIterator it = apetag->itemListMap().begin();
+        //   it != apetag->itemListMap().end(); ++it) {
+        //  cout << (*it).first << " - \""  << "\"" << endl; //<< (*it).second.toString()
+        //}
+        
+        if(apetag->itemListMap().contains(COVER_ART_FRONT)) {
+            return get_ape_item_image(apetag->itemListMap()[COVER_ART_FRONT],
                                       data, data_length, image_type);
         }
-        else if(apetag->itemListMap().contains("Cover Art (other)")) {
-            return get_ape_item_image(apetag->itemListMap()[ "Cover Art (other)" ],
+        else if(apetag->itemListMap().contains(COVER_ART_OTHER)) {
+            return get_ape_item_image(apetag->itemListMap()[COVER_ART_OTHER],
                                       data, data_length, image_type);
         }
         return false;
 
 bool set_ape_image(TagLib::APE::Tag * apetag, const char* data, int data_length, ImageType image_type) {
     if(apetag) {
-        apetag->addValue("Cover Art (front)", data);
+        APE::ItemListMap listmap = apetag->itemListMap();
+        if(listmap.contains(COVER_ART_FRONT))
+            apetag->removeItem(COVER_ART_FRONT);
+        
+        if(!data || data_length <= 0)
+            return true;
+        
+        ByteVector ImgData = ByteVector((TagLib::uint) data_length);
+        memcpy(ImgData.data(), data, data_length);
+        
+        APE::Item imageItem = APE::Item();
+        imageItem.setType(TagLib::APE::Item::Binary);
+        imageItem.setKey(COVER_ART_FRONT);
+        imageItem.setBinaryData(ImgData);
+        //if(imageItem.isEmpty())
+        //    cout << "set#5.1" << endl;
+        //else
+        //    cout << "set#5.2" << endl;
+        apetag->setItem(COVER_ART_FRONT, imageItem);
         return true;
     }
     return false;
 
 String get_ape_lyrics(APE::Tag * apetag) {
     if(apetag) {
-        if(apetag->itemListMap().contains("LYRICS")) {
-            return apetag->itemListMap()[ "LYRICS" ].toStringList().front();
+        if(apetag->itemListMap().contains(TAG_LYRICS)) {
+            return apetag->itemListMap()[TAG_LYRICS].toStringList().front();
         }
-        else if(apetag->itemListMap().contains("UNSYNCED LYRICS")) {
-            return apetag->itemListMap()[ "UNSYNCED LYRICS" ].toStringList().front();
+        else if(apetag->itemListMap().contains(TAG_LYRICS_UNSYNCED)) {
+            return apetag->itemListMap()[TAG_LYRICS_UNSYNCED].toStringList().front();
         }
     }
     return "";
 
 bool set_ape_lyrics(APE::Tag * apetag, const String &lyrics) {
     if(apetag) {
-        if(apetag->itemListMap().contains("LYRICS")) {
-            apetag->removeItem("LYRICS");
+        if(apetag->itemListMap().contains(TAG_LYRICS)) {
+            apetag->removeItem(TAG_LYRICS);
         }
-        if(apetag->itemListMap().contains("UNSYNCED LYRICS")) {
-            apetag->removeItem("UNSYNCED LYRICS");
+        if(apetag->itemListMap().contains(TAG_LYRICS_UNSYNCED)) {
+            apetag->removeItem(TAG_LYRICS_UNSYNCED);
         }
         if(!lyrics.isEmpty()) {
-            apetag->addValue("Lyrics", lyrics);
+            apetag->addValue(TAG_LYRICS, lyrics);
         }
         return true;
     }

libtaginfo/asfinfo.cc

     image_type = IMAGE_TYPE_UNKNOWN;
     if(asftag) {
         if(asftag->attributeListMap().contains("WM/Picture")) {
-            ByteVector PictureData = asftag->attributeListMap()["WM/Picture"].front().toByteVector();
+            ASF::Attribute attr = asftag->attributeListMap()["WM/Picture"].front();
+            ASF::Picture pict = attr.toPicture();
+            if(!pict.isValid())
+                return false;
             
-            TagLib::ID3v2::AttachedPictureFrame * PicFrame = 
-                (TagLib::ID3v2::AttachedPictureFrame *) PictureData.data();
+            ByteVector PictureData = pict.picture();
             
-            if(PicFrame->picture().size() > 0) {
-                data_length = PicFrame->picture().size();
+            if(PictureData.size() > 0) {
+                data_length = PictureData.size();
                 data = new char[data_length];
-                memcpy(data, PicFrame->picture().data(), PicFrame->picture().size());
+                memcpy(data, PictureData.data(), PictureData.size());
                 
-                String mimetype = PicFrame->mimeType();
+                String mimetype = pict.mimeType();
                 if(mimetype.find("/jpeg") != -1 || mimetype.find("/jpg") != -1)
                     image_type = IMAGE_TYPE_JPEG;
                 else if(mimetype.find("/png") != -1)
     return false;
 }
 
+bool set_asf_image(ASF::Tag * asftag, const char* data, int data_length, ImageType image_type) {
+    if(asftag) {
+        if(asftag->attributeListMap().contains("WM/Picture"))
+            asftag->removeItem("WM/Picture");
+        
+        if(!data || data_length == 0)
+            return true;
+        
+        ASF::Picture picture = ASF::Picture();
+        if(image_type == IMAGE_TYPE_JPEG || image_type == IMAGE_TYPE_UNKNOWN) //default to jpeg
+            picture.setMimeType("image/jpeg");
+        if(image_type == IMAGE_TYPE_PNG)
+            picture.setMimeType("image/png");
+        
+        ByteVector ImgData = ByteVector((TagLib::uint) data_length);
+        memcpy(ImgData.data(), data, data_length);
+        
+        picture.setPicture(ImgData);
+        ASF::Attribute attr = ASF::Attribute(picture);
+        asftag->setAttribute("WM/Picture", attr);
+        
+        return true;
+    }
+    return false;
+}
+
 ASFInfo::ASFInfo(const String &filename) : Info(filename) {
     if(!file_name.isEmpty() && !create_file_ref())
         printf("Error creating file ref! %s\n", filename.toCString());
 }
 
 bool ASFInfo::set_image(const char* data, int data_length, ImageType image_type) {
-    //TODO
+    if(asf_tag) {
+        return set_asf_image(asf_tag, data, data_length, image_type);
+    }
     return false;
 }
 

libtaginfo/mpcinfo.cc

 #include "taginfo.h"
 #include "taginfo_internal.h"
 
+#define COVER_ART_FRONT         "COVER ART (FRONT)"
+#define COVER_ART_OTHER         "COVER ART (OTHER)"
+
 
 using namespace TagInfo;
 
                     album_labels = split(album_labels_string, "|");
                 }
             }
-            if(taglib_apetag->itemListMap().contains("Cover Art (front)")) {
+            if(taglib_apetag->itemListMap().contains(COVER_ART_FRONT)) {
                 has_image = true;
             }
-            else if(taglib_apetag->itemListMap().contains("Cover Art (other)")) {
+            else if(taglib_apetag->itemListMap().contains(COVER_ART_OTHER)) {
                 has_image = true;
             }
             return true;

packaging/Makefile.am

 dist_noinst_DATA = \
     debian/debian/changelog \
     debian/debian/compat \
+    debian/debian/rules \
     debian/debian/control \
     debian/debian/copyright \
     debian/debian/docs \
     debian/debian/libtaginfo.1 \
     debian/debian/libtaginfo1-dev.install \
     debian/debian/libtaginfo1.install \
-    debian/debian/libtaginfo1.lintian-overrides \
     debian/debian/libtaginfoc0-dev.install \
     debian/debian/libtaginfoc0.install \
     debian/debian/libtaginfoc0.lintian-overrides \
     debian/debian/libtaginfo.manpages \
     debian/debian/source/format \
     ubuntu/raring/debian/changelog \
+    ubuntu/raring/debian/rules \
     ubuntu/raring/debian/compat \
     ubuntu/raring/debian/control \
     ubuntu/raring/debian/copyright \
     ubuntu/raring/debian/libtaginfo.1 \
     ubuntu/raring/debian/libtaginfo1-dev.install \
     ubuntu/raring/debian/libtaginfo1.install \
-    ubuntu/raring/debian/libtaginfo1.lintian-overrides \
     ubuntu/raring/debian/libtaginfoc0-dev.install \
     ubuntu/raring/debian/libtaginfoc0.install \
     ubuntu/raring/debian/libtaginfoc0.lintian-overrides \
     ubuntu/raring/debian/source/format \
     ubuntu/quantal/debian/changelog \
     ubuntu/quantal/debian/compat \
+    ubuntu/quantal/debian/rules \
     ubuntu/quantal/debian/control \
     ubuntu/quantal/debian/copyright \
     ubuntu/quantal/debian/docs \
     ubuntu/quantal/debian/libtaginfo.1 \
     ubuntu/quantal/debian/libtaginfo1-dev.install \
     ubuntu/quantal/debian/libtaginfo1.install \
-    ubuntu/quantal/debian/libtaginfo1.lintian-overrides \
     ubuntu/quantal/debian/libtaginfoc0-dev.install \
     ubuntu/quantal/debian/libtaginfoc0.install \
     ubuntu/quantal/debian/libtaginfoc0.lintian-overrides \

packaging/debian/debian/changelog

-libtaginfo (0.1.3) unstable; urgency=low
+libtaginfo (0.1.4-1) unstable; urgency=low
   * fixe .pc files
 
  -- Jörn Magens <shuerhaaken@googlemail.com>  Wed, 07 Mar 2013 10:15:16 +0100

packaging/debian/debian/libtaginfo1.lintian-overrides

-libtaginfo1: package-name-doesnt-match-sonames libtaginfo1

packaging/ubuntu/quantal/debian/changelog

-libtaginfo (0.1.3-1ppa1~quantal) quantal; urgency=medium
+libtaginfo (0.1.4-1ppa1~quantal) quantal; urgency=medium
   * fix .pc file
 
  -- Jörn Magens <shuerhaaken@googlemail.com>  Thu, 07 Mar 2013 09:38:57 +0100

packaging/ubuntu/quantal/debian/libtaginfo1.lintian-overrides

-libtaginfo1: package-name-doesnt-match-sonames libtaginfo1

packaging/ubuntu/raring/debian/changelog

-libtaginfo (0.1.3-1ppa1~raring) raring; urgency=medium
+libtaginfo (0.1.4-1ppa1~raring) raring; urgency=medium
   * fix .pc file
 
  -- Jörn Magens <shuerhaaken@googlemail.com>  Thu, 07 Mar 2013 09:38:57 +0100

packaging/ubuntu/raring/debian/libtaginfo1.lintian-overrides

-libtaginfo1: package-name-doesnt-match-sonames libtaginfo1

tests/Makefile.am

     write_wav/test \
     write_wma/test \
     ctest_read/test \
-    ctest_write/test
+    ctest_write/test \
+    write_image_mp3/test \
+    write_image_mpc/test \
+    write_image_ogg/test \
+    write_image_wma/test
 
 TESTS = $(check_PROGRAMS)
 
 ctest_write_test_SOURCES        = ctest_write/main.c
 ctest_write_test_LDADD          = $(top_builddir)/bindings/c/libtaginfo_c.la
 
+write_image_mp3_test_SOURCES    = write_image_mp3/main.cc
+write_image_mp3_test_LDADD      = $(taginfo_ldadd)
+
+write_image_mpc_test_SOURCES    = write_image_mpc/main.cc
+write_image_mpc_test_LDADD      = $(taginfo_ldadd)
+
+write_image_ogg_test_SOURCES    = write_image_ogg/main.cc
+write_image_ogg_test_LDADD      = $(taginfo_ldadd)
+
+write_image_wma_test_SOURCES    = write_image_wma/main.cc
+write_image_wma_test_LDADD      = $(taginfo_ldadd)
+
 
 DISTCLEANFILES = \
     Makefile.in

tests/samples/Makefile.am

 noinst_DATA = \
+    test.jpg \
     sample.aif \
     sample.ape \
     sample_apple_tags.m4a \

tests/write_image_mpc/main.cc

+#include "taginfo.h"
+#include <stdio.h>
+#include <iostream>
+#include <fstream>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#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.mpc";
+    std::string image = TESTDIR "samples/test.jpg";
+    
+    //std::cout << std::endl << "val: " << val << std::endl;
+    std::string target = "/tmp/out_01.mpc";
+    
+    std::ifstream  src(val.c_str());
+    std::ofstream  dst(target.c_str());
+    dst << src.rdbuf();
+    
+    char* data;
+    int data_length;
+    ImageType image_type = IMAGE_TYPE_JPEG;
+    
+    struct stat filestatus;
+    stat( image.c_str(), &filestatus );
+    //cout << filestatus.st_size << " bytes\n";
+    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;
+    }
+    data = (char*)mmap(0, data_length, PROT_READ, MAP_SHARED, fd, 0);
+    if(data == MAP_FAILED) {
+        close(fd);
+        perror("Error mmapping the file");
+        EXIT_FAILURE;
+    }
+    
+    info = Info::create_tag_info(target);
+    if(info) {
+        if(!info->set_image(data, data_length, image_type)) {
+            clean_up(data, data_length, fd);
+            delete info;
+            return EXIT_FAILURE;
+        }
+        info->write();
+    }
+    delete info;
+    info = NULL;
+    
+    info = Info::create_tag_info(target);
+    char* read;
+    int read_length;
+    ImageType read_type;
+    if(info) {
+        if(info->read()) {
+            if(!info->get_image(read, read_length, read_type)) {
+                delete info;
+                if(!read || remove(target.c_str()) != 0 ) {
+                    clean_up(data, data_length, fd);
+                    return EXIT_FAILURE;
+                }
+            }
+            int i;
+            for(i = 0; i<data_length; i++) {
+                if(!read || data[i] != read[i]) {
+                    clean_up(data, data_length, fd);
+                    free(read);
+                    return EXIT_FAILURE;
+                }
+            }
+            clean_up(data, data_length, fd);
+            free(read);
+            if(remove(target.c_str()) != 0 )
+                return EXIT_FAILURE;
+            return EXIT_SUCCESS;
+        }
+        delete info;
+        clean_up(data, data_length, fd);
+        if(remove(target.c_str()) != 0 )
+            return EXIT_FAILURE;
+        return EXIT_FAILURE;
+    }
+    else {
+       delete info;
+        clean_up(data, data_length, fd);
+        if(remove(target.c_str()) != 0 )
+            return EXIT_FAILURE;
+        return EXIT_FAILURE;
+    }
+    return EXIT_FAILURE;
+}
+