void testAddPicture() { ScopedFileCopy copy("silence-44-s", ".flac"); string newname = copy.fileName(); { FLAC::File f(newname.c_str()); List<FLAC::Picture *> lst = f.pictureList(); CPPUNIT_ASSERT_EQUAL((unsigned int)1, lst.size()); FLAC::Picture *newpic = new FLAC::Picture(); newpic->setType(FLAC::Picture::BackCover); newpic->setWidth(5); newpic->setHeight(6); newpic->setColorDepth(16); newpic->setNumColors(7); newpic->setMimeType("image/jpeg"); newpic->setDescription("new image"); newpic->setData("JPEG data"); f.addPicture(newpic); f.save(); } { FLAC::File f(newname.c_str()); List<FLAC::Picture *> lst = f.pictureList(); CPPUNIT_ASSERT_EQUAL((unsigned int)2, lst.size()); FLAC::Picture *pic = lst[0]; CPPUNIT_ASSERT_EQUAL(FLAC::Picture::FrontCover, pic->type()); CPPUNIT_ASSERT_EQUAL(1, pic->width()); CPPUNIT_ASSERT_EQUAL(1, pic->height()); CPPUNIT_ASSERT_EQUAL(24, pic->colorDepth()); CPPUNIT_ASSERT_EQUAL(0, pic->numColors()); CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType()); CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description()); CPPUNIT_ASSERT_EQUAL((unsigned int)150, pic->data().size()); pic = lst[1]; CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type()); CPPUNIT_ASSERT_EQUAL(5, pic->width()); CPPUNIT_ASSERT_EQUAL(6, pic->height()); CPPUNIT_ASSERT_EQUAL(16, pic->colorDepth()); CPPUNIT_ASSERT_EQUAL(7, pic->numColors()); CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), pic->mimeType()); CPPUNIT_ASSERT_EQUAL(String("new image"), pic->description()); CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), pic->data()); } }
void testReadPicture() { ScopedFileCopy copy("silence-44-s", ".flac"); string newname = copy.fileName(); FLAC::File f(newname.c_str()); List<FLAC::Picture *> lst = f.pictureList(); CPPUNIT_ASSERT_EQUAL((unsigned int)1, lst.size()); FLAC::Picture *pic = lst.front(); CPPUNIT_ASSERT_EQUAL(FLAC::Picture::FrontCover, pic->type()); CPPUNIT_ASSERT_EQUAL(1, pic->width()); CPPUNIT_ASSERT_EQUAL(1, pic->height()); CPPUNIT_ASSERT_EQUAL(24, pic->colorDepth()); CPPUNIT_ASSERT_EQUAL(0, pic->numColors()); CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType()); CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description()); CPPUNIT_ASSERT_EQUAL((unsigned int)150, pic->data().size()); }
bool TagEditor::open( const QString &fileName ) { clear(); #ifdef Q_OS_WIN fRef = new FileRef( ( const wchar_t * )fileName.utf16(), false ); #else fRef = new FileRef( fileName.toLocal8Bit(), false ); #endif if ( !fRef->isNull() && fRef->tag() ) { File &file = *fRef->file(); #if TAGLIB19 /* Copy ID3v2 to InfoTag */ if ( instanceOf( file, RIFF::WAV::File ) ) { const Tag &tag = *fRef->tag(); RIFF::Info::Tag &infoTag = *( ( RIFF::WAV::File & )file ).InfoTag(); if ( infoTag.isEmpty() && !tag.isEmpty() ) { infoTag.setTitle( tag.title() ); infoTag.setArtist( tag.artist() ); infoTag.setAlbum( tag.album() ); infoTag.setComment( tag.comment() ); infoTag.setGenre( tag.genre() ); infoTag.setYear( tag.year() ); infoTag.setTrack( tag.track() ); } } #endif const Tag &tag = getTag( *fRef, file ); bool hasTags = !tag.isEmpty(); setChecked( true ); if ( hasTags ) { titleE->setText( tag.title().toCString( true ) ); artistE->setText( tag.artist().toCString( true ) ); albumE->setText( tag.album().toCString( true ) ); commentE->setText( tag.comment().toCString( true ) ); genreE->setText( tag.genre().toCString( true ) ); yearB->setValue( tag.year() ); trackB->setValue( tag.track() ); } /* Covers */ if ( instanceOf( file, MPEG::File ) || instanceOf( file, RIFF::AIFF::File ) ) { pictureB->setEnabled( true ); if ( hasTags ) { ID3v2::Tag *id3v2 = NULL; if ( instanceOf( file, MPEG::File ) ) { MPEG::File &mpegF = ( MPEG::File & )file; #if TAGLIB19 if ( mpegF.hasID3v2Tag() ) #endif id3v2 = mpegF.ID3v2Tag(); } else if ( instanceOf( file, RIFF::AIFF::File ) ) id3v2 = ( ( RIFF::AIFF::File & )file ).tag(); if ( id3v2 ) { const ID3v2::FrameList &frameList = id3v2->frameList( "APIC" ); if ( !frameList.isEmpty() ) { ID3v2::AttachedPictureFrame &pictureFrame = *( ID3v2::AttachedPictureFrame * )frameList.front(); pictureMimeType = pictureFrame.mimeType().toCString(); *picture = pictureFrame.picture(); pictureB->setChecked( true ); pictureW->update(); } } } } else if ( instanceOf( file, FLAC::File ) ) { pictureB->setEnabled( true ); FLAC::File &flacF = ( FLAC::File & )file; if ( !flacF.pictureList().isEmpty() ) { FLAC::Picture &flacPicture = *flacF.pictureList().front(); pictureMimeType = flacPicture.mimeType().toCString(); *picture = flacPicture.data(); pictureB->setChecked( true ); pictureW->update(); hasTags = true; } } else if ( instanceOf( file, MP4::File ) ) { MP4::ItemListMap &itemListMap = ( ( MP4::File & )file ).tag()->itemListMap(); MP4::ItemListMap::ConstIterator it = itemListMap.find( "covr" ); pictureB->setEnabled( true ); if ( it != itemListMap.end() ) { MP4::CoverArtList coverArtList = it->second.toCoverArtList(); if ( !coverArtList.isEmpty() ) { MP4::CoverArt coverArt = coverArtList.front(); switch ( coverArt.format() ) { case MP4::CoverArt::JPEG: pictureMimeType = "image/jpeg"; break; case MP4::CoverArt::PNG: pictureMimeType = "image/png"; break; #if TAGLIB18 case MP4::CoverArt::BMP: pictureMimeType = "image/bmp"; break; case MP4::CoverArt::GIF: pictureMimeType = "image/gif"; break; #endif default: break; } if ( !pictureMimeType.isEmpty() ) { *picture = coverArt.data(); pictureB->setChecked( true ); pictureW->update(); hasTags = true; } } } } else if ( isOgg( file ) ) { const Ogg::XiphComment *xiphComment = getXiphComment( file ); if ( xiphComment ) { const Ogg::FieldListMap &fieldListMap = xiphComment->fieldListMap(); Ogg::FieldListMap::ConstIterator it = fieldListMap.find( "METADATA_BLOCK_PICTURE" ); pictureB->setEnabled( true ); if ( it != fieldListMap.end() && !it->second.isEmpty() ) { /* OGG picture and FLAC picture are the same except OGG picture is encoded into Base64 */ QByteArray pict_frame_decoded = QByteArray::fromBase64( it->second.front().toCString() ); FLAC::Picture flacPicture; if ( flacPicture.parse( ByteVector( pict_frame_decoded.data(), pict_frame_decoded.size() ) ) ) { pictureMimeType = flacPicture.mimeType().toCString(); *picture = flacPicture.data(); pictureB->setChecked( true ); pictureW->update(); } } } } pictureBChecked = pictureB->isChecked(); setChecked( hasTags ); return true; } delete fRef; fRef = NULL; return false; }