diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-01-01 19:10:10 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-01-01 19:10:10 +0000 |
| commit | 2b81921d36a167c3e9530c3c9d1a8cbd132b10e7 (patch) | |
| tree | 5bf99807b31184e04b302ba6e9965fa77d529b34 /src/plugins/Input/vorbis/vorbismetadatamodel.cpp | |
| parent | 6488626dfad8e8f14a6a842eedd8315b2d28f0a9 (diff) | |
| download | qmmp-2b81921d36a167c3e9530c3c9d1a8cbd132b10e7.tar.gz qmmp-2b81921d36a167c3e9530c3c9d1a8cbd132b10e7.tar.bz2 qmmp-2b81921d36a167c3e9530c3c9d1a8cbd132b10e7.zip | |
vorbis plugin: added support for METADATA_BLOCK_PICTURE (Closes issue 221)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1463 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Input/vorbis/vorbismetadatamodel.cpp')
| -rw-r--r-- | src/plugins/Input/vorbis/vorbismetadatamodel.cpp | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/plugins/Input/vorbis/vorbismetadatamodel.cpp b/src/plugins/Input/vorbis/vorbismetadatamodel.cpp index f7ea3f32d..0ef036402 100644 --- a/src/plugins/Input/vorbis/vorbismetadatamodel.cpp +++ b/src/plugins/Input/vorbis/vorbismetadatamodel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Ilya Kotov * + * Copyright (C) 2009-2010 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -59,6 +59,53 @@ QList<TagModel* > VorbisMetaDataModel::tags() return m_tags; } +QPixmap VorbisMetaDataModel::cover() +{ + TagLib::Ogg::Vorbis::File file(m_path.toLocal8Bit().constData()); + TagLib::Ogg::XiphComment *tag = file.tag(); + if(!tag) + return QPixmap(); + TagLib::StringList list = tag->fieldListMap()["METADATA_BLOCK_PICTURE"]; + if(list.isEmpty()) + return QPixmap(); + for(uint i = 0; i < list.size(); ++i) + { + TagLib::String value = list[i]; + QByteArray block = QByteArray::fromBase64(TStringToQString_qt4(value).toAscii()); + if(block.size() < 32) + continue; + qint64 pos = 0; + if(readPictureBlockField(block, pos) != 3) //picture type, use front cover only + continue; + pos += 4; + int mimeLength = readPictureBlockField(block, pos); //mime type length + pos += 4; + pos += mimeLength; //skip mime type + int descLength = readPictureBlockField(block, pos); //description length + pos += 4; + pos += descLength; //skip description + pos += 4; //width + pos += 4; //height + pos += 4; //color depth + pos += 4; //the number of colors used + int length = readPictureBlockField(block, pos); //picture size + pos += 4; + QPixmap cover; + cover.loadFromData(block.mid(pos, length)); //read binary picture data + return cover; + } + return QPixmap(); +} + +ulong VorbisMetaDataModel::readPictureBlockField(QByteArray data, int offset) +{ + return (((uchar)data.data()[offset] & 0xff) << 24) | + (((uchar)data.data()[offset+1] & 0xff) << 16) | + (((uchar)data.data()[offset+2] & 0xff) << 16) | + ((uchar)data.data()[offset+3] & 0xff); + +} + VorbisCommentModel::VorbisCommentModel(const QString &path) : TagModel(TagModel::Save) { m_file = new TagLib::Ogg::Vorbis::File (path.toLocal8Bit().constData()); |
