Commit fb482724 authored by Gildas Bazin's avatar Gildas Bazin

* modules/gui/skins2/*: use image handler to load graphic files.

parent c21b2610
...@@ -48,12 +48,19 @@ ...@@ -48,12 +48,19 @@
#include "../utils/var_bool.hpp" #include "../utils/var_bool.hpp"
#include "../utils/var_text.hpp" #include "../utils/var_text.hpp"
#include "vlc_image.h"
Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData):
Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData ):
SkinObject( pIntf ), m_rData( rData ), m_pTheme( NULL ) SkinObject( pIntf ), m_rData( rData ), m_pTheme( NULL )
{ {
m_pImageHandler = image_HandlerCreate( pIntf );
} }
Builder::~Builder()
{
if( m_pImageHandler ) image_HandlerDelete( m_pImageHandler );
}
CmdGeneric *Builder::parseAction( const string &rAction ) CmdGeneric *Builder::parseAction( const string &rAction )
{ {
...@@ -133,15 +140,17 @@ void Builder::addTheme( const BuilderData::Theme &rData ) ...@@ -133,15 +140,17 @@ void Builder::addTheme( const BuilderData::Theme &rData )
void Builder::addBitmap( const BuilderData::Bitmap &rData ) void Builder::addBitmap( const BuilderData::Bitmap &rData )
{ {
GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_fileName, GenericBitmap *pBmp =
rData.m_alphaColor ); new PngBitmap( getIntf(), m_pImageHandler,
rData.m_fileName, rData.m_alphaColor );
m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp ); m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
} }
void Builder::addBitmapFont( const BuilderData::BitmapFont &rData ) void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
{ {
GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_file, 0 ); GenericBitmap *pBmp =
new PngBitmap( getIntf(), m_pImageHandler, rData.m_file, 0 );
m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp ); m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type ); GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );
......
...@@ -47,7 +47,7 @@ class Builder: public SkinObject ...@@ -47,7 +47,7 @@ class Builder: public SkinObject
{ {
public: public:
Builder( intf_thread_t *pIntf, const BuilderData &rData ); Builder( intf_thread_t *pIntf, const BuilderData &rData );
virtual ~Builder() {} virtual ~Builder();
/// Create a Theme object, ready to use. /// Create a Theme object, ready to use.
/// Return NULL in case of problem /// Return NULL in case of problem
...@@ -90,6 +90,9 @@ class Builder: public SkinObject ...@@ -90,6 +90,9 @@ class Builder: public SkinObject
/// Function to parse "points" tags /// Function to parse "points" tags
Bezier *getPoints( const char *pTag ) const; Bezier *getPoints( const char *pTag ) const;
/// Image handler (used to load image files)
image_handler_t *m_pImageHandler;
}; };
#endif #endif
......
...@@ -22,122 +22,53 @@ ...@@ -22,122 +22,53 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#include <png.h> #include <vlc/vlc.h>
#include "vlc_image.h"
#include "png_bitmap.hpp" #include "png_bitmap.hpp"
PngBitmap::PngBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
PngBitmap::PngBitmap( intf_thread_t *pIntf, string fileName, string fileName, uint32_t aColor ):
uint32_t aColor ): GenericBitmap( pIntf ), m_width( 0 ), m_height( 0 )
GenericBitmap( pIntf ), m_width( 0 ), m_height( 0 ), m_pData( NULL )
{ {
// Open the PNG file video_format_t fmt_in = {0}, fmt_out = {0};
FILE *pFile = fopen( fileName.c_str(), "rb" ); picture_t *pPic;
if( pFile == NULL )
{
msg_Err( getIntf(), "Cannot open bitmap %s", fileName.c_str() );
return;
}
// Create the PNG structures
png_structp pReadStruct = png_create_read_struct( PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL );
if ( pReadStruct == NULL )
{
msg_Err( getIntf(), "Failed to create PNG read struct" );
return;
}
png_infop pInfo = png_create_info_struct( pReadStruct );
if( pInfo == NULL )
{
png_destroy_read_struct( &pReadStruct, NULL, NULL );
msg_Err( getIntf(), "Failed to create PNG info struct" );
return;
}
png_infop pEndInfo = png_create_info_struct( pReadStruct );
if( pEndInfo == NULL )
{
png_destroy_read_struct( &pReadStruct, NULL, NULL );
msg_Err( getIntf(), "Failed to create PNG end info struct" );
return;
}
// Initialize the PNG reader fmt_out.i_chroma = VLC_FOURCC('R','V','3','2');
png_init_io( pReadStruct, pFile );
// Read the image header pPic = image_ReadUrl( pImageHandler, fileName.c_str(), &fmt_in, &fmt_out );
png_read_info( pReadStruct, pInfo ); if( !pPic ) return;
m_width = png_get_image_width( pReadStruct, pInfo );
m_height = png_get_image_height( pReadStruct, pInfo );
int depth = png_get_bit_depth( pReadStruct, pInfo );
int colorType = png_get_color_type( pReadStruct, pInfo );
// Convert paletted images to RGB m_width = fmt_out.i_width;
if( colorType == PNG_COLOR_TYPE_PALETTE ) m_height = fmt_out.i_height;
{
png_set_palette_to_rgb( pReadStruct );
}
// Strip to 8 bits per channel
if( depth == 16 )
{
png_set_strip_16( pReadStruct );
}
// 4 bytes per pixel
if( !(colorType & PNG_COLOR_MASK_ALPHA ) )
{
png_set_filler( pReadStruct, 0xff, PNG_FILLER_AFTER );
}
// Invert colors
if( colorType & PNG_COLOR_MASK_COLOR )
{
png_set_bgr( pReadStruct );
}
png_read_update_info( pReadStruct, pInfo );
// Allocate memory for the buffers
m_pData = new uint8_t[m_height * m_width * 4]; m_pData = new uint8_t[m_height * m_width * 4];
uint8_t** pRows = new uint8_t*[m_height];
for( int i = 0; i < m_height; i++ )
{
pRows[i] = m_pData + (i * m_width * 4);
}
// Read the image
png_read_image( pReadStruct, pRows );
png_read_end( pReadStruct, pEndInfo );
// Compute the alpha layer // Compute the alpha layer
uint8_t *pData = m_pData; uint8_t *pData = m_pData, *pSrc = pPic->p->p_pixels;
for( int y = 0; y < m_height; y++ ) for( int y = 0; y < m_height; y++ )
{ {
for( int x = 0; x < m_width; x++ ) for( int x = 0; x < m_width; x++ )
{ {
uint32_t b = (uint32_t)*(pData++); uint32_t b = (uint32_t)*(pData++) = (uint32_t)*(pSrc++);
uint32_t g = (uint32_t)*(pData++); uint32_t g = (uint32_t)*(pData++) = (uint32_t)*(pSrc++);
uint32_t r = (uint32_t)*(pData++); uint32_t r = (uint32_t)*(pData++) = (uint32_t)*(pSrc++);
(uint32_t)*pData = (uint32_t)*pSrc;
// Transparent pixel ? // Transparent pixel ?
if( aColor == (r<<16 | g<<8 | b) ) if( aColor == (r<<16 | g<<8 | b) ) *pData = 0;
{ pData++; pSrc++;
*pData = 0;
}
pData++;
} }
pSrc += pPic->p->i_pitch - m_width * 4;
} }
// Free the structures pPic->pf_release( pPic );
png_destroy_read_struct( &pReadStruct, &pInfo, &pEndInfo ); return;
delete[] pRows;
// Close the file
fclose( pFile );
} }
PngBitmap::~PngBitmap() PngBitmap::~PngBitmap()
{ {
if( m_pData ) if( m_pData ) delete[] m_pData;
{
delete[] m_pData;
}
} }
......
...@@ -35,8 +35,8 @@ class PngBitmap: public GenericBitmap ...@@ -35,8 +35,8 @@ class PngBitmap: public GenericBitmap
public: public:
/// Load a PNG bitmap from a file. aColor is the transparency /// Load a PNG bitmap from a file. aColor is the transparency
/// color, in the format 0xRRGGBB /// color, in the format 0xRRGGBB
PngBitmap( intf_thread_t *pIntf, string fileName, PngBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
uint32_t aColor ); string fileName, uint32_t aColor );
virtual ~PngBitmap(); virtual ~PngBitmap();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment