Commit 567894b0 authored by Cyril Deguet's avatar Cyril Deguet

* first BMP loader for X11 skins : it can only handle 24bbp uncompressed

  images, but it works !
parent 3a0e5d28
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* x11_bitmap.cpp: X11 implementation of the Bitmap class * x11_bitmap.cpp: X11 implementation of the Bitmap class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: x11_bitmap.cpp,v 1.2 2003/04/30 21:16:24 asmax Exp $ * $Id: x11_bitmap.cpp,v 1.3 2003/05/18 11:25:00 asmax Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* Emmanuel Puig <karibu@via.ecp.fr> * Emmanuel Puig <karibu@via.ecp.fr>
...@@ -42,31 +42,50 @@ ...@@ -42,31 +42,50 @@
#include "../os_theme.h" #include "../os_theme.h"
#include "../src/skin_common.h" #include "../src/skin_common.h"
#include <stdio.h>
// macros to read little endian numbers
#define U16( p ) ( ((uint8_t*)(p))[0] | ((uint8_t*)(p))[1] << 8 )
#define U32( p ) ( U16( p ) | ((uint8_t*)(p))[2] << 16 | ((uint8_t*)(p))[3] << 24 )
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// X11Bitmap // X11Bitmap
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
X11Bitmap::X11Bitmap( intf_thread_t *p_intf, string FileName, int AColor ) X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor )
: Bitmap( p_intf, FileName, AColor ) : Bitmap( p_intf, FileName, AColor )
{ {
p_intf = _p_intf;
// Find the display // Find the display
display = p_intf->p_sys->display; display = p_intf->p_sys->display;
Window root = DefaultRootWindow( display ); int screen = DefaultScreen( display );
int depth = DefaultDepth( display, screen );
Screen *screenptr = DefaultScreenOfDisplay( display );
Visual *visual = DefaultVisualOfScreen( screenptr );
char *data = NULL;
Width = 0;
Height = 0;
AlphaColor = AColor; AlphaColor = AColor;
if( FileName != "" )
{
data = LoadFromFile( FileName, depth, Width, Height );
}
// Create the image
Bmp = XCreateImage( display, visual, depth, ZPixmap, 0, data, Width,
Height, 32, 4 * Width );
XInitImage( Bmp );
// Load the bitmap image // Load the bitmap image
int hotspotX, hotspotY; /* if( rc != BitmapSuccess )
int rc = XReadBitmapFile( display, root, FileName.c_str(),
(unsigned int*)&Width, (unsigned int*)&Height,
&Bmp, &hotspotX, &hotspotY );
if( rc != BitmapSuccess )
{ {
if( FileName != "" ) if( FileName != "" )
msg_Warn( p_intf, "Couldn't load bitmap: %s", FileName.c_str() ); msg_Warn( p_intf, "Couldn't load bitmap: %s", FileName.c_str() );
Width = 0; Width = 0;
Height = 0; Height = 0;
} }*/
/* else /* else
{ {
Width = gdk_pixbuf_get_width( Bmp ); Width = gdk_pixbuf_get_width( Bmp );
...@@ -100,9 +119,10 @@ X11Bitmap::X11Bitmap( intf_thread_t *p_intf, string FileName, int AColor ) ...@@ -100,9 +119,10 @@ X11Bitmap::X11Bitmap( intf_thread_t *p_intf, string FileName, int AColor )
}*/ }*/
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
X11Bitmap::X11Bitmap( intf_thread_t *p_intf, Graphics *from, int x, int y, X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, Graphics *from, int x, int y,
int w, int h, int AColor ) : Bitmap( p_intf, from, x, y, w, h, AColor ) int w, int h, int AColor ) : Bitmap( p_intf, from, x, y, w, h, AColor )
{ {
p_intf = _p_intf;
/* Width = w; /* Width = w;
Height = h; Height = h;
AlphaColor = AColor; AlphaColor = AColor;
...@@ -117,9 +137,10 @@ X11Bitmap::X11Bitmap( intf_thread_t *p_intf, Graphics *from, int x, int y, ...@@ -117,9 +137,10 @@ X11Bitmap::X11Bitmap( intf_thread_t *p_intf, Graphics *from, int x, int y,
BitBlt( bmpDC, 0, 0, Width, Height, fromDC, x, y, SRCCOPY );*/ BitBlt( bmpDC, 0, 0, Width, Height, fromDC, x, y, SRCCOPY );*/
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
X11Bitmap::X11Bitmap( intf_thread_t *p_intf, Bitmap *c ) X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, Bitmap *c )
: Bitmap( p_intf, c ) : Bitmap( p_intf, c )
{ {
p_intf = _p_intf;
/* HBITMAP HBuf; /* HBITMAP HBuf;
// Copy attibutes // Copy attibutes
...@@ -138,19 +159,15 @@ X11Bitmap::X11Bitmap( intf_thread_t *p_intf, Bitmap *c ) ...@@ -138,19 +159,15 @@ X11Bitmap::X11Bitmap( intf_thread_t *p_intf, Bitmap *c )
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
X11Bitmap::~X11Bitmap() X11Bitmap::~X11Bitmap()
{ {
XFreePixmap( display, Bmp ); XDestroyImage( Bmp );
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void X11Bitmap::DrawBitmap( int x, int y, int w, int h, int xRef, int yRef, void X11Bitmap::DrawBitmap( int x, int y, int w, int h, int xRef, int yRef,
Graphics *dest ) Graphics *dest )
{ {
if( Bmp ) Drawable destImg = ( (X11Graphics *)dest )->GetImage();
{ GC destGC = ( (X11Graphics *)dest )->GetGC();
Drawable destImg = ( (X11Graphics *)dest )->GetImage(); XPutImage( display, destImg, destGC, Bmp, x, y, xRef, yRef, w, h );
GC destGC = ( (X11Graphics *)dest )->GetGC();
XCopyArea( display, Bmp, destImg, destGC, x, y, w, h, xRef, yRef );
}
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool X11Bitmap::Hit( int x, int y) bool X11Bitmap::Hit( int x, int y)
...@@ -190,5 +207,71 @@ void X11Bitmap::SetBmpPixel( int x, int y, int color ) ...@@ -190,5 +207,71 @@ void X11Bitmap::SetBmpPixel( int x, int y, int color )
// SetPixelV( bmpDC, x, y, color ); // SetPixelV( bmpDC, x, y, color );
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
char *X11Bitmap::LoadFromFile( string fileName, int depth, int &width, int &height )
{
// BMP header fields
uint32_t fileSize;
uint32_t dataOffset;
uint32_t headerSize;
uint16_t planes;
uint16_t bpp;
uint32_t compression;
uint32_t dataSize;
uint32_t nColors;
FILE *file = fopen( fileName.c_str(), "ro" );
if( !file )
{
msg_Warn( p_intf, "Cannot open %s", fileName.c_str() );
return NULL;
}
// Read the headers
char headers[54];
fread( headers, 54, 1, file );
fileSize = U32( headers + 2 );
dataOffset = U32( headers + 10 );
headerSize = U32( headers + 14 );
width = (int32_t) U32( headers + 18 );
height = (int32_t) U32( headers + 22 );
planes = U32( headers + 26 );
bpp = U32( headers + 28 );
compression = U32( headers + 30 );
dataSize = U32( headers + 34 );
nColors = U32( headers + 50 );
// fprintf(stderr,"image %d %d\n", width, height);
switch( bpp )
{
case 24:
// 24 bits per pixel
{
// Pad to a 32bit boundary
int pad = ((3 * width - 1) / 4) * 4 + 4 - 3 * width;
uint32_t *data = new uint32_t[height * width];
uint32_t *ptr;
for( int j = 0; j < height; j++ )
{
ptr = data + width * (height - j - 1);
for( int i = 0; i < width; i++ )
{
// Read a pixel
uint32_t pixel = 0;
fread( &pixel, 3, 1, file );
*(ptr++) = U32( &pixel );
}
fseek( file, pad, SEEK_CUR );
}
return (char*)data;
}
default:
msg_Warn( p_intf, "%s : %d bbp not supported !", fileName.c_str(),
bpp );
return NULL;
}
}
//---------------------------------------------------------------------------
#endif #endif
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* x11_bitmap.h: X11 implementation of the Bitmap class * x11_bitmap.h: X11 implementation of the Bitmap class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: x11_bitmap.h,v 1.1 2003/04/28 14:32:57 asmax Exp $ * $Id: x11_bitmap.h,v 1.2 2003/05/18 11:25:00 asmax Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -42,15 +42,16 @@ class Graphics; ...@@ -42,15 +42,16 @@ class Graphics;
class X11Bitmap : public Bitmap class X11Bitmap : public Bitmap
{ {
private: private:
intf_thread_t *p_intf;
Display *display; Display *display;
Pixmap Bmp; XImage *Bmp;
public: public:
// Constructors // Constructors
X11Bitmap( intf_thread_t *p_intf, string FileName, int AColor ); X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor );
X11Bitmap( intf_thread_t *p_intf, Graphics *from, int x, int y, X11Bitmap( intf_thread_t *_p_intf, Graphics *from, int x, int y,
int w, int h, int AColor ); int w, int h, int AColor );
X11Bitmap( intf_thread_t *p_intf, Bitmap *c ); X11Bitmap( intf_thread_t *_p_intf, Bitmap *c );
// Destructor // Destructor
virtual ~X11Bitmap(); virtual ~X11Bitmap();
...@@ -61,6 +62,9 @@ class X11Bitmap : public Bitmap ...@@ -61,6 +62,9 @@ class X11Bitmap : public Bitmap
virtual int GetBmpPixel( int x, int y ); virtual int GetBmpPixel( int x, int y );
virtual void SetBmpPixel( int x, int y, int color ); virtual void SetBmpPixel( int x, int y, int color );
protected:
char *LoadFromFile( string fileName, int depth, int &width, int &height);
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* x11_run.cpp: * x11_run.cpp:
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: x11_run.cpp,v 1.3 2003/05/13 20:36:29 asmax Exp $ * $Id: x11_run.cpp,v 1.4 2003/05/18 11:25:00 asmax Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
//--- WWWINDOWS ------------------------------------------------------------- //--- WWWINDOWS -------------------------------------------------------------
#ifndef BASIC_SKINS
#include <wx/wx.h> #include <wx/wx.h>
#endif
//--- VLC ------------------------------------------------------------------- //--- VLC -------------------------------------------------------------------
#include <vlc/intf.h> #include <vlc/intf.h>
...@@ -44,7 +46,9 @@ ...@@ -44,7 +46,9 @@
#include "../os_theme.h" #include "../os_theme.h"
#include "../src/skin_common.h" #include "../src/skin_common.h"
#include "../src/vlcproc.h" #include "../src/vlcproc.h"
#ifndef BASIC_SKINS
#include "../../wxwindows/wxwindows.h" #include "../../wxwindows/wxwindows.h"
#endif
// include the icon graphic // include the icon graphic
#include "share/vlc32x32.xpm" #include "share/vlc32x32.xpm"
...@@ -60,6 +64,7 @@ int SkinManage( intf_thread_t *p_intf ); ...@@ -60,6 +64,7 @@ int SkinManage( intf_thread_t *p_intf );
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Local classes declarations. // Local classes declarations.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#ifndef BASIC_SKINS
class Instance: public wxApp class Instance: public wxApp
{ {
public: public:
...@@ -72,6 +77,7 @@ public: ...@@ -72,6 +77,7 @@ public:
private: private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
}; };
#endif
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -200,6 +206,7 @@ private: ...@@ -200,6 +206,7 @@ private:
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Implementation of Instance class // Implementation of Instance class
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#ifndef BASIC_SKINS
Instance::Instance( ) Instance::Instance( )
{ {
} }
...@@ -229,7 +236,7 @@ bool Instance::OnInit() ...@@ -229,7 +236,7 @@ bool Instance::OnInit()
return TRUE; return TRUE;
} }
#endif
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -244,7 +251,7 @@ void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event ) ...@@ -244,7 +251,7 @@ void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
Window wnd = ((XAnyEvent *)event)->window; Window wnd = ((XAnyEvent *)event)->window;
fprintf(stderr,"event %d %x\n", event->type, wnd); // fprintf(stderr,"event %d %x\n", event->type, wnd);
// Create event to dispatch in windows // Create event to dispatch in windows
// Skin event // Skin event
...@@ -359,6 +366,9 @@ void OSRun( intf_thread_t *p_intf ) ...@@ -359,6 +366,9 @@ void OSRun( intf_thread_t *p_intf )
XNextEvent( display, event ); XNextEvent( display, event );
ProcessEvent( p_intf, proc, event ); ProcessEvent( p_intf, proc, event );
// kludge: add timer
SkinManage( p_intf );
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* x11_window.cpp: X11 implementation of the Window class * x11_window.cpp: X11 implementation of the Window class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: x11_window.cpp,v 1.2 2003/05/13 20:36:29 asmax Exp $ * $Id: x11_window.cpp,v 1.3 2003/05/18 11:25:00 asmax Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -289,7 +289,6 @@ void X11Window::RefreshFromImage( int x, int y, int w, int h ) ...@@ -289,7 +289,6 @@ void X11Window::RefreshFromImage( int x, int y, int w, int h )
*/ */
Drawable drawable = (( X11Graphics* )Image )->GetImage(); Drawable drawable = (( X11Graphics* )Image )->GetImage();
fprintf(stderr, "prout\n");
XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y ); XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
XSync( display, 0); XSync( display, 0);
/* /*
......
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