Repository navigation
Expand file tree
/
Copy pathSDL_os2util.c
More file actions
114 lines (95 loc) · 3.77 KB
/
Copy pathSDL_os2util.c
File metadata and controls
114 lines (95 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifdef SDL_VIDEO_DRIVER_OS2
#include "SDL_os2util.h"
HPOINTER utilCreatePointer(SDL_Surface *surface, ULONG ulHotX, ULONG ulHotY)
{
HBITMAP hbm;
BITMAPINFOHEADER2 bmih;
BITMAPINFO bmi;
HPS hps;
PULONG pulBitmap;
PULONG pulDst, pulSrc, pulDstMask;
ULONG ulY, ulX;
HPOINTER hptr = NULLHANDLE;
if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
debug_os2("Image format should be SDL_PIXELFORMAT_ARGB8888");
return NULLHANDLE;
}
pulBitmap = (PULONG) SDL_malloc(surface->h * surface->w * 2 * sizeof(ULONG));
if (!pulBitmap) {
SDL_OutOfMemory();
return NULLHANDLE;
}
/* pulDst - last line of surface (image) part of the result bitmap */
pulDst = &pulBitmap[ (surface->h - 1) * surface->w ];
/* pulDstMask - last line of mask part of the result bitmap */
pulDstMask = &pulBitmap[ (2 * surface->h - 1) * surface->w ];
/* pulSrc - first line of source image */
pulSrc = (PULONG)surface->pixels;
for (ulY = 0; ulY < surface->h; ulY++) {
for (ulX = 0; ulX < surface->w; ulX++) {
if ((pulSrc[ulX] & 0xFF000000) == 0) {
pulDst[ulX] = 0;
pulDstMask[ulX] = 0xFFFFFFFF;
} else {
pulDst[ulX] = pulSrc[ulX] & 0xFFFFFF;
pulDstMask[ulX] = 0;
}
}
/* Set image and mask pointers on one line up */
pulDst -= surface->w;
pulDstMask -= surface->w;
/* Set source image pointer to the next line */
pulSrc = (PULONG) (((PCHAR)pulSrc) + surface->pitch);
}
/* Create system bitmap object. */
SDL_zero(bmih);
SDL_zero(bmi);
bmih.cbFix = sizeof(BITMAPINFOHEADER2);
bmih.cx = surface->w;
bmih.cy = 2 * surface->h;
bmih.cPlanes = 1;
bmih.cBitCount = 32;
bmih.ulCompression = BCA_UNCOMP;
bmih.cbImage = bmih.cx * bmih.cy * 4;
bmi.cbFix = sizeof(BITMAPINFOHEADER);
bmi.cx = bmih.cx;
bmi.cy = bmih.cy;
bmi.cPlanes = 1;
bmi.cBitCount = 32;
hps = WinGetPS(HWND_DESKTOP);
hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)&bmih, CBM_INIT,
(PBYTE)pulBitmap, (PBITMAPINFO2)&bmi);
if (hbm == GPI_ERROR) {
debug_os2("GpiCreateBitmap() failed");
} else {
/* Create a system pointer object. */
hptr = WinCreatePointer(HWND_DESKTOP, hbm, TRUE, ulHotX, ulHotY);
if (hptr == NULLHANDLE) {
debug_os2("WinCreatePointer() failed");
}
}
GpiDeleteBitmap(hbm);
WinReleasePS(hps);
SDL_free(pulBitmap);
return hptr;
}
#endif /* SDL_VIDEO_DRIVER_OS2 */
/* vi: set ts=4 sw=4 expandtab: */