From 2b81921d36a167c3e9530c3c9d1a8cbd132b10e7 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Fri, 1 Jan 2010 19:10:10 +0000 Subject: 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 --- src/plugins/Input/vorbis/vorbismetadatamodel.cpp | 49 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/plugins/Input/vorbis/vorbismetadatamodel.cpp') 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 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()); -- cgit v1.2.3-13-gbd6f