]> git.sesse.net Git - vlc/blob - modules/access/screen/beos.cpp
23ec59088e24b43cda157026d5862e8a5b92f176
[vlc] / modules / access / screen / beos.cpp
1 /*****************************************************************************
2  * beos.cpp: Screen capture module.
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Eric Petit <titer@m0k.org>
8  *
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.
13  *
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.
18  *
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24
25 #include <vlc/vlc.h>
26
27 #include <Screen.h>
28 #include <Bitmap.h>
29
30 extern "C"
31 {
32
33 #include "screen.h"
34
35 struct screen_data_t
36 {
37     BScreen * p_screen;
38     BBitmap * p_bitmap;
39 };
40
41 int screen_InitCapture( demux_t *p_demux )
42 {
43     demux_sys_t   *p_sys = p_demux->p_sys;
44     screen_data_t *p_data;
45     BRect          rect;
46     int            i_chroma;
47     int            i_bits_per_pixel;
48
49     p_sys->p_data = p_data =
50         (screen_data_t *)malloc( sizeof( screen_data_t ) );
51
52     p_data->p_screen = new BScreen();
53     rect = p_data->p_screen->Frame();
54
55     p_data->p_bitmap = new BBitmap( rect, p_data->p_screen->ColorSpace() );
56
57     switch( p_data->p_screen->ColorSpace() )
58     {
59         case B_RGB32:
60             i_chroma = VLC_FOURCC('R','V','3','2');
61             i_bits_per_pixel = 32;
62             break;
63         case B_RGB16:
64             i_chroma = VLC_FOURCC('R','V','1','6');
65             i_bits_per_pixel = 16;
66             break;
67         default:
68             msg_Err( p_demux, "screen depth %i unsupported",
69                      p_data->p_screen->ColorSpace() );
70             delete p_data->p_bitmap;
71             delete p_data->p_screen;
72             free( p_data );
73             return VLC_EGENERIC;
74     }
75     es_format_Init( &p_sys->fmt, VIDEO_ES, i_chroma );
76     p_sys->fmt.video.i_width  = (int)rect.Width();
77     p_sys->fmt.video.i_height = (int)rect.Height();
78     p_sys->fmt.video.i_bits_per_pixel = i_bits_per_pixel;
79
80     return VLC_SUCCESS;
81 }
82
83 int screen_CloseCapture( demux_t *p_demux )
84 {
85     demux_sys_t   *p_sys  = p_demux->p_sys;
86     screen_data_t *p_data = p_sys->p_data;
87
88     delete p_data->p_bitmap;
89     delete p_data->p_screen;
90     free( p_data );
91
92     return VLC_SUCCESS;
93 }
94
95 block_t *screen_Capture( demux_t *p_demux )
96 {
97     demux_sys_t   *p_sys  = p_demux->p_sys;
98     screen_data_t *p_data = p_sys->p_data;
99     block_t       *p_block;
100
101     p_block = block_New( p_demux, p_sys->fmt.video.i_width *
102                          p_sys->fmt.video.i_height *
103                          p_sys->fmt.video.i_bits_per_pixel / 8 );
104
105     p_data->p_screen->ReadBitmap( p_data->p_bitmap );
106
107     for( unsigned i = 0; i < p_sys->fmt.video.i_height; i++ )
108     {
109         memcpy( p_block->p_buffer + i * p_sys->fmt.video.i_width *
110                     p_sys->fmt.video.i_bits_per_pixel / 8,
111                 (uint8_t *) p_data->p_bitmap->Bits() +
112                     i * p_data->p_bitmap->BytesPerRow(),
113                 p_sys->fmt.video.i_width *
114                     p_sys->fmt.video.i_bits_per_pixel / 8 );
115     }
116     return p_block;
117 }
118
119 } /* extern "C" */