1 /*****************************************************************************
2 * x11_bitmap.cpp: X11 implementation of the Bitmap class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_bitmap.cpp,v 1.11 2003/06/09 12:33:16 asmax Exp $
7 * Authors: Cyril Deguet <asmax@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
23 *****************************************************************************/
27 //--- X11 -------------------------------------------------------------------
29 #include <X11/Xutil.h>
32 //--- VLC -------------------------------------------------------------------
35 //--- SKIN ------------------------------------------------------------------
36 #include "../os_api.h"
37 #include "../src/graphics.h"
38 #include "x11_graphics.h"
39 #include "../src/bitmap.h"
40 #include "x11_bitmap.h"
41 #include "../src/theme.h"
42 #include "../os_theme.h"
43 #include "../src/skin_common.h"
47 // macros to read little endian numbers
48 #define U16( p ) ( ((uint8_t*)(p))[0] | ((uint8_t*)(p))[1] << 8 )
49 #define U32( p ) ( U16( p ) | ((uint8_t*)(p))[2] << 16 | ((uint8_t*)(p))[3] << 24 )
51 //---------------------------------------------------------------------------
53 //---------------------------------------------------------------------------
54 X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor )
55 : Bitmap( p_intf, FileName, AColor )
60 display = p_intf->p_sys->display;
61 int screen = DefaultScreen( display );
62 Screen *screenptr = DefaultScreenOfDisplay( display );
63 Visual *visual = DefaultVisualOfScreen( screenptr );
73 AlphaColor = (AColor & 0xff) << 16 | (AColor & 0xff00) |
74 (AColor & 0xff0000) >> 16;
77 imlib_context_set_display( display );
78 imlib_context_set_visual( visual );
79 imlib_context_set_colormap( DefaultColormap( display, screen ) );
80 imlib_context_set_dither( 1 );
81 imlib_context_set_blend( 1 );
83 Img = imlib_load_image_immediately( FileName.c_str() );
84 imlib_context_set_image( Img );
85 Width = imlib_image_get_width();
86 Height = imlib_image_get_height();
89 DATA32 *data = imlib_image_get_data();
91 for( int j = 0; j < Height; j++)
93 for( int i = 0; i < Width; i++)
95 if( AlphaColor != 0 && *ptr == 0xff000000 )
97 // Avoid transparency for black pixels
100 else if( (*ptr & 0xffffff) == AlphaColor )
107 imlib_image_set_has_alpha( 1 );
108 imlib_image_set_irrelevant_alpha( 0 );
109 imlib_image_put_back_data( data );
112 //---------------------------------------------------------------------------
113 X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, Graphics *from, int x, int y,
114 int w, int h, int AColor ) : Bitmap( p_intf, from, x, y, w, h, AColor )
121 HDC fromDC = ( (X11Graphics *)from )->GetImageHandle();
124 bmpDC = CreateCompatibleDC( fromDC );
125 HBmp = CreateCompatibleBitmap( fromDC, Width, Height );
126 SelectObject( bmpDC, HBmp );
127 DeleteObject( HBmp );
128 BitBlt( bmpDC, 0, 0, Width, Height, fromDC, x, y, SRCCOPY );*/
130 //---------------------------------------------------------------------------
131 X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, Bitmap *c )
132 : Bitmap( p_intf, c )
138 c->GetSize( Width, Height );
139 AlphaColor = c->GetAlphaColor();
142 bmpDC = CreateCompatibleDC( NULL );
143 HBuf = CreateCompatibleBitmap( bmpDC, Width, Height );
144 SelectObject( bmpDC, HBuf );
146 BitBlt( bmpDC, 0, 0, Width, Height, ( (X11Bitmap *)c )->GetBmpDC(),
148 DeleteObject( HBuf );*/
150 //---------------------------------------------------------------------------
151 X11Bitmap::~X11Bitmap()
156 imlib_context_set_image( Img );
161 //---------------------------------------------------------------------------
162 void X11Bitmap::DrawBitmap( int x, int y, int w, int h, int xRef, int yRef,
168 Drawable destImg = ( (X11Graphics *)dest )->GetImage();
169 imlib_context_set_image( Img );
170 imlib_context_set_drawable( destImg );
171 imlib_render_image_part_on_drawable_at_size( x, y, w, h, xRef, yRef, w, h );
175 //---------------------------------------------------------------------------
176 bool X11Bitmap::Hit( int x, int y)
178 int c = GetBmpPixel( x, y );
180 if( c == -1 || (unsigned int)c == AlphaColor )
185 //---------------------------------------------------------------------------
186 int X11Bitmap::GetBmpPixel( int x, int y )
188 if( !Img || x < 0 || x >= Width || y < 0 || y >= Height )
193 int rowstride, offset;
196 rowstride = gdk_pixbuf_get_rowstride( Bmp );
197 pixels = gdk_pixbuf_get_pixels( Bmp );
198 has_alpha = gdk_pixbuf_get_has_alpha( Bmp );
200 offset = y * rowstride + ( x * (has_alpha ? 4 : 3) );
202 int r = pixels [offset];
203 int g = pixels [offset + 1] << 8;
204 int b = pixels [offset + 2] << 16;
208 //---------------------------------------------------------------------------
209 void X11Bitmap::SetBmpPixel( int x, int y, int color )
211 // SetPixelV( bmpDC, x, y, color );
213 //---------------------------------------------------------------------------