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

png_bitmap.cpp

00001 /*****************************************************************************
00002  * png_bitmap.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: png_bitmap.cpp 12940 2005-10-23 14:39:57Z asmax $
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 <vlc/vlc.h>
00026 #include "vlc_image.h"
00027 #include "png_bitmap.hpp"
00028 
00029 PngBitmap::PngBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
00030                       string fileName, uint32_t aColor ):
00031     GenericBitmap( pIntf ), m_width( 0 ), m_height( 0 )
00032 {
00033     video_format_t fmt_in = {0}, fmt_out = {0};
00034     picture_t *pPic;
00035 
00036     fmt_out.i_chroma = VLC_FOURCC('R','V','3','2');
00037 
00038     pPic = image_ReadUrl( pImageHandler, fileName.c_str(), &fmt_in, &fmt_out );
00039     if( !pPic ) return;
00040 
00041     m_width = fmt_out.i_width;
00042     m_height = fmt_out.i_height;
00043 
00044     m_pData = new uint8_t[m_height * m_width * 4];
00045 
00046     // Compute the alpha layer
00047     uint8_t *pData = m_pData, *pSrc = pPic->p->p_pixels;
00048     for( int y = 0; y < m_height; y++ )
00049     {
00050         for( int x = 0; x < m_width; x++ )
00051         {
00052             uint32_t b = *(pSrc++);
00053             uint32_t g = *(pSrc++);
00054             uint32_t r = *(pSrc++);
00055             uint8_t a = *(pSrc++);
00056             *(pData++) = (b * a) >> 8;
00057             *(pData++) = (g * a) >> 8;
00058             *(pData++) = (r * a) >> 8;
00059 
00060             // Transparent pixel ?
00061             if( aColor == (r<<16 | g<<8 | b) )
00062             {
00063                 *pData = 0;
00064             }
00065             else
00066             {
00067                 *pData = a;
00068             }
00069             pData++;
00070         }
00071         pSrc += pPic->p->i_pitch - m_width * 4;
00072     }
00073 
00074     pPic->pf_release( pPic );
00075     return;
00076 }
00077 
00078 
00079 PngBitmap::~PngBitmap()
00080 {
00081     if( m_pData ) delete[] m_pData;
00082 }
00083 
00084 
00085 uint8_t *PngBitmap::getData() const
00086 {
00087     if( m_pData == NULL )
00088     {
00089         msg_Warn( getIntf(), "PngBitmap::getData() returns NULL" );
00090     }
00091     return m_pData;
00092 }

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