1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
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.
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.
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 *****************************************************************************/
25 #include "scaled_bitmap.hpp"
28 ScaledBitmap::ScaledBitmap( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
29 int width, int height ):
30 GenericBitmap( pIntf ), m_width( width ), m_height( height )
32 // XXX We should check that width and height are positive...
34 // Allocate memory for the buffer
35 m_pData = new uint8_t[m_height * m_width * 4];
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;
42 // Algorithm for horizontal enlargement
43 if( width > srcWidth )
45 // Decision variables for Bresenham algorithm
46 int incX1 = 2 * (srcWidth-1);
47 int incX2 = incX1 - 2 * (width-1);
49 for( int y = 0; y < height; y++ )
51 int dX = incX1 - (width-1);
52 uint32_t yOffset = ((y * srcHeight) / height) * srcWidth;
53 pSrcData = ((uint32_t*)rBitmap.getData()) + yOffset;
55 for( int x = 0; x < width; x++ )
57 *(pDestData++) = *pSrcData;
71 // Algorithm for horizontal reduction
74 // Decision variables for Bresenham algorithm
75 int incX1 = 2 * (width-1);
76 int incX2 = incX1 - 2 * (srcWidth-1);
78 for( int y = 0; y < height; y++ )
80 int dX = incX1 - (srcWidth-1);
81 uint32_t yOffset = ((y * srcHeight) / height) * srcWidth;
82 pSrcData = ((uint32_t*)rBitmap.getData()) + yOffset;
86 *(pDestData++) = *pSrcData;
88 else for( int x = 0; x < width; x++ )
90 *(pDestData++) = *(pSrcData++);
105 ScaledBitmap::~ScaledBitmap()