* x11_bitmap.cpp: X11 implementation of the Bitmap class
*****************************************************************************
* 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>
* Emmanuel Puig <karibu@via.ecp.fr>
#include "../os_theme.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( 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 )
{
+ p_intf = _p_intf;
+
// Find the 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;
+ 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
- int hotspotX, hotspotY;
- int rc = XReadBitmapFile( display, root, FileName.c_str(),
- (unsigned int*)&Width, (unsigned int*)&Height,
- &Bmp, &hotspotX, &hotspotY );
- if( rc != BitmapSuccess )
+/* if( rc != BitmapSuccess )
{
if( FileName != "" )
msg_Warn( p_intf, "Couldn't load bitmap: %s", FileName.c_str() );
Width = 0;
Height = 0;
- }
+ }*/
/* else
{
Width = gdk_pixbuf_get_width( Bmp );
}*/
}
//---------------------------------------------------------------------------
-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 )
{
+ p_intf = _p_intf;
/* Width = w;
Height = h;
AlphaColor = AColor;
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 )
{
+ p_intf = _p_intf;
/* HBITMAP HBuf;
// Copy attibutes
//---------------------------------------------------------------------------
X11Bitmap::~X11Bitmap()
{
- XFreePixmap( display, Bmp );
+ XDestroyImage( Bmp );
}
//---------------------------------------------------------------------------
void X11Bitmap::DrawBitmap( int x, int y, int w, int h, int xRef, int yRef,
Graphics *dest )
{
- if( Bmp )
- {
- Drawable destImg = ( (X11Graphics *)dest )->GetImage();
- GC destGC = ( (X11Graphics *)dest )->GetGC();
-
- XCopyArea( display, Bmp, destImg, destGC, x, y, w, h, xRef, yRef );
- }
+ Drawable destImg = ( (X11Graphics *)dest )->GetImage();
+ GC destGC = ( (X11Graphics *)dest )->GetGC();
+ XPutImage( display, destImg, destGC, Bmp, x, y, xRef, yRef, w, h );
}
//---------------------------------------------------------------------------
bool X11Bitmap::Hit( int x, int y)
// 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
* x11_bitmap.h: X11 implementation of the Bitmap class
*****************************************************************************
* 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>
*
class X11Bitmap : public Bitmap
{
private:
+ intf_thread_t *p_intf;
Display *display;
- Pixmap Bmp;
+ XImage *Bmp;
public:
// Constructors
- 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, string FileName, int AColor );
+ X11Bitmap( intf_thread_t *_p_intf, Graphics *from, int x, int y,
int w, int h, int AColor );
- X11Bitmap( intf_thread_t *p_intf, Bitmap *c );
+ X11Bitmap( intf_thread_t *_p_intf, Bitmap *c );
// Destructor
virtual ~X11Bitmap();
virtual int GetBmpPixel( int x, int y );
virtual void SetBmpPixel( int x, int y, int color );
+
+ protected:
+ char *LoadFromFile( string fileName, int depth, int &width, int &height);
};
//---------------------------------------------------------------------------
* x11_run.cpp:
*****************************************************************************
* 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>
*
#include <X11/Xlib.h>
//--- WWWINDOWS -------------------------------------------------------------
+#ifndef BASIC_SKINS
#include <wx/wx.h>
+#endif
//--- VLC -------------------------------------------------------------------
#include <vlc/intf.h>
#include "../os_theme.h"
#include "../src/skin_common.h"
#include "../src/vlcproc.h"
+#ifndef BASIC_SKINS
#include "../../wxwindows/wxwindows.h"
+#endif
// include the icon graphic
#include "share/vlc32x32.xpm"
//---------------------------------------------------------------------------
// Local classes declarations.
//---------------------------------------------------------------------------
+#ifndef BASIC_SKINS
class Instance: public wxApp
{
public:
private:
intf_thread_t *p_intf;
};
+#endif
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Implementation of Instance class
//---------------------------------------------------------------------------
+#ifndef BASIC_SKINS
Instance::Instance( )
{
}
return TRUE;
}
-
+#endif
//---------------------------------------------------------------------------
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
// Skin event
XNextEvent( display, event );
ProcessEvent( p_intf, proc, event );
+
+// kludge: add timer
+ SkinManage( p_intf );
}
}