X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Freaddib.c;h=0e0e82379f1c6617a1d97f08fc00755f4c16558f;hb=e7f8539e60ea67d011a1452a9e59d0c942a98592;hp=df327f833884f0087889d73a4e7d3a461ec8ec18;hpb=7734d07b64a52a381d4ccfc857851b96706b3fec;p=hengband%2Fhengband.git diff --git a/src/readdib.c b/src/readdib.c index df327f833..0e0e82379 100644 --- a/src/readdib.c +++ b/src/readdib.c @@ -1,9 +1,9 @@ -/* File: readbits.c */ - -/* - * This package provides a routine to read a DIB file and set up the - * device dependent version of the image. - * +/*! + * @file readdib.c + * @brief Windows用ビットマップファイル読み込み処理パッケージ / + * This package provides a routine to read a DIB file and set up the device dependent version of the image. + * @date 2014/08/08 + * @author * This file has been modified for use with "Angband 2.8.2" * * COPYRIGHT: @@ -15,6 +15,9 @@ * any way you find useful, provided that you agree that * Microsoft has no warranty obligations or liability for any * Sample Application Files which are modified. + * @details + * mind.cとあるが実際には超能力者、練気術師、狂戦士、鏡使い、忍者までの + * 特殊技能を揃えて実装している。 */ #include @@ -32,11 +35,11 @@ #endif /* - * Make sure "huge" is legal XXX XXX XXX + * Make sure "huge" is legal */ #undef huge #ifdef WIN32 -# define huge /* oops */ +#define huge #endif @@ -48,16 +51,19 @@ #endif -/* - * Number of bytes to be read during each read operation +/*! + * 一度にファイルから読み込むデータ量 / Number of bytes to be read during each read operation */ #define MAXREAD 32768 -/* - * Private routine to read more than 64K at a time - * - * Reads data in steps of 32k till all the data has been read. - * +/*! + * @brief 32KBのデータ読み取りを繰り返すことで、64KB以上のデータを一度に読み取るサブルーチン + * Private routine to read more than 64K at a time Reads data in steps of 32k till all the data has been read. + * @param fh ファイルヘッダ + * @param pv 読み取りポインタ + * @param ul 読み込むバイト数 + * @return + * 取得できたデータ量をバイトで返す。0ならば何らかのエラー。 * Returns number of bytes requested, or zero if something went wrong. */ static DWORD PASCAL lread(int fh, VOID FAR *pv, DWORD ul) @@ -72,15 +78,17 @@ static DWORD PASCAL lread(int fh, VOID FAR *pv, DWORD ul) ul -= MAXREAD; hp += MAXREAD; } - if (_lread(fh, (LPSTR)hp, (WORD)ul) != (WORD)ul) + if (_lread(fh, (LPSTR)hp, (WORD)ul) != ul) return 0; return ulT; } - -/* +/*! + * @brief BITMAPINFOHEADERを取得してカラーテーブルを基本としたパレットを作成する。 * Given a BITMAPINFOHEADER, create a palette based on the color table. - * + * @param lpInfo BITMAPINFOHEADERのポインタ + * @return + * パレットの参照を返す。NULLならばエラー。 * Returns the handle of a palette, or zero if something went wrong. */ static HPALETTE PASCAL NEAR MakeDIBPalette(LPBITMAPINFOHEADER lpInfo) @@ -97,7 +105,7 @@ static HPALETTE PASCAL NEAR MakeDIBPalette(LPBITMAPINFOHEADER lpInfo) if (lpInfo->biClrUsed) { npPal = (PLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) + - (WORD)lpInfo->biClrUsed * sizeof(PALETTEENTRY)); + (WORD)lpInfo->biClrUsed * sizeof(PALETTEENTRY)); if (!npPal) return(FALSE); @@ -108,7 +116,7 @@ static HPALETTE PASCAL NEAR MakeDIBPalette(LPBITMAPINFOHEADER lpInfo) lpRGB = (RGBQUAD FAR *)((LPSTR)lpInfo + lpInfo->biSize); /* copy colors from the color table to the LogPalette structure */ - for (i = 0; i < lpInfo->biClrUsed; i++, lpRGB++) + for (i = 0; i < (WORD)lpInfo->biClrUsed; i++, lpRGB++) { npPal->palPalEntry[i].peRed = lpRGB->rgbRed; npPal->palPalEntry[i].peGreen = lpRGB->rgbGreen; @@ -133,16 +141,23 @@ static HPALETTE PASCAL NEAR MakeDIBPalette(LPBITMAPINFOHEADER lpInfo) } -/* +/*! + * @brief + * ビットマップファイルを受け取り、画像のデバイス依存の描画のために使われる共通パレットとビットマップを作成する * Given a DIB, create a bitmap and corresponding palette to be used for a * device-dependent representation of the image. - * + * @param hDC デバイスコンテキストハンドル + * @param hDIB ビットマップ画像ハンドル + * @param phPal パレット取得ハンドル + * @param phBitmap ビットマップ取得ハンドル + * @return + * 成功したならばTRUEを返す。失敗の場合FALSE。 * Returns TRUE on success (phPal and phBitmap are filled with appropriate * handles. Caller is responsible for freeing objects) and FALSE on failure * (unable to create objects, both pointer are invalid). */ static BOOL NEAR PASCAL MakeBitmapAndPalette(HDC hDC, HANDLE hDIB, - HPALETTE * phPal, HBITMAP * phBitmap) + HPALETTE * phPal, HBITMAP * phBitmap) { LPBITMAPINFOHEADER lpInfo; BOOL result = FALSE; @@ -158,9 +173,9 @@ static BOOL NEAR PASCAL MakeBitmapAndPalette(HDC hDC, HANDLE hDIB, RealizePalette(hDC); lpBits = ((LPSTR)lpInfo + (WORD)lpInfo->biSize + - (WORD)lpInfo->biClrUsed * sizeof(RGBQUAD)); + (WORD)lpInfo->biClrUsed * sizeof(RGBQUAD)); hBitmap = CreateDIBitmap(hDC, lpInfo, CBM_INIT, lpBits, - (LPBITMAPINFO)lpInfo, DIB_RGB_COLORS); + (LPBITMAPINFO)lpInfo, DIB_RGB_COLORS); SelectPalette(hDC, hOldPal, TRUE); RealizePalette(hDC); @@ -181,14 +196,24 @@ static BOOL NEAR PASCAL MakeBitmapAndPalette(HDC hDC, HANDLE hDIB, -/* +/*! + * @brief + * ビットマップファイルを読み込み、BITMAPINFO構造体にハンドルを取得する。 * Reads a DIB from a file, obtains a handle to its BITMAPINFO struct, and * loads the DIB. Once the DIB is loaded, the function also creates a bitmap * and palette out of the DIB for a device-dependent form. - * + * device-dependent representation of the image. + * @param hWnd ウィンドウハンドル + * @param lpFileName 読み込むビットマップファイル + * @param pInfo 取得情報を補完するビットマップ情報構造体ポインタ + * @return * Returns TRUE if the DIB is loaded and the bitmap/palette created, in which * case, the DIBINIT structure pointed to by pInfo is filled with the appropriate * handles, and FALSE if something went wrong. + * @details + * Reads a DIB from a file, obtains a handle to its BITMAPINFO struct, and + * loads the DIB. Once the DIB is loaded, the function also creates a bitmap + * and palette out of the DIB for a device-dependent form. */ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo) { @@ -213,7 +238,7 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo) } pInfo->hDIB = GlobalAlloc(GHND, (DWORD)(sizeof(BITMAPINFOHEADER) + - 256 * sizeof(RGBQUAD))); + 256 * sizeof(RGBQUAD))); if (!pInfo->hDIB) return (FALSE); @@ -248,7 +273,8 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo) goto ErrExit; } - if (!(nNumColors = (WORD)lpbi->biClrUsed)) + nNumColors = (WORD)lpbi->biClrUsed; + if (!nNumColors) { /* no color table for 24-bit, default size otherwise */ if (lpbi->biBitCount != 24) @@ -262,7 +288,7 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo) if (lpbi->biSizeImage == 0) { lpbi->biSizeImage = (((((lpbi->biWidth * (DWORD)lpbi->biBitCount) + 31) & ~31) >> 3) - * lpbi->biHeight); + * lpbi->biHeight); } /* otherwise wouldn't work with 16 color bitmaps -- S.K. */ @@ -322,7 +348,7 @@ BOOL ReadDIB(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo) hDC = GetDC(hWnd); if (!MakeBitmapAndPalette(hDC, pInfo->hDIB, &((HPALETTE)pInfo->hPalette), - &((HBITMAP)pInfo->hBitmap))) + &((HBITMAP)pInfo->hBitmap))) { ReleaseDC(hWnd,hDC); goto ErrExit2;