[Flac-dev] FLAC__metadata_get_picture()

Alex J. Ivasyuv industral at gmail.com
Thu May 8 17:22:55 PDT 2008


Hi all!

I have a problem to get _all_ images from flac file.
I have flac file with 3 images inside ( FLAC__METADATA_TYPE_PICTURE )

How to get _all_ images with bool FLAC::Metadata::get_picture() func?

This function is wrapper FLAC__bool FLAC__metadata_get_picture().

flac-1.2.1/src/libFLAC/metadata_iterators.c:
...
285 FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, 
FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, 
const char *mime_type, const FLAC__byte *description, unsigned 
max_width, unsigned max_height, unsigned max_depth, unsigned max_colors)
  286 {
  287     FLAC__Metadata_SimpleIterator *it;
  288     FLAC__uint64 max_area_seen = 0;
  289     FLAC__uint64 max_depth_seen = 0;
  290
  291     FLAC__ASSERT(0 != filename);
  292     FLAC__ASSERT(0 != picture);
  293
  294     *picture = 0;
  295
  296     it = FLAC__metadata_simple_iterator_new();
  297     if(0 == it)
  298         return false;
  299     if(!FLAC__metadata_simple_iterator_init(it, filename, 
/*read_only=*/true, /*preserve_file_stats=*/true)) {
  300         FLAC__metadata_simple_iterator_delete(it);
  301         return false;
  302     }
  303     do {
  304         if(FLAC__metadata_simple_iterator_get_block_type(it) == 
FLAC__METADATA_TYPE_PICTURE) {
  305             FLAC__StreamMetadata *obj = 
FLAC__metadata_simple_iterator_get_block(it);
  306             FLAC__uint64 area = 
(FLAC__uint64)obj->data.picture.width * 
(FLAC__uint64)obj->data.picture.height;
  307             /* check constraints */
  308             if(
  309                 (type == (FLAC__StreamMetadata_Picture_Type)(-1) 
|| type == obj->data.picture.type) &&
  310                 (mime_type == 0 || !strcmp(mime_type, 
obj->data.picture.mime_type)) &&
  311                 (description == 0 || !strcmp((const char 
*)description, (const char *)obj->data.picture.description)) &&
  312                 obj->data.picture.width <= max_width &&
  313                 obj->data.picture.height <= max_height &&
  314                 obj->data.picture.depth <= max_depth &&
  315                 obj->data.picture.colors <= max_colors &&
  316                 (area > max_area_seen || (area == max_area_seen && 
obj->data.picture.depth > max_depth_seen))
  317             ) {
  318                 if(*picture)
  319                     FLAC__metadata_object_delete(*picture);
  320                 *picture = obj; // <------- HERE
  321                 max_area_seen = area;
  322                 max_depth_seen = obj->data.picture.depth;
  323             }
  324             else {
  325                 FLAC__metadata_object_delete(obj);
  326             }
  327         }
  328     } while(FLAC__metadata_simple_iterator_next(it));
  329
  330     FLAC__metadata_simple_iterator_delete(it);
  331
  332     return (0 != *picture);
  333 }
...

In line 320 picture always overwrite in do { } ... while ( ) cycle.
So it means, that every time I will get only the last image from file.
Am I right?

So how to get all images?
Thanks for any help.

Bests,



More information about the Flac-dev mailing list