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