aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Soll <[email protected]>2015-07-05 11:33:47 +0200
committerAlbert Astals Cid <[email protected]>2015-07-05 11:33:47 +0200
commitd645eec297a5fb3e9968c6dfded933ebb35d442c (patch)
treec0c8df02393355cceb6db5bff3f49dc359c4ca20
parentccf4f365c92dd641e56cfeb3db8a3c27c17da5f4 (diff)
Add FLAC cover extraction
-rw-r--r--coverinfo.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/coverinfo.cpp b/coverinfo.cpp
index 01c1cb0..a6bb4b7 100644
--- a/coverinfo.cpp
+++ b/coverinfo.cpp
@@ -39,6 +39,7 @@
#include <taglib/tstring.h>
#include <taglib/id3v2tag.h>
#include <taglib/attachedpictureframe.h>
+#include <taglib/flacfile.h>
#ifdef TAGLIB_WITH_MP4
#include <taglib/mp4coverart.h>
@@ -290,6 +291,13 @@ bool CoverInfo::hasEmbeddedAlbumArt() const
TagLib::ID3v2::FrameList frames = id3tag->frameListMap()["APIC"];
return !frames.isEmpty();
}
+ else if (TagLib::FLAC::File *flacFile =
+ dynamic_cast<TagLib::FLAC::File *>(fileTag.data()))
+ {
+
+ // Look if images are embedded.
+ return !flacFile->pictureList().isEmpty();
+ }
#ifdef TAGLIB_WITH_MP4
else if(TagLib::MP4::File *mp4File =
dynamic_cast<TagLib::MP4::File *>(fileTag.data()))
@@ -357,6 +365,29 @@ static QImage embeddedMPEGAlbumArt(TagLib::ID3v2::Tag *id3tag)
picture.size());
}
+static QImage embeddedFLACAlbumArt(TagLib::FLAC::File *flacFile)
+{
+ TagLib::List<TagLib::FLAC::Picture *> flacPictures = flacFile->pictureList();
+ if(flacPictures.isEmpty()) {
+
+ // No pictures are embedded.
+ return QImage();
+ }
+
+ // Always use first picture - even if multiple are embedded.
+ TagLib::ByteVector coverData = flacPictures[0]->data();
+ QImage result = QImage::fromData(
+ reinterpret_cast<const uchar *>(coverData.data()),
+ coverData.size());
+
+ if(!result.isNull()) {
+ return result;
+ }
+
+ // Error while casting image.
+ return QImage();
+}
+
#ifdef TAGLIB_WITH_MP4
static QImage embeddedMP4AlbumArt(TagLib::MP4::Tag *tag)
{
@@ -426,6 +457,11 @@ QImage CoverInfo::embeddedAlbumArt() const
TagLib::ID3v2::Tag *id3tag = mpegFile->ID3v2Tag(false);
return embeddedMPEGAlbumArt(id3tag);
}
+ else if (TagLib::FLAC::File *flacFile =
+ dynamic_cast<TagLib::FLAC::File *>(fileTag.data()))
+ {
+ return embeddedFLACAlbumArt(flacFile);
+ }
#ifdef TAGLIB_WITH_MP4
else if(TagLib::MP4::File *mp4File =
dynamic_cast<TagLib::MP4::File *>(fileTag.data()))