1 /*****************************************************************************
2 * win32.c: Screen capture module.
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
30 #include <vlc/input.h>
43 int screen_InitCapture( demux_t *p_demux )
45 demux_sys_t *p_sys = p_demux->p_sys;
46 screen_data_t *p_data;
47 int i_chroma, i_bits_per_pixel;
51 p_sys->p_data = p_data = malloc( sizeof( screen_data_t ) );
53 /* Get the device context for the whole screen */
54 p_data->hdc_src = CreateDC( "DISPLAY", NULL, NULL, NULL );
55 if( !p_data->hdc_src )
57 msg_Err( p_demux, "cannot get device context" );
61 p_data->hdc_dst = CreateCompatibleDC( p_data->hdc_src );
62 if( !p_data->hdc_dst )
64 msg_Err( p_demux, "cannot get compat device context" );
65 ReleaseDC( 0, p_data->hdc_src );
69 i_bits_per_pixel = GetDeviceCaps( p_data->hdc_src, BITSPIXEL );
70 switch( i_bits_per_pixel )
72 case 8: /* FIXME: set the palette */
73 i_chroma = VLC_FOURCC('R','G','B','2'); break;
75 i_chroma = VLC_FOURCC('R','V','1','5'); break;
77 i_chroma = VLC_FOURCC('R','V','1','6'); break;
79 i_chroma = VLC_FOURCC('R','V','2','4'); break;
81 i_chroma = VLC_FOURCC('R','V','3','2'); break;
83 msg_Err( p_demux, "unknown screen depth %i",
84 p_sys->fmt.video.i_bits_per_pixel );
85 ReleaseDC( 0, p_data->hdc_src );
86 ReleaseDC( 0, p_data->hdc_dst );
90 #if 1 /* For now we force RV24 because of chroma inversion in the other cases*/
91 i_chroma = VLC_FOURCC('R','V','2','4');
92 i_bits_per_pixel = 24;
95 es_format_Init( &p_sys->fmt, VIDEO_ES, i_chroma );
96 p_sys->fmt.video.i_width = GetDeviceCaps( p_data->hdc_src, HORZRES );
97 p_sys->fmt.video.i_height = GetDeviceCaps( p_data->hdc_src, VERTRES );
98 p_sys->fmt.video.i_bits_per_pixel = i_bits_per_pixel;
100 /* Create the bitmap info header */
101 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
102 bmi.bmiHeader.biWidth = p_sys->fmt.video.i_width;
103 bmi.bmiHeader.biHeight = - p_sys->fmt.video.i_height;
104 bmi.bmiHeader.biPlanes = 1;
105 bmi.bmiHeader.biBitCount = p_sys->fmt.video.i_bits_per_pixel;
106 bmi.bmiHeader.biCompression = BI_RGB;
107 bmi.bmiHeader.biSizeImage = 0;
108 bmi.bmiHeader.biXPelsPerMeter =
109 bmi.bmiHeader.biYPelsPerMeter = 0;
110 bmi.bmiHeader.biClrUsed = 0;
111 bmi.bmiHeader.biClrImportant = 0;
113 /* Create the bitmap storage space */
114 p_data->hbmp = CreateDIBSection( p_data->hdc_dst, (BITMAPINFO *)&bmi,
115 DIB_RGB_COLORS, (void **)&p_data->p_buffer, NULL, 0 );
116 if( !p_data->hbmp || !p_data->p_buffer )
118 msg_Err( p_demux, "cannot create bitmap" );
119 if( p_data->hbmp ) DeleteObject( p_data->hbmp );
120 ReleaseDC( 0, p_data->hdc_src );
121 DeleteDC( p_data->hdc_dst );
125 /* Select the bitmap into the compatible DC */
126 p_data->hgdi_backup = SelectObject( p_data->hdc_dst, p_data->hbmp );
127 if( !p_data->hgdi_backup )
129 msg_Err( p_demux, "cannot select bitmap" );
135 int screen_CloseCapture( demux_t *p_demux )
137 demux_sys_t *p_sys = p_demux->p_sys;
138 screen_data_t *p_data = p_sys->p_data;
140 SelectObject( p_data->hdc_dst, p_data->hgdi_backup );
141 DeleteObject( p_data->hbmp );
142 DeleteDC( p_data->hdc_dst );
143 ReleaseDC( 0, p_data->hdc_src );
149 block_t *screen_Capture( demux_t *p_demux )
151 demux_sys_t *p_sys = p_demux->p_sys;
152 screen_data_t *p_data = p_sys->p_data;
156 if( !BitBlt( p_data->hdc_dst, 0, 0,
157 p_sys->fmt.video.i_width, p_sys->fmt.video.i_height,
158 p_data->hdc_src, 0, 0, SRCCOPY ) )
160 msg_Err( p_demux, "error during BitBlt()" );
164 i_size = (p_sys->fmt.video.i_bits_per_pixel + 7) / 8 *
165 p_sys->fmt.video.i_width * p_sys->fmt.video.i_height;
167 if( !( p_block = block_New( p_demux, i_size ) ) )
169 msg_Warn( p_demux, "cannot get block" );
173 memcpy( p_block->p_buffer, p_data->p_buffer, i_size );