[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdesupport/taglib
From:       Lukáš Lalinský <lalinsky () gmail ! com>
Date:       2010-07-25 11:06:36
Message-ID: 20100725110636.B7229AC7E2 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1154376 by lalinsky:

Read-only support for FLAC picture blocks

CCBUG:218696


 M  +1 -0      bindings/c/CMakeLists.txt  
 M  +2 -0      taglib/CMakeLists.txt  
 M  +1 -1      taglib/flac/CMakeLists.txt  
 M  +3 -2      taglib/flac/Makefile.am  
 M  +42 -1     taglib/flac/flacfile.cpp  
 M  +20 -0     taglib/flac/flacfile.h  
 A             taglib/flac/flacpicture.cpp   [License: LGPL (v2.1) (wrong address)]
 A             taglib/flac/flacpicture.h   [License: LGPL (v2.1) (wrong address)]
 AM            tests/data/silence-44-s.flac  
 M  +21 -0     tests/test_flac.cpp  


--- trunk/kdesupport/taglib/bindings/c/CMakeLists.txt #1154375:1154376
@@ -9,6 +9,7 @@
 		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mpc
 		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mp4
 		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mpeg/id3v2
+		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mpeg/id3v2/frames
 		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/wavpack
 		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/ogg/speex
 		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/trueaudio
--- trunk/kdesupport/taglib/taglib/CMakeLists.txt #1154375:1154376
@@ -12,6 +12,7 @@
     ${CMAKE_CURRENT_SOURCE_DIR}/ogg/vorbis
     ${CMAKE_CURRENT_SOURCE_DIR}/ogg/speex
     ${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2
+    ${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2/frames
     ${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v1
     ${CMAKE_CURRENT_SOURCE_DIR}/ape
     ${CMAKE_CURRENT_SOURCE_DIR}/wavpack
@@ -92,6 +93,7 @@
 
 SET(flacs_SRCS
 flac/flacfile.cpp
+flac/flacpicture.cpp
 flac/flacproperties.cpp
 )
 
--- trunk/kdesupport/taglib/taglib/flac/CMakeLists.txt #1154375:1154376
@@ -1 +1 @@
-INSTALL( FILES  flacfile.h flacproperties.h DESTINATION ${INCLUDE_INSTALL_DIR}/taglib )
+INSTALL( FILES  flacfile.h flacpicture.h flacproperties.h DESTINATION ${INCLUDE_INSTALL_DIR}/taglib )
--- trunk/kdesupport/taglib/taglib/flac/Makefile.am #1154375:1154376
@@ -4,12 +4,13 @@
 	-I$(top_srcdir)/taglib/toolkit \
 	-I$(top_srcdir)/taglib/ogg \
 	-I$(top_srcdir)/taglib/mpeg/id3v2 \
+	-I$(top_srcdir)/taglib/mpeg/id3v2/frames \ 
 	-I$(top_srcdir)/taglib/mpeg/id3v1 \
 	$(all_includes)
 
 noinst_LTLIBRARIES = libflac.la
 
-libflac_la_SOURCES = flacfile.cpp flacproperties.cpp
+libflac_la_SOURCES = flacfile.cpp flacpicture.cpp flacproperties.cpp
 
-taglib_include_HEADERS = flacfile.h flacproperties.h
+taglib_include_HEADERS = flacfile.h flacpicture.h flacproperties.h
 taglib_includedir = $(includedir)/taglib
--- trunk/kdesupport/taglib/taglib/flac/flacfile.cpp #1154375:1154376
@@ -34,6 +34,7 @@
 #include <id3v1tag.h>
 #include <xiphcomment.h>
 
+#include "flacpicture.h"
 #include "flacfile.h"
 
 using namespace TagLib;
@@ -41,7 +42,15 @@
 namespace
 {
   enum { XiphIndex = 0, ID3v2Index = 1, ID3v1Index = 2 };
-  enum { StreamInfo = 0, Padding, Application, SeekTable, VorbisComment, CueSheet };
+  enum {
+    StreamInfo = 0,
+    Padding,
+    Application,
+    SeekTable,
+    VorbisComment,
+    CueSheet,
+    PictureBlock
+  };
   enum { MinPaddingLength = 4096 };
 }
 
@@ -64,6 +73,9 @@
 
   ~FilePrivate()
   {
+    for(uint i = 0; i < pictureList.size(); i++) {
+      delete pictureList[i];
+    }
     delete properties;
   }
 
@@ -78,6 +90,7 @@
   Properties *properties;
   ByteVector streamInfoData;
   ByteVector xiphCommentData;
+  List<Picture *> pictureList;
 
   long flacStart;
   long streamStart;
@@ -423,6 +436,16 @@
         debug("FLAC::File::scan() -- multiple Vorbis Comment blocks found, using the first one");
       }
     }
+    else if(blockType == PictureBlock) {
+      ByteVector pictureData = readBlock(length);
+      FLAC::Picture *picture = new FLAC::Picture();
+      if(picture->parse(pictureData)) {
+        addPicture(picture);
+      }
+      else {
+        debug("FLAC::File::scan() -- invalid picture found");
+      }
+    }
 
     nextBlockOffset += length + 4;
 
@@ -502,3 +525,21 @@
 
   return 0;
 }
+
+List<FLAC::Picture *> FLAC::File::pictureList()
+{
+  return d->pictureList;
+}
+
+void FLAC::File::addPicture(Picture *picture)
+{
+  d->pictureList.append(picture);
+}
+
+void FLAC::File::removePictures()
+{
+  for(uint i = 0; i < d->pictureList.size(); i++)
+    delete d->pictureList[i];
+  d->pictureList.clear();
+}
+
--- trunk/kdesupport/taglib/taglib/flac/flacfile.h #1154375:1154376
@@ -28,7 +28,9 @@
 
 #include "taglib_export.h"
 #include "tfile.h"
+#include "tlist.h"
 
+#include "flacpicture.h"
 #include "flacproperties.h"
 
 namespace TagLib {
@@ -182,6 +184,24 @@
        */
       long streamLength();  // BIC: remove
 
+      /*!
+       * Returns a list of pictures attached to the FLAC file.
+       */
+      List<Picture *> pictureList();
+
+      /*!
+       * Remove all attached images.
+       */
+      void removePictures();
+
+      /*!
+       * Add a new picture to the file. The file takes ownership of the
+       * picture and will handle freeing its memory.
+       *
+       * \note The file will be saved only after calling save().
+       */
+      void addPicture(Picture *picture);
+
     private:
       File(const File &);
       File &operator=(const File &);
--- trunk/kdesupport/taglib/tests/test_flac.cpp #1154375:1154376
@@ -15,6 +15,7 @@
   CPPUNIT_TEST_SUITE(TestFLAC);
   CPPUNIT_TEST(testSignature);
   CPPUNIT_TEST(testMultipleCommentBlocks);
+  CPPUNIT_TEST(testPicture);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -41,6 +42,26 @@
     delete f;
   }
 
+  void testPicture()
+  {
+    ScopedFileCopy copy("silence-44-s", ".flac");
+    string newname = copy.fileName();
+
+    FLAC::File *f = new FLAC::File(newname.c_str());
+    List<FLAC::Picture *> lst = f->pictureList();
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size());
+
+    FLAC::Picture *pic = lst.front();
+    CPPUNIT_ASSERT_EQUAL(3, int(pic->type()));
+    CPPUNIT_ASSERT_EQUAL(1, pic->width());
+    CPPUNIT_ASSERT_EQUAL(1, pic->height());
+    CPPUNIT_ASSERT_EQUAL(24, pic->colorDepth());
+    CPPUNIT_ASSERT_EQUAL(0, pic->numColors());
+    CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType());
+    CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description());
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic->data().size());
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic