1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: scaled_bitmap.cpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
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., 59 Temple Place - Suite 330, Boston, MA 02111, 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 alogrithm
46 int incX1 = 2 * srcWidth;
47 int incX2 = incX1 - 2 * width;
48 int dX = incX1 - width;
50 for( int y = 0; y < height; y++ )
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 alogrithm
75 int incX1 = 2 * width;
76 int incX2 = incX1 - 2 * srcWidth;
77 int dX = incX1 - srcWidth;
79 for( int y = 0; y < height; y++ )
81 uint32_t yOffset = ((y * srcHeight) / height) * srcWidth;
82 pSrcData = ((uint32_t*)rBitmap.getData()) + yOffset;
84 for( int x = 0; x < width; x++ )
86 *(pDestData++) = *(pSrcData++);
101 ScaledBitmap::~ScaledBitmap()