]> granicus.if.org Git - taglib/commitdiff
Add direct support APIC (attached picture) frames. I'll probably add an
authorScott Wheeler <wheeler@kde.org>
Mon, 26 Apr 2004 08:49:02 +0000 (08:49 +0000)
committerScott Wheeler <wheeler@kde.org>
Mon, 26 Apr 2004 08:49:02 +0000 (08:49 +0000)
example to the examples dir later today showing how to use this.

CCMAIL:Matthias Welwarsky <matze@stud.fbi.fh-darmstadt.de>
CCMAIL:Jorn Baayen <jbaayen@gnome.org>

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@306452 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

mpeg/id3v2/frames/Makefile.am
mpeg/id3v2/frames/attachedpictureframe.cpp [new file with mode: 0644]
mpeg/id3v2/frames/attachedpictureframe.h [new file with mode: 0644]
mpeg/id3v2/id3v2framefactory.cpp

index 73b2bb882c5d645f1ea2a25ba399e18d2dc4c7b8..ea3a8c979cc57f0e4585998e210a0584d7d64577 100644 (file)
@@ -5,9 +5,18 @@ INCLUDES = \
 
 noinst_LTLIBRARIES = libframes.la
 
-libframes_la_SOURCES = unknownframe.cpp textidentificationframe.cpp commentsframe.cpp
+libframes_la_SOURCES = \
+       attachedpictureframe.cpp \
+       commentsframe.cpp \
+       textidentificationframe.cpp \
+       unknownframe.cpp
+
+taglib_include_HEADERS = \
+       attachedpictureframe.h \
+       commentsframe.h \
+       textidentificationframe.h \
+       unknownframe.h
 
-taglib_include_HEADERS = unknownframe.h textidentificationframe.h commentsframe.h
 taglib_includedir = $(includedir)/taglib
 
 EXTRA_DIST = $(libframes_la_SOURCES) $(taglib_include_HEADERS)
diff --git a/mpeg/id3v2/frames/attachedpictureframe.cpp b/mpeg/id3v2/frames/attachedpictureframe.cpp
new file mode 100644 (file)
index 0000000..565c435
--- /dev/null
@@ -0,0 +1,160 @@
+/***************************************************************************
+    copyright            : (C) 2004 by Scott Wheeler
+    email                : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ *   This library is free software; you can redistribute it and/or modify  *
+ *   it  under the terms of the GNU Lesser General Public License version  *
+ *   2.1 as published by the Free Software Foundation.                     *
+ *                                                                         *
+ *   This library is distributed in the hope that it will be useful, but   *
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
+ *   Lesser General Public License for more details.                       *
+ *                                                                         *
+ *   You should have received a copy of the GNU Lesser General Public      *
+ *   License along with this library; if not, write to the Free Software   *
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
+ *   USA                                                                   *
+ ***************************************************************************/
+
+#include <tdebug.h>
+
+#include "attachedpictureframe.h"
+
+using namespace TagLib;
+using namespace ID3v2;
+
+class AttachedPictureFrame::AttachedPictureFramePrivate
+{
+public:
+  AttachedPictureFramePrivate() : textEncoding(String::Latin1),
+                                 type(AttachedPictureFrame::Other) {}
+
+  String::Type textEncoding;
+  String mimeType;
+  AttachedPictureFrame::Type type;
+  String description;
+  ByteVector data;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+AttachedPictureFrame::AttachedPictureFrame(const ByteVector &data) : Frame(data)
+{
+  setData(data);
+  d = new AttachedPictureFramePrivate;
+}
+
+AttachedPictureFrame::~AttachedPictureFrame()
+{
+  delete d;
+}
+
+String AttachedPictureFrame::toString() const
+{
+  String s = "[" + d->mimeType + "]";
+  return d->description.isEmpty() ? s : d->description + " " + s;
+}
+
+String::Type AttachedPictureFrame::textEncoding() const
+{
+  return d->textEncoding;
+}
+
+void AttachedPictureFrame::setTextEncoding(String::Type t)
+{
+  d->textEncoding = t;
+}
+
+String AttachedPictureFrame::mimeType() const
+{
+  return d->mimeType;
+}
+
+void AttachedPictureFrame::setMimeType(const String &m)
+{
+  d->mimeType = m;
+}
+
+AttachedPictureFrame::Type AttachedPictureFrame::type() const
+{
+  return d->type;
+}
+
+void AttachedPictureFrame::setType(Type t)
+{
+  d->type = t;
+}
+
+ByteVector AttachedPictureFrame::picture() const
+{
+  return d->data;
+}
+
+void AttachedPictureFrame::setPicture(const ByteVector &p)
+{
+  d->data = p;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// protected members
+////////////////////////////////////////////////////////////////////////////////
+
+void AttachedPictureFrame::parseFields(const ByteVector &data)
+{
+  if(data.size() < 5) {
+    debug("A picture frame must contain at least 5 bytes.");
+    return;
+  }
+
+  int pos = 0;
+
+  d->textEncoding = String::Type(data[pos]);
+  pos += 1;
+
+  int offset = data.find(textDelimiter(String::Latin1), pos);
+  if(offset < pos)
+    return;
+  d->mimeType = String(data.mid(pos, offset - pos), String::Latin1);
+  pos = offset + 1;
+
+  d->type = Type(data[pos]);
+  pos += 1;
+
+  offset = data.find(textDelimiter(d->textEncoding), pos);
+  if(offset < pos)
+    return;  
+  d->description = String(data.mid(pos, offset - pos), d->textEncoding);
+  pos = offset + 1;
+
+  d->data = data.mid(pos);
+}
+
+ByteVector AttachedPictureFrame::renderFields() const
+{
+  ByteVector data;
+
+  data.append(char(d->textEncoding));
+  data.append(d->mimeType.data(String::Latin1));
+  data.append(textDelimiter(String::Latin1));
+  data.append(char(d->type));
+  data.append(d->description.data(d->textEncoding));
+  data.append(textDelimiter(d->textEncoding));
+  data.append(d->data);
+
+  return data;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// private members
+////////////////////////////////////////////////////////////////////////////////
+
+AttachedPictureFrame::AttachedPictureFrame(const ByteVector &data, Header *h) : Frame(h)
+{
+  d = new AttachedPictureFramePrivate;
+  parseFields(data.mid(Header::size(h->version()), size()));
+}
diff --git a/mpeg/id3v2/frames/attachedpictureframe.h b/mpeg/id3v2/frames/attachedpictureframe.h
new file mode 100644 (file)
index 0000000..896f002
--- /dev/null
@@ -0,0 +1,195 @@
+/***************************************************************************
+    copyright            : (C) 2004 by Scott Wheeler
+    email                : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ *   This library is free software; you can redistribute it and/or modify  *
+ *   it  under the terms of the GNU Lesser General Public License version  *
+ *   2.1 as published by the Free Software Foundation.                     *
+ *                                                                         *
+ *   This library is distributed in the hope that it will be useful, but   *
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
+ *   Lesser General Public License for more details.                       *
+ *                                                                         *
+ *   You should have received a copy of the GNU Lesser General Public      *
+ *   License along with this library; if not, write to the Free Software   *
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
+ *   USA                                                                   *
+ ***************************************************************************/
+
+#ifndef TAGLIB_ATTACHEDPICTUREFRAME_H
+#define TAGLIB_ATTACHEDPICTUREFRAME_H
+
+#include <id3v2frame.h>
+#include <id3v2header.h>
+
+namespace TagLib {
+
+  namespace ID3v2 {
+
+    //! An ID3v2 attached picture frame implementation
+
+    /*!
+     * This is an implementation of ID3v2 attached pictures.  Pictures may be
+     * included in tags, one per APIC frame (but there may be multiple APIC
+     * frames in a single tag).  These pictures are usually in either JPEG or
+     * PNG format.
+     */
+
+    class AttachedPictureFrame : public Frame
+    {
+      friend class FrameFactory;
+
+    public:
+
+      /*!
+       * This describes the function or content of the picture.
+       */
+      enum Type {
+        //! A type not enumerated below
+        Other              = 0x00,
+        //! 32x32 PNG image that should be used as the file icon
+        FileIcon           = 0x01,
+        //! File icon of a different size or format
+        OtherFileIcon      = 0x02,
+        //! Front cover image of the album
+        FrontCover         = 0x03,
+        //! Back cover image of the album
+        BackCover          = 0x04,
+        //! Inside leaflet page of the album
+        LeafletPage        = 0x05,
+        //! Image from the album itself
+        Media              = 0x06,
+        //! Picture of the lead artist or soloist
+        LeadArtist         = 0x07,
+        //! Picture of the artist or performer
+        Artist             = 0x08,
+        //! Picture of the conductor
+        Conductor          = 0x09,
+        //! Picture of the band or orchestra
+        Band               = 0x0A,
+        //! Picture of the composer
+        Composer           = 0x0B,
+        //! Picture of the lyricist or text writer
+        Lyricist           = 0x0C,
+        //! Picture of the recording location or studio
+        RecordingLocation  = 0x0D,
+        //! Picture of the artists during recording
+        DuringRecording    = 0x0E,
+        //! Picture of the artists during performance
+        DuringPerformance  = 0x0F,
+        //! Picture from a movie or video related to the track
+        MovieScreenCapture = 0x10,
+        //! Picture of a large, coloured fish
+        ColouredFish       = 0x11,
+        //! Illustration related to the track
+        Illustration       = 0x12,
+        //! Logo of the band or performer
+        BandLogo           = 0x13,
+        //! Logo of the publisher (record company)
+        PublisherLogo      = 0x14
+      };
+
+      /*!
+       * Constructs an empty picture frame.  The description, content and text
+       * encoding should be set manually.
+       */
+      AttachedPictureFrame();
+
+      /*!
+       * Constructs an AttachedPicture frame based on \a data.
+       */
+      explicit AttachedPictureFrame(const ByteVector &data);
+
+      /*!
+       * Destroys the AttahcedPictureFrame instance.
+       */
+      virtual ~AttachedPictureFrame();
+
+      /*!
+       * Returns a string containing the description and mime-type
+       */
+      virtual String toString() const;
+
+      /*!
+       * Returns the text encoding used for the description.
+       *
+       * \see setTextEncoding()
+       * \see description()
+       */
+      String::Type textEncoding() const;
+
+      /*!
+       * Set the text encoding used for the description.
+       *
+       * \see description()
+       */
+      void setTextEncoding(String::Type t);
+
+      /*!
+       * Returns the mime type of the image.  This should in most cases be
+       * "image/png" or "image/jpeg".
+       */
+      String mimeType() const;
+
+      /*!
+       * Sets the mime type of the image.  This should in most cases be
+       * "image/png" or "image/jpeg".
+       */
+      void setMimeType(const String &m);
+
+      /*!
+       * Returns the type of the image.
+       *
+       * \see Type
+       * \see setType()
+       */
+      Type type() const;
+
+      /*!
+       * Sets the type for the image.
+       *
+       * \see Type
+       * \see type()
+       */
+      void setType(Type t);
+
+      /*!
+       * Returns the image data as a ByteVector.
+       *
+       * \note ByteVector has a data() method that returns a const char * which
+       * should make it easy to export this data to external programs.
+       *
+       * \see setPicture()
+       * \see mimeType()
+       */
+      ByteVector picture() const;
+
+      /*!
+       * Sets the image data to \a p.  \a p should be of the type specified in
+       * this frame's mime-type specification.
+       *
+       * \see picture()
+       * \see mimeType()
+       * \see setMimeType()
+       */
+      void setPicture(const ByteVector &p);
+
+    protected:
+      virtual void parseFields(const ByteVector &data);
+      virtual ByteVector renderFields() const;
+
+    private:
+      AttachedPictureFrame(const ByteVector &data, Header *h);
+      AttachedPictureFrame(const AttachedPictureFrame &);
+      AttachedPictureFrame &operator=(const AttachedPictureFrame &);
+
+      class AttachedPictureFramePrivate;
+      AttachedPictureFramePrivate *d;
+    };
+  }
+}
+
+#endif
index 23ab78a37a59895086ad305484929d4837c67853..d550b29f24aa57c16ce59b62a2d1057a16be4978 100644 (file)
@@ -26,6 +26,7 @@
 #include "frames/unknownframe.h"
 #include "frames/textidentificationframe.h"
 #include "frames/commentsframe.h"
+#include "frames/attachedpictureframe.h"
 
 using namespace TagLib;
 using namespace ID3v2;
@@ -108,6 +109,15 @@ Frame *FrameFactory::createFrame(const ByteVector &data, uint version) const
     return f;
   }
 
+  // Attached Picture (frames 4.14)
+
+  if(frameID == "APIC") {
+    AttachedPictureFrame *f = new AttachedPictureFrame(data, header);
+    if(d->useDefaultEncoding)
+      f->setTextEncoding(d->defaultEncoding);
+    return f;
+  }
+
   return new UnknownFrame(data, header);
 }