diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index fce8e057..3e553a93 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -22,7 +22,7 @@ * License Version 1.1. You may obtain a copy of the License at * * http://www.mozilla.org/MPL/ * ***************************************************************************/ - +#include #include #include #include @@ -724,7 +724,39 @@ MP4::Tag::track() const PictureMap MP4::Tag::pictures() const { + if(!d->items.contains("covr")) return PictureMap(); + + CoverArtList list = d->items["covr"].toCoverArtList(); + if( list.isEmpty() ) + return PictureMap(); + + PictureMap map; + for(CoverArtList::ConstIterator it = list.begin(); it != list.end(); ++it) + { + CoverArt art = *it; + String mime = "image/"; + switch(art.format()) + { + case CoverArt::BMP: + mime.append("bmp"); + break; + case CoverArt::JPEG: + mime.append("jpeg"); + break; + case CoverArt::GIF: + mime.append("gif"); + break; + case CoverArt::PNG: + mime.append("png"); + break; + case CoverArt::Unknown: + break; + } + Picture picture(art.data(), Picture::Other, mime); + map.insert(picture); + } + return PictureMap(map); } void @@ -772,6 +804,48 @@ MP4::Tag::setTrack(uint value) void MP4::Tag::setPictures(const PictureMap &l) { + CoverArtList list; + for(PictureMap::ConstIterator pictureMapIt = l.begin(); + pictureMapIt != l.end(); + ++pictureMapIt) + { + PictureList pictures = pictureMapIt->second; + for(PictureList::ConstIterator pictureListIt = pictures.begin(); + pictureListIt != pictures.end(); + ++pictureListIt) + { + Picture picture = *pictureListIt; + CoverArt::Format format; + const char* mime = picture.mime().toCString(); + if(std::strcmp("image/", mime) == 0) + { + format = CoverArt::Unknown; + } + else if(std::strcmp("image/bmp", mime) == 0) + { + format = CoverArt::BMP; + } + else if(std::strcmp("image/png", mime) == 0) + { + format = CoverArt::PNG; + } + else if(std::strcmp("image/gif", mime) == 0) + { + format = CoverArt::GIF; + } + else if(std::strcmp("image/jpeg", mime) == 0) + { + format = CoverArt::JPEG; + } + else + { + format = CoverArt::Unknown; + } + CoverArt art(format, picture.data()); + list.append(art); + } + } + d->items["covr"] = list; } bool MP4::Tag::isEmpty() const