sdl

FORK: Simple Directmedia Layer
git clone https://git.neptards.moe/neptards/sdl.git
Log | Files | Refs

SDL_os2util.c (3820B)


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