Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

scaled_bitmap.cpp

00001 /*****************************************************************************
00002  * scaled_bitmap.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: scaled_bitmap.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #include "scaled_bitmap.hpp"
00026 
00027 
00028 ScaledBitmap::ScaledBitmap( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
00029                             int width, int height ):
00030     GenericBitmap( pIntf ), m_width( width ), m_height( height )
00031 {
00032     // XXX We should check that width and height are positive...
00033 
00034     // Allocate memory for the buffer
00035     m_pData = new uint8_t[m_height * m_width * 4];
00036 
00037     int srcWidth = rBitmap.getWidth();
00038     int srcHeight = rBitmap.getHeight();
00039     uint32_t *pSrcData = (uint32_t*)rBitmap.getData();
00040     uint32_t *pDestData = (uint32_t*)m_pData;
00041 
00042     // Algorithm for horizontal enlargement
00043     if( width > srcWidth )
00044     {
00045         // Decision variables for Bresenham algorithm
00046         int incX1 = 2 * (srcWidth-1);
00047         int incX2 = incX1 - 2 * (width-1);
00048         int dX = incX1 - (width-1);
00049 
00050         for( int y = 0; y < height; y++ )
00051         {
00052             uint32_t yOffset = ((y * srcHeight) / height) * srcWidth;
00053             pSrcData = ((uint32_t*)rBitmap.getData()) + yOffset;
00054 
00055             for( int x = 0; x < width; x++ )
00056             {
00057                 *(pDestData++) = *pSrcData;
00058 
00059                 if( dX <= 0 )
00060                 {
00061                     dX += incX1;
00062                 }
00063                 else
00064                 {
00065                     dX += incX2;
00066                     pSrcData++;
00067                 }
00068             }
00069         }
00070     }
00071     // Algorithm for horizontal reduction
00072     else
00073     {
00074         // Decision variables for Bresenham algorithm
00075         int incX1 = 2 * (width-1);
00076         int incX2 = incX1 - 2 * (srcWidth-1);
00077         int dX = incX1 - (srcWidth-1);
00078 
00079         for( int y = 0; y < height; y++ )
00080         {
00081             uint32_t yOffset = ((y * srcHeight) / height) * srcWidth;
00082             pSrcData = ((uint32_t*)rBitmap.getData()) + yOffset;
00083 
00084             for( int x = 0; x < width; x++ )
00085             {
00086                 *(pDestData++) = *(pSrcData++);
00087 
00088                 while( dX <= 0 )
00089                 {
00090                     dX += incX1;
00091                     pSrcData++;
00092                 }
00093                 dX += incX2;
00094             }
00095         }
00096 
00097     }
00098 }
00099 
00100 
00101 ScaledBitmap::~ScaledBitmap()
00102 {
00103     if( m_pData )
00104     {
00105         delete[] m_pData;
00106     }
00107 }
00108 

Generated on Tue Dec 20 10:14:42 2005 for vlc-0.8.4a by  doxygen 1.4.2