]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/file_bitmap.cpp
Remove vlc_object_attach()
[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 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_common.h>
30 #include <vlc_image.h>
31 #include <vlc_url.h>
32 #include "file_bitmap.hpp"
33
34 FileBitmap::FileBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
35                         string fileName, uint32_t aColor, int nbFrames,
36                         int fps, int nbLoops ):
37     GenericBitmap( pIntf, nbFrames, fps, nbLoops ), m_width( 0 ), m_height( 0 ),
38     m_pData( NULL )
39 {
40     video_format_t fmt_in, fmt_out;
41     picture_t *pPic;
42
43     video_format_Init( &fmt_in, 0 );
44     video_format_Init( &fmt_out, VLC_CODEC_RGBA );
45
46     char* psz_uri = make_URI( fileName.c_str(), NULL );
47     pPic = image_ReadUrl( pImageHandler, psz_uri, &fmt_in, &fmt_out );
48     free( psz_uri );
49
50     if( !pPic )
51         return;
52
53     m_width = fmt_out.i_width;
54     m_height = fmt_out.i_height;
55
56     m_pData = new uint8_t[m_height * m_width * 4];
57
58     // Compute the alpha layer
59     uint8_t *pData = m_pData, *pSrc = pPic->p->p_pixels;
60     for( int y = 0; y < m_height; y++ )
61     {
62         for( int x = 0; x < m_width; x++ )
63         {
64             uint32_t r = *pSrc++;
65             uint32_t g = *pSrc++;
66             uint32_t b = *pSrc++;
67             uint8_t  a = *pSrc++;
68
69             *(pData++) = b * a / 255;
70             *(pData++) = g * a / 255;
71             *(pData++) = r * a / 255;
72
73             // Transparent pixel ?
74             if( aColor == (r<<16 | g<<8 | b) )
75             {
76                 *pData = 0;
77             }
78             else
79             {
80                 *pData = a;
81             }
82             pData++;
83         }
84         pSrc += pPic->p->i_pitch - m_width * 4;
85     }
86
87     picture_Release( pPic );
88     return;
89 }
90
91
92 FileBitmap::~FileBitmap()
93 {
94     delete[] m_pData;
95 }
96
97
98 uint8_t *FileBitmap::getData() const
99 {
100     if( m_pData == NULL )
101     {
102         msg_Warn( getIntf(), "FileBitmap::getData() returns NULL" );
103     }
104     return m_pData;
105 }