+static void ParsePicture( demux_t *p_demux, uint8_t *p_data, int i_data )
+{
+ static const int pi_cover_score[] = {
+ 0, /* other */
+ 2, 1, /* icons */
+ 10, /* front cover */
+ 9, /* back cover */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 6, /* movie/video screen capture */
+ 0,
+ 7, /* Illustration */
+ 8, /* Band/Artist logotype */
+ 0, /* Publisher/Studio */
+ };
+ demux_sys_t *p_sys = p_demux->p_sys;
+ int i_type;
+ int i_len;
+ char *psz_mime = NULL;
+ char *psz_description = NULL;
+ input_attachment_t *p_attachment;
+ char psz_name[128];
+
+ if( i_data < 4 + 3*4 )
+ return;
+#define RM(x) do { i_data -= (x); p_data += (x); } while(0)
+ RM(4);
+
+ i_type = GetDWBE( p_data ); RM(4);
+ i_len = GetDWBE( p_data ); RM(4);
+ if( i_data < i_len + 4 )
+ goto error;
+ psz_mime = strndup( p_data, i_len ); RM(i_len);
+ i_len = GetDWBE( p_data ); RM(4);
+ if( i_data < i_len + 4*4 + 4)
+ goto error;
+ psz_description = strndup( p_data, i_len ); RM(i_len);
+ EnsureUTF8( psz_description );
+ RM(4*4);
+ i_len = GetDWBE( p_data ); RM(4);
+ if( i_len > i_data )
+ goto error;
+
+ msg_Dbg( p_demux, "FLAC: Picture type=%d mime=%s description='%s' file length=%d",
+ i_type, psz_mime, psz_description, i_len );
+
+ snprintf( psz_name, sizeof(psz_name), "picture%d", p_sys->i_attachment );
+ if( !strcasecmp( psz_mime, "image/jpeg" ) )
+ strcat( psz_name, ".jpg" );
+ else if( !strcasecmp( psz_mime, "image/png" ) )
+ strcat( psz_name, ".png" );
+
+ p_attachment = vlc_input_attachment_New( psz_name, psz_mime, psz_description,
+ p_data, i_data );
+ TAB_APPEND( p_sys->i_attachment, p_sys->attachment, p_attachment );
+
+ if( i_type >= 0 && i_type < sizeof(pi_cover_score)/sizeof(pi_cover_score[0]) &&
+ p_sys->i_cover_score < pi_cover_score[i_type] )
+ {
+ p_sys->i_cover_idx = p_sys->i_attachment-1;
+ p_sys->i_cover_score = pi_cover_score[i_type];
+ }
+error:
+ if( psz_mime )
+ free( psz_mime );
+ if( psz_description )
+ free( psz_description );
+}
+#undef RM
+