///////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/*
* This file is part of MiniGUI, a mature cross-platform windowing
* and Graphics User Interface (GUI) support system for embedded systems
* and smart IoT devices.
*
* Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd.
* Copyright (C) 1998~2002, WEI Yongming
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Or,
*
* As this program is a library, any link to this program must follow
* GNU General Public License version 3 (GPLv3). If you cannot accept
* GPLv3, you need to be licensed from FMSoft.
*
* If you have got a commercial license of this program, please use it
* under the terms and conditions of the commercial license.
*
* For more information about the commercial license, please refer to
* .
*/
static HCURSOR load_cursor_from_file (const char* filename)
{
FILE* fp;
WORD16 wTemp;
int w, h, xhot, yhot, colornum;
#if 0
DWORD32 size;
#endif
DWORD32 offset, imagesize, imagew, imageh;
BYTE* image;
HCURSOR csr = 0;
if (!(fp = fopen(filename, "rb")))
return 0;
fseek(fp, sizeof(WORD16), SEEK_SET);
/* the cbType of struct CURSORDIR. */
wTemp = MGUI_ReadLE16FP (fp);
if(wTemp != 2) {
_WRN_PRINTF ("LoadCursorFromFile: bad file type: %d\n", wTemp);
goto error;
}
/* skip the cdCount of struct CURSORDIR, we always use the first cursor. */
fseek(fp, sizeof(WORD16), SEEK_CUR);
/* cursor info, read the members of struct CURSORDIRENTRY. */
w = fgetc (fp); /* the width of first cursor. */
h = fgetc (fp); /* the height of first cursor. */
if (w != CURSORWIDTH || h != CURSORHEIGHT) {
_WRN_PRINTF ("LoadCursorFromFile: bad first cursor width (%d) and height (%d)\n", w, h);
goto error;
}
fseek(fp, sizeof(BYTE)*2, SEEK_CUR); /* skip bColorCount and bReserved. */
wTemp = MGUI_ReadLE16FP (fp);
xhot = wTemp;
wTemp = MGUI_ReadLE16FP (fp);
yhot = wTemp;
#if 0
size = MGUI_ReadLE32FP (fp);
#else
fseek (fp, sizeof(DWORD32), SEEK_CUR); /* skip size. */
#endif
offset = MGUI_ReadLE32FP (fp);
/* read the cursor image info. */
fseek(fp, offset, SEEK_SET);
fseek(fp, sizeof(DWORD32), SEEK_CUR); /* skip the biSize member. */
imagew = MGUI_ReadLE32FP (fp);
imageh = MGUI_ReadLE32FP (fp);
if (imagew != CURSORWIDTH || imageh != (CURSORHEIGHT*2)) {
_WRN_PRINTF ("LoadCursorFromFile: bad cursor image width (%d) and height (%d)\n", imagew, imageh);
goto error;
}
/* check the biPlanes member; */
wTemp = MGUI_ReadLE16FP (fp);
if (wTemp != 1) {
_WRN_PRINTF ("LoadCursorFromFile: bad planes (%d)\n", wTemp);
goto error;
}
/* check the biBitCount member; */
wTemp = MGUI_ReadLE16FP (fp);
if (wTemp > 4) {
_WRN_PRINTF ("LoadCursorFromFile: bad bit count (%d)\n", wTemp);
goto error;
}
colornum = (int)wTemp;
fseek(fp, sizeof(DWORD32), SEEK_CUR); /* skip the biCompression members. */
imagesize = MGUI_ReadLE32FP (fp);
/* skip the rest members and the color table. */
fseek(fp, sizeof(DWORD32)*4 + sizeof(BYTE)*(4< 4) goto error;
colornum = wTemp;
/* skip the biCompression members. */
p += sizeof (DWORD32);
imagesize = MGUI_ReadLE32Mem (&p);
/* skip the rest members and the color table. */
p += sizeof(DWORD32)*4 + sizeof(BYTE)*(4<