]> git.sesse.net Git - vlc/commitdiff
* first BMP loader for X11 skins : it can only handle 24bbp uncompressed
authorCyril Deguet <asmax@videolan.org>
Sun, 18 May 2003 11:25:00 +0000 (11:25 +0000)
committerCyril Deguet <asmax@videolan.org>
Sun, 18 May 2003 11:25:00 +0000 (11:25 +0000)
  images, but it works !

modules/gui/skins/x11/x11_bitmap.cpp
modules/gui/skins/x11/x11_bitmap.h
modules/gui/skins/x11/x11_run.cpp
modules/gui/skins/x11/x11_window.cpp

index 3bcd88dd7e326851d47fd589701cc2541e2fd679..100dd3f43edb67990583163029604447da145832 100644 (file)
@@ -2,7 +2,7 @@
  * 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 );
@@ -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 )
 {
+    p_intf = _p_intf;
 /*    Width  = w;
     Height = h;
     AlphaColor = AColor;
@@ -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 );*/
 }
 //---------------------------------------------------------------------------
-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
@@ -138,19 +159,15 @@ X11Bitmap::X11Bitmap( intf_thread_t *p_intf, Bitmap *c )
 //---------------------------------------------------------------------------
 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)
@@ -190,5 +207,71 @@ void X11Bitmap::SetBmpPixel( int x, int y, int 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
index f4096b8be732c61911e4a3b265b9061da5149f6e..659e6685025a46bb492292f0a11b80e2e2972b1c 100644 (file)
@@ -2,7 +2,7 @@
  * 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>
  *
@@ -42,15 +42,16 @@ class Graphics;
 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();
@@ -61,6 +62,9 @@ class X11Bitmap : public Bitmap
 
         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);
 };
 //---------------------------------------------------------------------------
 
index 4ce3546001ce100336ce652772e4295130ad0f70..0711387aec7bb3be892e50e44cc149866bb6f356 100644 (file)
@@ -2,7 +2,7 @@
  * 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>
  *
@@ -28,7 +28,9 @@
 #include <X11/Xlib.h>
 
 //--- WWWINDOWS -------------------------------------------------------------
+#ifndef BASIC_SKINS
 #include <wx/wx.h>
+#endif
 
 //--- VLC -------------------------------------------------------------------
 #include <vlc/intf.h>
@@ -44,7 +46,9 @@
 #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"
@@ -60,6 +64,7 @@ int  SkinManage( intf_thread_t *p_intf );
 //---------------------------------------------------------------------------
 // Local classes declarations.
 //---------------------------------------------------------------------------
+#ifndef BASIC_SKINS
 class Instance: public wxApp
 {
 public:
@@ -72,6 +77,7 @@ public:
 private:
     intf_thread_t *p_intf;
 };
+#endif
 
 
 //---------------------------------------------------------------------------
@@ -200,6 +206,7 @@ private:
 //---------------------------------------------------------------------------
 // Implementation of Instance class
 //---------------------------------------------------------------------------
+#ifndef BASIC_SKINS
 Instance::Instance( )
 {
 }
@@ -229,7 +236,7 @@ bool Instance::OnInit()
 
     return TRUE;
 }
-
+#endif
 
 
 //---------------------------------------------------------------------------
@@ -244,7 +251,7 @@ void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
 
     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
@@ -359,6 +366,9 @@ void OSRun( intf_thread_t *p_intf )
         XNextEvent( display, event );
         
         ProcessEvent( p_intf, proc, event );
+
+// kludge: add timer
+        SkinManage( p_intf );
     }
     
 }
index 031b08b55dd796197c8456bfdf66f6d56deaa9f3..91a822a8dbc59b894abef435d93a2d127700784a 100644 (file)
@@ -2,7 +2,7 @@
  * x11_window.cpp: X11 implementation of the Window class
  *****************************************************************************
  * 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>
  *
@@ -289,7 +289,6 @@ void X11Window::RefreshFromImage( int x, int y, int w, int h )
 */ 
     Drawable drawable = (( X11Graphics* )Image )->GetImage();
     
-    fprintf(stderr, "prout\n");
     XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
     XSync( display, 0);
 /*