]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/scaled_bitmap.cpp
Translate french comment
[vlc] / modules / gui / skins2 / src / scaled_bitmap.cpp
1 /*****************************************************************************
2  * scaled_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 "scaled_bitmap.hpp"
26
27
28 ScaledBitmap::ScaledBitmap( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
29                             int width, int height ):
30     GenericBitmap( pIntf ), m_width( width ), m_height( height )
31 {
32     // XXX We should check that width and height are positive...
33
34     // Allocate memory for the buffer
35     m_pData = new uint8_t[m_height * m_width * 4];
36
37     int srcWidth = rBitmap.getWidth();
38     int srcHeight = rBitmap.getHeight();
39     uint32_t *pSrcData = (uint32_t*)rBitmap.getData();
40     uint32_t *pDestData = (uint32_t*)m_pData;
41
42     // Algorithm for horizontal enlargement
43     if( width > srcWidth )
44     {
45         // Decision variables for Bresenham algorithm
46         int incX1 = 2 * (srcWidth-1);
47         int incX2 = incX1 - 2 * (width-1);
48         int dX = incX1 - (width-1);
49
50         for( int y = 0; y < height; y++ )
51         {
52             uint32_t yOffset = ((y * srcHeight) / height) * srcWidth;
53             pSrcData = ((uint32_t*)rBitmap.getData()) + yOffset;
54
55             for( int x = 0; x < width; x++ )
56             {
57                 *(pDestData++) = *pSrcData;
58
59                 if( dX <= 0 )
60                 {
61                     dX += incX1;
62                 }
63                 else
64                 {
65                     dX += incX2;
66                     pSrcData++;
67                 }
68             }
69         }
70     }
71     // Algorithm for horizontal reduction
72     else
73     {
74         // Decision variables for Bresenham algorithm
75         int incX1 = 2 * (width-1);
76         int incX2 = incX1 - 2 * (srcWidth-1);
77         int dX = incX1 - (srcWidth-1);
78
79         for( int y = 0; y < height; y++ )
80         {
81             uint32_t yOffset = ((y * srcHeight) / height) * srcWidth;
82             pSrcData = ((uint32_t*)rBitmap.getData()) + yOffset;
83
84             for( int x = 0; x < width; x++ )
85             {
86                 *(pDestData++) = *(pSrcData++);
87
88                 while( dX <= 0 )
89                 {
90                     dX += incX1;
91                     pSrcData++;
92                 }
93                 dX += incX2;
94             }
95         }
96
97     }
98 }
99
100
101 ScaledBitmap::~ScaledBitmap()
102 {
103     if( m_pData )
104     {
105         delete[] m_pData;
106     }
107 }
108