bool ArtUtility::extractSingle( JobContext& job, const CoverArtBox::Item& item, uint32_t index ) { // compute out filename string out_name = job.file; FileSystem::pathnameStripExtension( out_name ); ostringstream oss; oss << out_name << ".art[" << index << ']'; // if implicit we try to determine type by inspecting data BasicType bt = item.type; if( bt == BT_IMPLICIT ) bt = computeBasicType( item.buffer, item.size ); // add file extension appropriate for known covr-box types switch( bt ) { case BT_GIF: oss << ".gif"; break; case BT_JPEG: oss << ".jpg"; break; case BT_PNG: oss << ".png"; break; case BT_BMP: oss << ".bmp"; break; default: oss << ".dat"; break; } out_name = oss.str(); verbose1f( "extracting %s (index=%d) -> %s\n", job.file.c_str(), index, out_name.c_str() ); if( dryrunAbort() ) return SUCCESS; File out( out_name, File::MODE_CREATE ); if( openFileForWriting( out )) return FAILURE; File::Size nout; if( out.write( item.buffer, item.size, nout )) return herrf( "write failed: %s\n", out_name.c_str() ); out.close(); return SUCCESS; }
void Tags::c_setArtwork( MP4Tags*& tags, uint32_t index, MP4TagArtwork& c_artwork ) { if( !(index < artwork.size()) ) return; CoverArtBox::Item& item = artwork[index]; switch( c_artwork.type ) { case MP4_ART_BMP: item.type = BT_BMP; break; case MP4_ART_GIF: item.type = BT_GIF; break; case MP4_ART_JPEG: item.type = BT_JPEG; break; case MP4_ART_PNG: item.type = BT_PNG; break; case MP4_ART_UNDEFINED: default: item.type = computeBasicType( c_artwork.data, c_artwork.size ); break; } item.buffer = (uint8_t*)malloc( c_artwork.size ); item.size = c_artwork.size; item.autofree = true; memcpy( item.buffer, c_artwork.data, c_artwork.size ); updateArtworkShadow( tags ); }