1
/*****************************************************************************
2
* win32_bitmap.cpp: Win32 implementation of the Bitmap class
3
*****************************************************************************
4
* Copyright (C) 2003 VideoLAN
5
* $Id: win32_bitmap.cpp 6961 2004-03-05 17:34:23Z sam $
7
* Authors: Olivier Teuli�re <ipkiss@via.ecp.fr>
8
* Emmanuel Puig <karibu@via.ecp.fr>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24
*****************************************************************************/
28
//--- WIN32 -----------------------------------------------------------------
32
//--- VLC -------------------------------------------------------------------
35
//--- SKIN ------------------------------------------------------------------
36
#include "../os_api.h"
37
#include "../src/graphics.h"
38
#include "win32_graphics.h"
39
#include "../src/bitmap.h"
40
#include "win32_bitmap.h"
41
#include "../src/skin_common.h"
45
//---------------------------------------------------------------------------
47
//---------------------------------------------------------------------------
48
Win32Bitmap::Win32Bitmap( intf_thread_t *p_intf, string FileName, int AColor )
49
: Bitmap( p_intf, FileName, AColor )
56
// Create image from file if it exists
57
HBitmap = (HBITMAP) LoadImage( NULL, FileName.c_str(), IMAGE_BITMAP,
58
0, 0, LR_LOADFROMFILE );
62
msg_Warn( p_intf, "Couldn't load bitmap: %s", FileName.c_str() );
64
HBitmap = CreateBitmap( 0, 0, 1, 32, NULL );
67
// Create device context
68
bmpDC = CreateCompatibleDC( NULL );
69
SelectObject( bmpDC, HBitmap );
72
GetObject( HBitmap, sizeof( Bmp ), &Bmp );
74
Height = Bmp.bmHeight;
76
// If alpha color is not 0, then change 0 color to non black color to avoid
77
// window transparency
78
if( (int)AlphaColor != OSAPI_GetNonTransparentColor( 0 ) )
80
bufDC = CreateCompatibleDC( bmpDC );
81
HBuf = CreateCompatibleBitmap( bmpDC, Width, Height );
82
SelectObject( bufDC, HBuf );
85
HBRUSH Brush = CreateSolidBrush( OSAPI_GetNonTransparentColor( 0 ) );
90
FillRect( bufDC, r, Brush );
91
DeleteObject( Brush );
94
if( p_intf->p_sys->TransparentBlt && IS_WINNT )
96
// This function contains a memory leak on win95/win98
97
p_intf->p_sys->TransparentBlt( bufDC, 0, 0, Width, Height,
98
bmpDC, 0, 0, Width, Height, 0 );
102
BitBlt( bufDC, 0, 0, Width, Height, bmpDC, 0, 0, SRCCOPY );
105
BitBlt( bmpDC, 0, 0, Width, Height, bufDC, 0, 0, SRCCOPY );
107
DeleteObject( HBuf );
111
DeleteObject( HBitmap );
113
//---------------------------------------------------------------------------
114
Win32Bitmap::Win32Bitmap( intf_thread_t *p_intf, Graphics *from, int x, int y,
115
int w, int h, int AColor ) : Bitmap( p_intf, from, x, y, w, h, AColor )
121
HDC fromDC = ( (Win32Graphics *)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
Win32Bitmap::Win32Bitmap( intf_thread_t *p_intf, Bitmap *c )
132
: Bitmap( p_intf, c )
137
c->GetSize( Width, Height );
138
AlphaColor = c->GetAlphaColor();
141
bmpDC = CreateCompatibleDC( NULL );
142
HBuf = CreateCompatibleBitmap( bmpDC, Width, Height );
143
SelectObject( bmpDC, HBuf );
145
BitBlt( bmpDC, 0, 0, Width, Height, ( (Win32Bitmap *)c )->GetBmpDC(),
147
DeleteObject( HBuf );
149
//---------------------------------------------------------------------------
150
Win32Bitmap::~Win32Bitmap()
154
//---------------------------------------------------------------------------
155
void Win32Bitmap::DrawBitmap( int x, int y, int w, int h, int xRef, int yRef,
158
HDC destDC = ( (Win32Graphics *)dest )->GetImageHandle();
160
if( p_intf->p_sys->TransparentBlt && IS_WINNT )
162
// This function contains a memory leak on win95/win98
163
p_intf->p_sys->TransparentBlt( destDC, xRef, yRef, w, h,
164
bmpDC, x, y, w, h, AlphaColor );
168
BitBlt( destDC, xRef, yRef, w, h, bmpDC, x, y, SRCCOPY );
171
//---------------------------------------------------------------------------
172
bool Win32Bitmap::Hit( int x, int y)
174
unsigned int c = GetPixel( bmpDC, x, y );
175
if( c == AlphaColor || c == CLR_INVALID )
181
//---------------------------------------------------------------------------
182
int Win32Bitmap::GetBmpPixel( int x, int y )
184
return GetPixel( bmpDC, x, y );
186
//---------------------------------------------------------------------------
187
void Win32Bitmap::SetBmpPixel( int x, int y, int color )
189
SetPixelV( bmpDC, x, y, color );
191
//---------------------------------------------------------------------------