]> git.sesse.net Git - vlc/blobdiff - src/misc/image.c
Add image_Mime2Fourcc() function and use in image_ReadUrl()
[vlc] / src / misc / image.c
index 9120f7cd112338a09efb8781daa2db12b1dad0ee..86eeb452a8badc4f1a0ae596944f814ad05c3990 100644 (file)
@@ -236,6 +236,15 @@ static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url,
     p_block = block_New( p_image->p_parent, i_size );
 
     stream_Read( p_stream, p_block->p_buffer, i_size );
+
+    if( !p_fmt_in->i_chroma )
+    {
+        char *psz_mime = NULL;
+        stream_Control( p_stream, STREAM_GET_CONTENT_TYPE, &psz_mime );
+        if( psz_mime )
+            p_fmt_in->i_chroma = image_Mime2Fourcc( psz_mime );
+        free( psz_mime );
+    }
     stream_Delete( p_stream );
 
     if( !p_fmt_in->i_chroma )
@@ -576,6 +585,40 @@ static const char *Fourcc2Ext( vlc_fourcc_t i_codec )
 }
 */
 
+static const struct
+{
+    vlc_fourcc_t i_codec;
+    const char *psz_mime;
+} mime_table[] =
+{
+    { VLC_FOURCC('b','m','p',' '), "image/bmp" },
+    { VLC_FOURCC('b','m','p',' '), "image/x-bmp" },
+    { VLC_FOURCC('b','m','p',' '), "image/x-bitmap" },
+    { VLC_FOURCC('b','m','p',' '), "image/x-ms-bmp" },
+    { VLC_FOURCC('p','n','m',' '), "image/x-portable-anymap" },
+    { VLC_FOURCC('p','n','m',' '), "image/x-portable-bitmap" },
+    { VLC_FOURCC('p','n','m',' '), "image/x-portable-graymap" },
+    { VLC_FOURCC('p','n','m',' '), "image/x-portable-pixmap" },
+    { VLC_FOURCC('g','i','f',' '), "image/gif" },
+    { VLC_FOURCC('j','p','e','g'), "image/jpeg" },
+    { VLC_FOURCC('p','c','x',' '), "image/pcx" },
+    { VLC_FOURCC('p','n','g',' '), "image/png" },
+    { VLC_FOURCC('t','i','f','f'), "image/tiff" },
+    { VLC_FOURCC('t','g','a',' '), "iamge/x-tga" },
+    { VLC_FOURCC('x','p','m',' '), "image/x-xpixmap" },
+    { 0, NULL }
+};
+
+vlc_fourcc_t image_Mime2Fourcc( const char *psz_mime )
+{
+    int i;
+    for( i = 0; mime_table[i].i_codec; i++ )
+        if( !strcmp( psz_mime, mime_table[i].psz_mime ) )
+            return mime_table[i].i_codec;
+    return 0;
+}
+
+
 static picture_t *video_new_buffer( decoder_t *p_dec )
 {
     p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;