]> git.sesse.net Git - vlc/blobdiff - modules/video_output/wingdi.c
* modules/video_output/wingdi.c: fixed gdi output for 24 and 32 bits color depth.
[vlc] / modules / video_output / wingdi.c
index 66bee45127318cf31fddd9c99c3469f7b0043bff..c08b9ef1dd72fcafdf54d3b06221013a023d929c 100755 (executable)
@@ -2,7 +2,7 @@
  * wingdi.c : Win32 / WinCE GDI video output plugin for vlc
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: wingdi.c,v 1.3 2002/11/22 20:27:19 sam Exp $
+ * $Id: wingdi.c,v 1.8 2003/12/04 14:48:24 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -10,7 +10,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -46,7 +46,7 @@ static void End       ( vout_thread_t * );
 static int  Manage    ( vout_thread_t * );
 static void Render    ( vout_thread_t *, picture_t * );
 static void Display   ( vout_thread_t *, picture_t * );
-static void SetPalette( vout_thread_t *, u16 *, u16 *, u16 * );
+static void SetPalette( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
 
 static void EventThread        ( vlc_object_t * );
 static long FAR PASCAL WndProc ( HWND, UINT, WPARAM, LPARAM );
@@ -67,15 +67,19 @@ struct vout_sys_t
     /* Our offscreen bitmap and its framebuffer */
     HDC        off_dc;
     HBITMAP    off_bitmap;
-    BITMAPINFO bitmapinfo;
     uint8_t *  p_buffer;
+
+    BITMAPINFO bitmapinfo;
+    RGBQUAD    red;
+    RGBQUAD    green;
+    RGBQUAD    blue;
 };
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("Windows GDI video output module") );
+    set_description( _("Windows GDI video output") );
     set_capability( "video output", 10 );
     set_callbacks( OpenVideo, CloseVideo );
 vlc_module_end();
@@ -151,6 +155,12 @@ static int Init( vout_thread_t *p_vout )
             p_vout->output.pf_setpalette = SetPalette;
             break;
         case 24:
+            p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
+            p_vout->output.i_rmask  = 0x00ff0000;
+            p_vout->output.i_gmask  = 0x0000ff00;
+            p_vout->output.i_bmask  = 0x000000ff;
+            break;
+        case 32:
             p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
             p_vout->output.i_rmask  = 0x00ff0000;
             p_vout->output.i_gmask  = 0x0000ff00;
@@ -190,9 +200,9 @@ static int Init( vout_thread_t *p_vout )
             break;
         }
 
-        vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_width,
-                              p_vout->output.i_height,
-                              p_vout->output.i_chroma );
+        vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_chroma,
+                              p_vout->output.i_width, p_vout->output.i_height,
+                              p_vout->output.i_aspect );
 
         if( p_pic->i_planes == 0 )
         {
@@ -255,18 +265,24 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
 {
     /* No need to do anything, the fake direct buffers stay as they are */
     HDC hdc;
-    int y;
+    int i_src_bytes, i_dest_bytes;
 
     hdc = GetDC( p_vout->p_sys->window );
     SelectObject( p_vout->p_sys->off_dc, p_vout->p_sys->off_bitmap );
 
     /* Stupid GDI is upside-down */
-    for( y = p_pic->p->i_lines ; y-- ; )
+    i_src_bytes = p_pic->p->i_lines * p_pic->p->i_pitch;
+    i_dest_bytes = 0;
+
+    while( i_src_bytes )
     {
-        memcpy( p_vout->p_sys->p_buffer
-                         + p_pic->p->i_pitch * (p_pic->p->i_lines-y),
-                p_pic->p->p_pixels + p_pic->p->i_pitch * y,
-                p_pic->p->i_pitch );
+        i_src_bytes -= p_pic->p->i_pitch;
+
+        p_vout->p_vlc->pf_memcpy( p_vout->p_sys->p_buffer + i_dest_bytes,
+                                  p_pic->p->p_pixels + i_src_bytes,
+                                  p_pic->p->i_visible_pitch );
+
+        i_dest_bytes += p_pic->p->i_pitch;
     }
 
     BitBlt( hdc, 0, 0, p_vout->output.i_width, p_vout->output.i_height,
@@ -278,7 +294,8 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
 /*****************************************************************************
  * SetPalette: sets an 8 bpp palette
  *****************************************************************************/
-static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
+static void SetPalette( vout_thread_t *p_vout,
+                        uint16_t *red, uint16_t *green, uint16_t *blue )
 {
     msg_Err( p_vout, "FIXME: SetPalette unimplemented" );
 }
@@ -433,7 +450,8 @@ static long FAR PASCAL WndProc ( HWND hWnd, UINT message,
  *****************************************************************************/
 static void InitBuffers( vout_thread_t *p_vout )
 {
-    BITMAPINFOHEADER *p_header = &p_vout->p_sys->bitmapinfo.bmiHeader;
+    BITMAPINFOHEADER * p_header = &p_vout->p_sys->bitmapinfo.bmiHeader;
+    BITMAPINFO *       p_info = &p_vout->p_sys->bitmapinfo;
     int   i_pixels = p_vout->render.i_height * p_vout->render.i_width;
     HDC   window_dc;
 
@@ -445,23 +463,39 @@ static void InitBuffers( vout_thread_t *p_vout )
     msg_Dbg( p_vout, "GDI depth is %i", p_vout->p_sys->i_depth );
 
     /* Initialize offscreen bitmap */
+    memset( p_info, 0, sizeof( BITMAPINFO ) + 3 * sizeof( RGBQUAD ) );
+
     p_header->biSize = sizeof( BITMAPINFOHEADER );
+    p_header->biSizeImage = 0;
     p_header->biPlanes = 1;
-    p_header->biCompression = BI_RGB;
     switch( p_vout->p_sys->i_depth )
     {
         case 8:
             p_header->biBitCount = 8;
-            p_header->biSizeImage = i_pixels;
+            p_header->biCompression = BI_RGB;
+            /* FIXME: we need a palette here */
             break;
         case 24:
+            p_header->biBitCount = 24;
+            p_header->biCompression = BI_RGB;
+            ((DWORD*)p_info->bmiColors)[0] = 0x00ff0000;
+            ((DWORD*)p_info->bmiColors)[1] = 0x0000ff00;
+            ((DWORD*)p_info->bmiColors)[2] = 0x000000ff;
+            break;
+        case 32:
             p_header->biBitCount = 32;
-            p_header->biSizeImage = i_pixels * 4;
+            p_header->biCompression = BI_RGB;
+            ((DWORD*)p_info->bmiColors)[0] = 0x00ff0000;
+            ((DWORD*)p_info->bmiColors)[1] = 0x0000ff00;
+            ((DWORD*)p_info->bmiColors)[2] = 0x000000ff;
             break;
         case 16:
         default:
             p_header->biBitCount = 16;
-            p_header->biSizeImage = i_pixels * 2;
+            p_header->biCompression = BI_RGB;
+            ((DWORD*)p_info->bmiColors)[0] = 0x00007c00;
+            ((DWORD*)p_info->bmiColors)[1] = 0x000003e0;
+            ((DWORD*)p_info->bmiColors)[2] = 0x0000001f;
             break;
     }
     p_header->biWidth = p_vout->render.i_width;