+static int ParseImageAttachments( decoder_t *p_dec )
+{
+ decoder_sys_t *p_sys = p_dec->p_sys;
+ input_attachment_t **pp_attachments;
+ int i_attachments_cnt;
+ int k = 0;
+
+ if( VLC_SUCCESS != decoder_GetInputAttachments( p_dec, &pp_attachments, &i_attachments_cnt ))
+ return VLC_EGENERIC;
+
+ for( k = 0; k < i_attachments_cnt; k++ )
+ {
+ input_attachment_t *p_attach = pp_attachments[k];
+
+ vlc_fourcc_t type = 0;
+
+ if( ( !strcmp( p_attach->psz_mime, "image/bmp" ) ) || /* BMP */
+ ( !strcmp( p_attach->psz_mime, "image/x-bmp" ) ) ||
+ ( !strcmp( p_attach->psz_mime, "image/x-bitmap" ) ) ||
+ ( !strcmp( p_attach->psz_mime, "image/x-ms-bmp" ) ) )
+ {
+ type = VLC_FOURCC('b','m','p',' ');
+ }
+ else if( ( !strcmp( p_attach->psz_mime, "image/x-portable-anymap" ) ) || /* PNM */
+ ( !strcmp( p_attach->psz_mime, "image/x-portable-bitmap" ) ) || /* PBM */
+ ( !strcmp( p_attach->psz_mime, "image/x-portable-graymap" ) ) || /* PGM */
+ ( !strcmp( p_attach->psz_mime, "image/x-portable-pixmap" ) ) ) /* PPM */
+ {
+ type = VLC_FOURCC('p','n','m',' ');
+ }
+ else if ( !strcmp( p_attach->psz_mime, "image/gif" ) ) /* GIF */
+ type = VLC_FOURCC('g','i','f',' ');
+ else if ( !strcmp( p_attach->psz_mime, "image/jpeg" ) ) /* JPG, JPEG */
+ type = VLC_FOURCC('j','p','e','g');
+ else if ( !strcmp( p_attach->psz_mime, "image/pcx" ) ) /* PCX */
+ type = VLC_FOURCC('p','c','x',' ');
+ else if ( !strcmp( p_attach->psz_mime, "image/png" ) ) /* PNG */
+ type = VLC_FOURCC('p','n','g',' ');
+ else if ( !strcmp( p_attach->psz_mime, "image/tiff" ) ) /* TIF, TIFF */
+ type = VLC_FOURCC('t','i','f','f');
+ else if ( !strcmp( p_attach->psz_mime, "image/x-tga" ) ) /* TGA */
+ type = VLC_FOURCC('t','g','a',' ');
+ else if ( !strcmp( p_attach->psz_mime, "image/x-xpixmap") ) /* XPM */
+ type = VLC_FOURCC('x','p','m',' ');
+
+ if( ( type != 0 ) &&
+ ( p_attach->i_data > 0 ) &&
+ ( p_attach->p_data != NULL ) )
+ {
+ picture_t *p_pic = NULL;
+ image_handler_t *p_image;
+
+ p_image = image_HandlerCreate( p_dec );
+ if( p_image != NULL )
+ {
+ block_t *p_block;
+
+ p_block = block_New( p_image->p_parent, p_attach->i_data );
+
+ if( p_block != NULL )
+ {
+ video_format_t fmt_in;
+ video_format_t fmt_out;
+
+ memcpy( p_block->p_buffer, p_attach->p_data, p_attach->i_data );
+
+ memset( &fmt_in, 0, sizeof( video_format_t));
+ memset( &fmt_out, 0, sizeof( video_format_t));
+
+ fmt_in.i_chroma = type;
+ fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
+
+ /* Find a suitable decoder module */
+ if( module_Exists( p_dec, "SDL Image decoder" ) )
+ {
+ /* ffmpeg thinks it can handle bmp properly but it can't (at least
+ * not all of them), so use sdl_image if it is available */
+
+ vlc_value_t val;
+
+ var_Create( p_dec, "codec", VLC_VAR_MODULE | VLC_VAR_DOINHERIT );
+ val.psz_string = (char*) "sdl_image";
+ var_Set( p_dec, "codec", val );
+ }
+
+ p_pic = image_Read( p_image, p_block, &fmt_in, &fmt_out );
+ var_Destroy( p_dec, "codec" );
+ }
+
+ image_HandlerDelete( p_image );
+ }
+ if( p_pic )
+ {
+ image_attach_t *p_picture = malloc( sizeof(image_attach_t) );
+
+ if( p_picture )
+ {
+ p_picture->psz_filename = strdup( p_attach->psz_name );
+ p_picture->p_pic = p_pic;
+
+ TAB_APPEND( p_sys->i_images, p_sys->pp_images, p_picture );
+ }
+ }
+ }
+ vlc_input_attachment_Delete( pp_attachments[ k ] );
+ }
+ free( pp_attachments );
+
+ return VLC_SUCCESS;
+}
+