本文整理汇总了C++中taglib::id3v2::AttachedPictureFrame类的典型用法代码示例。如果您正苦于以下问题:C++ AttachedPictureFrame类的具体用法?C++ AttachedPictureFrame怎么用?C++ AttachedPictureFrame使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AttachedPictureFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: malloc
/* GET ALBUM COVER
*/
const char * tag_data_get_cover (TagDatac * data, uint * len)
{
TagLib::ID3v2::AttachedPictureFrame * pic = NULL;
if (!(reinterpret_cast<TagData *>(data))->id3v2 || (reinterpret_cast<TagData *>(data))->id3v2->frameListMap()["APIC"].isEmpty())
{
*len = 0;
return NULL;
}
TagLib::ID3v2::FrameList::ConstIterator it;
TagLib::ID3v2::FrameList l = (reinterpret_cast<TagData *>(data))->id3v2->frameListMap()["APIC"];
for(it=l.begin(); it!=l.end(); ++it)
{
TagLib::ID3v2::AttachedPictureFrame * t = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(*it);
if (pic == NULL)
pic = t;
if (t->type () == TagLib::ID3v2::AttachedPictureFrame::FrontCover)
{
pic = t;
break;
}
}
if (pic == NULL)
{
*len = 0;
return NULL;
}
*len = pic->picture ().size ();
const char * out = (const char *) malloc (*len);
memcpy ((void *) out, pic->picture ().data(), *len);
return out;
}
示例2: exportPictures
bool MetaDSF::exportPictures(const char *prefix) const
{
std::map<std::string, unsigned int> counter;
TagLib::ID3v2::FrameList l = _i->_file.ID3v2Tag()->frameList("APIC");
TagLib::ID3v2::FrameList::ConstIterator it;
for (it = l.begin(); it != l.end(); ++it) {
TagLib::ID3v2::AttachedPictureFrame *f =
static_cast<TagLib::ID3v2::AttachedPictureFrame *>(*it);
std::string fname = prefix;
std::string tname = picTypeDesc[f->type()].toCString();
std::string ext = MIMETypeToExtMap[f->mimeType()].toCString();
if (counter.find(tname) == counter.end())
counter[tname] = 1;
else
counter[tname] += 1;
fname += "_";
fname += tname;
fname += "_";
fname += std::to_string(counter[tname]);
fname += ".";
fname += ext;
//std::cout << "fname = " << fname << std::endl;
writeFileFromVector(fname.c_str(), f->picture());
}
return true;
}
示例3: attachPicture
bool MetaDSF::attachPicture(const TagLib::String &path,
const TagLib::String &ptype)
{
// Determine MIME type
TagLib::String mimeType;
TagLib::String ext = path.substr(path.rfind(".") + 1);
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
if (extToMIMETypeMap.find(ext) == extToMIMETypeMap.end()) {
std::cerr << "Unknown image format " << ext << std::endl;
return false;
}
mimeType = extToMIMETypeMap[ext];
// Load file into memory
TagLib::ByteVector v;
if (loadFileIntoVector(path.toCString(), v) <= 0) {
return false;
}
std::string pt = ptype.toCString();
TagLib::ID3v2::AttachedPictureFrame *apic =
new TagLib::ID3v2::AttachedPictureFrame();
TagLib::ID3v2::AttachedPictureFrame::Type t =
static_cast<TagLib::ID3v2::AttachedPictureFrame::Type>(std::stoi(pt, 0, 16));
apic->setPicture(v);
apic->setMimeType(mimeType);
apic->setType(t);
_i->_file.ID3v2Tag()->addFrame(apic);
_i->_changed = true;
return true;
}
示例4: fileref
Tag::Tag(const QString &filename)
: m_filename(filename)
{
TagLib::MPEG::File mpegfile(filename.toLocal8Bit().constData());
TagLib::ID3v2::Tag* id3v2 = mpegfile.ID3v2Tag();
if (id3v2 && !id3v2->isEmpty()) {
readRegularTag(id3v2, m_data);
int picnum = 0;
TagLib::ID3v2::FrameList frames = id3v2->frameListMap()["APIC"]; // attached picture
TagLib::ID3v2::FrameList::ConstIterator it = frames.begin();
while (it != frames.end()) {
TagLib::ID3v2::AttachedPictureFrame* apic = static_cast<TagLib::ID3v2::AttachedPictureFrame*>(*it);
TagLib::ByteVector bytes = apic->picture();
QImage img = QImage::fromData(reinterpret_cast<const uchar*>(bytes.data()), bytes.size());
if (!img.isNull()) {
m_data[QLatin1String("picture") + QString::number(picnum++)] = QVariant(img);
}
++it;
}
} else {
TagLib::FileRef fileref(filename.toLocal8Bit().constData());
if (fileref.isNull())
return;
TagLib::Tag* tag = fileref.tag();
if (!tag || tag->isEmpty())
return;
readRegularTag(tag, m_data);
}
}
示例5: exportImage
bool CTagBase::exportImage(const wchar_t* s)
{
if (!s) return false;
if (_tagFile)
{
//get picture
TagLib::MPEG::File *f = (TagLib::MPEG::File *)_tagFile.get();
if (!f->hasID3v2Tag() || f->ID3v2Tag()->isEmpty())
return false;
/*
TagLib::ID3v2::FrameList::ConstIterator it = f->ID3v2Tag()->frameList().begin();
for (; it != f->ID3v2Tag()->frameList().end(); it++)
{
if ((*it)->frameID().operator == (TagLib::ByteVector("APIC")))
{
HANDLE hFile = CreateFile(s, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hFile)
return false;
int nWriteBytes = 0;
size_t size = (*it)->size();
::WriteFile(hFile, (*it)->render().data(), (*it)->size(), (LPDWORD)&nWriteBytes, NULL);
::CloseHandle(hFile);
if (nWriteBytes != size)
return false;
return true;
}
}*/
if (f->ID3v2Tag()->frameListMap().size() == 0)
return false;
if (f->ID3v2Tag()->frameListMap().find("APIC") == f->ID3v2Tag()->frameListMap().end())
return false;
TagLib::ID3v2::FrameList Flist = f->ID3v2Tag()->frameListMap()["APIC"];
if (Flist.isEmpty())
return false;
TagLib::ID3v2::AttachedPictureFrame *p = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(Flist.front());
size_t size = p->picture().size();
CString strPicType = p->mimeType().toCString(true);
int nPos = strPicType.Find('/');
CString strTemp = strPicType.Right(strPicType.GetLength() - nPos - 1);
//CString strPicPath = s;
//if (strTemp == _T("png"))
// strPicPath.Append(_T(".png"));
//else
// strPicPath.Append(_T(".jpg"));
HANDLE hFile = CreateFile(s, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hFile)
return false;
int nWriteBytes = 0;
::WriteFile(hFile, p->picture().data(), size, (LPDWORD)&nWriteBytes, NULL);
::CloseHandle(hFile);
if (nWriteBytes != size)
return false;
return true;
}
return false;
}
示例6: WriteCover
/*
** Extracts cover art embedded in ID3v2 tags.
**
*/
bool CCover::ExtractID3(TagLib::ID3v2::Tag* tag, const std::wstring& target)
{
const TagLib::ID3v2::FrameList& frameList = tag->frameList("APIC");
if (!frameList.isEmpty())
{
// Grab the first image
TagLib::ID3v2::AttachedPictureFrame* frame = static_cast<TagLib::ID3v2::AttachedPictureFrame*>(frameList.front());
return WriteCover(frame->picture(), target);
}
return false;
}
示例7:
/*
** Extracts cover art embedded in ID3v2 tags.
**
*/
bool QCoverArt::ExtractID3(TagLib::ID3v2::Tag* tag)
{
const TagLib::ID3v2::FrameList& frameList = tag->frameList("APIC");
if (!frameList.isEmpty())
{
// Grab the first image
TagLib::ID3v2::AttachedPictureFrame* frame = static_cast<TagLib::ID3v2::AttachedPictureFrame*>(frameList.front());
img.loadFromData((const unsigned char*)frame->picture().data(), (int)frame->picture().size());
return true;
}
return false;
}
示例8: addImage
bool CTagBase::addImage(wchar_t* s)
{
if (!_tagFile) return false;
TagLib::MPEG::File *pAudioFile = (TagLib::MPEG::File *)_tagFile.get();
CString strFileName = s;
ImageFile imageFile((CW2A)strFileName.GetBuffer());
if (!pAudioFile->isValid() || !imageFile.isValid())
return false;
TagLib::ID3v2::Tag *tag = pAudioFile->ID3v2Tag(true);
TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
frame->setMimeType(imageFile.mimeType());
frame->setPicture(imageFile.data());
tag->addFrame(frame);
return pAudioFile->save();
}
示例9: if
QImage
ID3v2TagHelper::embeddedCover() const
{
TagLib::ID3v2::FrameList apicList = m_tag->frameListMap()[fieldName( Meta::valHasCover ).toCString()];
TagLib::ID3v2::AttachedPictureFrame *cover = NULL;
TagLib::ID3v2::AttachedPictureFrame *otherCover = NULL;
for( TagLib::ID3v2::FrameList::ConstIterator it = apicList.begin(); it != apicList.end(); ++it )
{
TagLib::ID3v2::AttachedPictureFrame *currFrame =
dynamic_cast< TagLib::ID3v2::AttachedPictureFrame * >( *it );
if( currFrame->picture().size() < MIN_COVER_SIZE )
continue;
if( currFrame->type() == TagLib::ID3v2::AttachedPictureFrame::FrontCover )
{
cover = currFrame;
}
else if( currFrame->type() == TagLib::ID3v2::AttachedPictureFrame::Other )
{
otherCover = currFrame;
}
}
if( !cover && otherCover )
cover = otherCover;
if( !cover )
return QImage();
return QImage::fromData( ( uchar * )( cover->picture().data() ), cover->picture().size() );
}
示例10: coverFromMPEGTags
bool CoverUtils::coverFromMPEGTags(TagLib::ID3v2::Tag *tag, Album *album) {
if (!tag) return false;
TagLib::ID3v2::FrameList list = tag->frameList("APIC");
if (list.isEmpty()) return false;
TagLib::ID3v2::AttachedPictureFrame *frame =
static_cast<TagLib::ID3v2::AttachedPictureFrame *>(list.front());
if (!frame) return false;
const int frameSize = frame->picture().size();
if (frameSize <= 0) return false;
QImage image;
image.loadFromData((const uchar *) frame->picture().data(), frame->picture().size());
if (!isAcceptableImage(image)) return false;
return saveImage(image, album);
}
示例11:
bool
ID3v2TagHelper::hasEmbeddedCover() const
{
TagLib::ID3v2::FrameList apicList = m_tag->frameListMap()[fieldName( Meta::valHasCover ).toCString()];
for( TagLib::ID3v2::FrameList::ConstIterator it = apicList.begin(); it != apicList.end(); ++it )
{
TagLib::ID3v2::AttachedPictureFrame *currFrame =
dynamic_cast< TagLib::ID3v2::AttachedPictureFrame * >( *it );
if( currFrame->picture().size() < MIN_COVER_SIZE )
continue;
if( currFrame->type() == TagLib::ID3v2::AttachedPictureFrame::FrontCover ||
currFrame->type() == TagLib::ID3v2::AttachedPictureFrame::Other )
return true;
}
return false;
}
示例12: buffer
bool
ID3v2TagHelper::setEmbeddedCover( const QImage &cover )
{
QByteArray bytes;
QBuffer buffer( &bytes );
buffer.open( QIODevice::WriteOnly );
if( !cover.save( &buffer, "JPEG" ) )
{
buffer.close();
return false;
}
buffer.close();
TagLib::ByteVector field = fieldName( Meta::valHasCover ).toCString();
TagLib::ID3v2::FrameList apicList = m_tag->frameListMap()[field];
TagLib::ID3v2::AttachedPictureFrame *frontCover = NULL;
// remove covers
TagLib::List<TagLib::ID3v2::AttachedPictureFrame*> backedUpPictures;
for( TagLib::ID3v2::FrameList::ConstIterator it = apicList.begin(); it != apicList.end(); ++it )
{
TagLib::ID3v2::AttachedPictureFrame *currFrame =
dynamic_cast< TagLib::ID3v2::AttachedPictureFrame * >( *it );
m_tag->removeFrame( currFrame, false );
}
// add new cover
frontCover = new TagLib::ID3v2::AttachedPictureFrame( field );
frontCover->setMimeType( "image/jpeg" );
frontCover->setPicture( TagLib::ByteVector( bytes.data(), bytes.count() ) );
frontCover->setType( TagLib::ID3v2::AttachedPictureFrame::FrontCover );
m_tag->addFrame( frontCover );
return true;
}
示例13: deletePictures
int MetaDSF::deletePictures(const TagLib::String &ptype)
{
TagLib::ID3v2::FrameList l = _i->_file.ID3v2Tag()->frameList("APIC");
TagLib::ID3v2::FrameList dl; // a list of frames to be deleted
TagLib::ID3v2::FrameList::ConstIterator it;
std::string pt = ptype.toCString();
// retrieve a list of frames that matches the given type
for (it = l.begin(); it != l.end(); it++) {
TagLib::ID3v2::AttachedPictureFrame *f =
static_cast<TagLib::ID3v2::AttachedPictureFrame *>(*it);
TagLib::ID3v2::AttachedPictureFrame::Type t =
static_cast<TagLib::ID3v2::AttachedPictureFrame::Type>(std::stoi(pt,
0, 16));
if (f->type() == t) {
dl.append(f);
}
}
_i->deleteFrames(dl);
_i->_changed = true;
return dl.size();
}
示例14: saveFile
void saveFile(string stdPath, DataEditors* editors) {
const char* charPath = stdPath.c_str();
ifstream fileCheck(charPath);
if(!fileCheck.good()) {
QWidget *w = new QWidget();
QLabel *l = new QLabel("Invalid file!", w);
QPushButton *b = new QPushButton("OK", w);
QVBoxLayout *lay = new QVBoxLayout();
lay->addWidget(l);
lay->addWidget(b);
w->setLayout(lay);
QWidget::connect(b, SIGNAL(clicked()), w, SLOT(close()));
w->show();
return;
}
TagLib::FileName name = charPath;
TagLib::FileRef file(name);
if(editors->artist->isEnabled())
file.tag()->setArtist(editors->artist->text().toStdString());
if(editors->album->isEnabled())
file.tag()->setAlbum(editors->album->text().toStdString());
if(editors->track->isEnabled())
file.tag()->setTrack(editors->track->text().toInt());
if(editors->title->isEnabled())
file.tag()->setTitle(editors->title->text().toStdString());
if(editors->year->isEnabled())
file.tag()->setYear(editors->year->text().toInt());
if(editors->genre->isEnabled())
file.tag()->setGenre(editors->genre->currentText().toStdString());
if(editors->comment->isEnabled())
file.tag()->setComment(editors->comment->toPlainText().toStdString());
file.save();
if(editors->picture->isEnabled()) {
TagLib::MPEG::File mpegFile(name);
TagLib::ID3v2::Tag *tag = mpegFile.ID3v2Tag(true);
TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
QString picture = editors->picture->text();
if(picture == "<Attached picture>") {
TagLib::ID3v2::AttachedPictureFrame *f =
static_cast<TagLib::ID3v2::AttachedPictureFrame *>(editors->mpegFile->ID3v2Tag(true)->frameList("APIC").front());
frame->setMimeType(f->mimeType());
frame->setPicture(f->picture());
tag->removeFrames("APIC");
tag->addFrame(frame);
mpegFile.save();
} else if(picture == "") {
tag->removeFrames("APIC");
mpegFile.save();
} else {
frame->setMimeType("image/jpeg");
string stdPic = picture.toStdString();
const char* charPicture = stdPic.c_str();
ifstream fileCheck(charPicture);
if(!fileCheck.good()) {
QWidget *w = new QWidget();
QLabel *l = new QLabel("Invalid picture!", w);
QPushButton *b = new QPushButton("OK", w);
QVBoxLayout *lay = new QVBoxLayout();
lay->addWidget(l);
lay->addWidget(b);
w->setLayout(lay);
QWidget::connect(b, SIGNAL(clicked()), w, SLOT(close()));
w->show();
delete w;
return;
}
ImageFile imageTagLibFile(charPicture);
frame->setPicture(imageTagLibFile.data());
tag->removeFrames("APIC");
tag->addFrame(frame);
mpegFile.save();
}
}
}
示例15: if
//.........这里部分代码省略.........
// Preference is TXXX frames, RVA2 frame, then LAME header
auto trackGainFrame = TagLib::ID3v2::UserTextIdentificationFrame::find(const_cast<TagLib::ID3v2::Tag *>(tag), "REPLAYGAIN_TRACK_GAIN");
auto trackPeakFrame = TagLib::ID3v2::UserTextIdentificationFrame::find(const_cast<TagLib::ID3v2::Tag *>(tag), "REPLAYGAIN_TRACK_PEAK");
auto albumGainFrame = TagLib::ID3v2::UserTextIdentificationFrame::find(const_cast<TagLib::ID3v2::Tag *>(tag), "REPLAYGAIN_ALBUM_GAIN");
auto albumPeakFrame = TagLib::ID3v2::UserTextIdentificationFrame::find(const_cast<TagLib::ID3v2::Tag *>(tag), "REPLAYGAIN_ALBUM_PEAK");
if(!trackGainFrame)
trackGainFrame = TagLib::ID3v2::UserTextIdentificationFrame::find(const_cast<TagLib::ID3v2::Tag *>(tag), "replaygain_track_gain");
if(trackGainFrame) {
SFB::CFString str(trackGainFrame->fieldList().back().toCString(true), kCFStringEncodingUTF8);
double num = CFStringGetDoubleValue(str);
AddDoubleToDictionary(dictionary, Metadata::kTrackGainKey, num);
AddDoubleToDictionary(dictionary, Metadata::kReferenceLoudnessKey, 89.0);
foundReplayGain = true;
}
if(!trackPeakFrame)
trackPeakFrame = TagLib::ID3v2::UserTextIdentificationFrame::find(const_cast<TagLib::ID3v2::Tag *>(tag), "replaygain_track_peak");
if(trackPeakFrame) {
SFB::CFString str(trackPeakFrame->fieldList().back().toCString(true), kCFStringEncodingUTF8);
double num = CFStringGetDoubleValue(str);
AddDoubleToDictionary(dictionary, Metadata::kTrackPeakKey, num);
}
if(!albumGainFrame)
albumGainFrame = TagLib::ID3v2::UserTextIdentificationFrame::find(const_cast<TagLib::ID3v2::Tag *>(tag), "replaygain_album_gain");
if(albumGainFrame) {
SFB::CFString str(albumGainFrame->fieldList().back().toCString(true), kCFStringEncodingUTF8);
double num = CFStringGetDoubleValue(str);
AddDoubleToDictionary(dictionary, Metadata::kAlbumGainKey, num);
AddDoubleToDictionary(dictionary, Metadata::kReferenceLoudnessKey, 89.0);
foundReplayGain = true;
}
if(!albumPeakFrame)
albumPeakFrame = TagLib::ID3v2::UserTextIdentificationFrame::find(const_cast<TagLib::ID3v2::Tag *>(tag), "replaygain_album_peak");
if(albumPeakFrame) {
SFB::CFString str(albumPeakFrame->fieldList().back().toCString(true), kCFStringEncodingUTF8);
double num = CFStringGetDoubleValue(str);
AddDoubleToDictionary(dictionary, Metadata::kAlbumPeakKey, num);
}
// If nothing found check for RVA2 frame
if(!foundReplayGain) {
frameList = tag->frameListMap()["RVA2"];
for(auto frameIterator : tag->frameListMap()["RVA2"]) {
TagLib::ID3v2::RelativeVolumeFrame *relativeVolume = dynamic_cast<TagLib::ID3v2::RelativeVolumeFrame *>(frameIterator);
if(!relativeVolume)
continue;
// Attempt to use the master volume if present
auto channels = relativeVolume->channels();
auto channelType = TagLib::ID3v2::RelativeVolumeFrame::MasterVolume;
// Fall back on whatever else exists in the frame
if(!channels.contains(TagLib::ID3v2::RelativeVolumeFrame::MasterVolume))
channelType = channels.front();
float volumeAdjustment = relativeVolume->volumeAdjustment(channelType);
if(TagLib::String("track", TagLib::String::Latin1) == relativeVolume->identification()) {
if((int)volumeAdjustment)
AddFloatToDictionary(dictionary, Metadata::kTrackGainKey, volumeAdjustment);
}
else if(TagLib::String("album", TagLib::String::Latin1) == relativeVolume->identification()) {
if((int)volumeAdjustment)
AddFloatToDictionary(dictionary, Metadata::kAlbumGainKey, volumeAdjustment);
}
// Fall back to track gain if identification is not specified
else {
if((int)volumeAdjustment)
AddFloatToDictionary(dictionary, Metadata::kTrackGainKey, volumeAdjustment);
}
}
}
// Extract album art if present
for(auto it : tag->frameListMap()["APIC"]) {
TagLib::ID3v2::AttachedPictureFrame *frame = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame *>(it);
if(frame) {
SFB::CFData data((const UInt8 *)frame->picture().data(), (CFIndex)frame->picture().size());
SFB::CFString description;
if(!frame->description().isEmpty())
description = CFString(frame->description().toCString(true), kCFStringEncodingUTF8);
attachedPictures.push_back(std::make_shared<AttachedPicture>(data, (AttachedPicture::Type)frame->type(), description));
}
}
return true;
}