]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/file_bitmap.cpp
* all: new skin text variable "$B" to get the stream bitrate
[vlc] / modules / gui / skins2 / src / file_bitmap.cpp
1 /*****************************************************************************
2  * file_bitmap.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include <vlc/vlc.h>
26 #include "vlc_image.h"
27 #include "file_bitmap.hpp"
28
29 FileBitmap::FileBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
30                         string fileName, uint32_t aColor, int nbFrames,
31                         int fps ):
32     GenericBitmap( pIntf, nbFrames, fps ), m_width( 0 ), m_height( 0 ),
33     m_pData( NULL )
34 {
35     video_format_t fmt_in = {0}, fmt_out = {0};
36     picture_t *pPic;
37
38     fmt_out.i_chroma = VLC_FOURCC('R','V','3','2');
39
40 fprintf(stderr,"FILE %s\n", fileName.c_str());
41     
42     pPic = image_ReadUrl( pImageHandler, fileName.c_str(), &fmt_in, &fmt_out );
43     if( !pPic ) return;
44
45     m_width = fmt_out.i_width;
46     m_height = fmt_out.i_height;
47
48     m_pData = new uint8_t[m_height * m_width * 4];
49
50     // Compute the alpha layer
51     uint8_t *pData = m_pData, *pSrc = pPic->p->p_pixels;
52     for( int y = 0; y < m_height; y++ )
53     {
54         for( int x = 0; x < m_width; x++ )
55         {
56             uint32_t b = *(pSrc++);
57             uint32_t g = *(pSrc++);
58             uint32_t r = *(pSrc++);
59             uint8_t a = *(pSrc++);
60             *(pData++) = (b * a) >> 8;
61             *(pData++) = (g * a) >> 8;
62             *(pData++) = (r * a) >> 8;
63
64             // Transparent pixel ?
65             if( aColor == (r<<16 | g<<8 | b) )
66             {
67                 *pData = 0;
68             }
69             else
70             {
71                 *pData = a;
72             }
73             pData++;
74         }
75         pSrc += pPic->p->i_pitch - m_width * 4;
76     }
77
78     pPic->pf_release( pPic );
79     return;
80 }
81
82
83 FileBitmap::~FileBitmap()
84 {
85     if( m_pData ) delete[] m_pData;
86 }
87
88
89 uint8_t *FileBitmap::getData() const
90 {
91     if( m_pData == NULL )
92     {
93         msg_Warn( getIntf(), "FileBitmap::getData() returns NULL" );
94     }
95     return m_pData;
96 }