55#define WIDTH_BYTES_ALIGN32(cx, bpp) ((((cx) * (bpp) + 31) & ~31) >> 3)
88 colors =
max ? (1 <<
info->bmiHeader.biBitCount) :
info->bmiHeader.biClrUsed;
91 if (!colors && (
info->bmiHeader.biBitCount <= 8))
92 colors = 1 <<
info->bmiHeader.biBitCount;
127 Info->bmiHeader.biWidth *
Info->bmiHeader.biPlanes,
128 Info->bmiHeader.biBitCount) * ScanLines;
132 Ret =
Info->bmiHeader.biSizeImage;
170 *planes =
header->biPlanes;
189 if (
header->biSize ==
sizeof(BITMAPV5HEADER))
191 BITMAPV5HEADER *v5hdr = (BITMAPV5HEADER *)
header;
192 *
width = v5hdr->bV5Width;
193 *
height = v5hdr->bV5Height;
194 *planes = v5hdr->bV5Planes;
195 *
bpp = v5hdr->bV5BitCount;
196 *
compr = v5hdr->bV5Compression;
197 *
size = v5hdr->bV5SizeImage;
200 DPRINT(
"(%lu): wrong size for header\n",
header->biSize);
254 UINT ConvertedInfoSize;
286 if (BitmapInfo != pConvertedInfo)
287 RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
331 if ((pbm->bmWidthBytes != 0) && (!(pbm->bmWidthBytes & 1)))
439 return NtGdiGetDIBitsInternal(
hDC,
hbmp, uStartScan, cScanLines, lpvBits, lpbmi, uUsage,
440 cjBmpScanSize, cjInfoSize);
457 WORD Planes, BitsPerPixel;
459 UINT cjBmpScanSize = 0;
487 if (pbmiConverted ==
NULL)
489 DPRINT1(
"CBM_CREATDIB needs a BITMAPINFO!\n");
496 DPRINT1(
"Invalid ColorUse: %lu\n", ColorUse);
533 DPRINT1(
"DIB_GetBitmapInfo failed!\n");
541 DPRINT1(
"Invalid compression: %lu!\n", Compression);
548 DPRINT1(
"Invalid compression: %lu!\n", Compression);
556 DPRINT1(
"Invalid ColorUse: %lu\n", ColorUse);
576 DPRINT(
"pBMI %p, Size bpp %u, dibsize %d, Conv %u, BSS %u\n",
577 Data, BitsPerPixel, DibSize, cjInfoSize, cjBmpScanSize);
599 if ((pbmiConverted !=
NULL) && (pbmiConverted !=
Data))
601 RtlFreeHeap(RtlGetProcessHeap(), 0, pbmiConverted);
621 HDC hDCc, SavehDC, nhDC;
624 HPALETTE hPal =
NULL;
636 if (lpbmi->bmiHeader.biCompression ==
BI_JPEG
637 || lpbmi->bmiHeader.biCompression ==
BI_PNG)
682 dwWidth = lpbmi->bmiHeader.biWidth;
687 cScanLines, (
void *) lpvBits, (
LPBITMAPINFO) lpbmi, fuColorUse);
725 UINT ConvertedInfoSize;
727 UINT cjBmpScanSize = 0;
735 #define MaxScanLines 1000
736 #define MaxHeight 2000
737 #define MaxSourceHeight 2000
738 #define IS_ALIGNED(Pointer, Alignment) \
739 (((ULONG_PTR)(void *)(Pointer)) % (Alignment) == 0)
741 if (!ScanLines || !lpbmi || !Bits)
744 DPRINT(
"ScanLines %d Height %d Width %d biHeight %d biWidth %d\n"
745 " lpbmi '%p' ColorUse '%d' SizeImage '%d' StartScan %d\n"
746 " biCompression '%d' biBitCount '%d'\n",
747 ScanLines,
Height,
Width, lpbmi->bmiHeader.biHeight,
748 lpbmi->bmiHeader.biWidth, lpbmi, ColorUse,
749 lpbmi->bmiHeader.biSizeImage, StartScan,
750 lpbmi->bmiHeader.biCompression, lpbmi->bmiHeader.biBitCount);
752 if (lpbmi->bmiHeader.biWidth < 0)
770 if ((StartScan > bmiHeight) && (ScanLines > bmiHeight))
772 DPRINT(
"Returning ScanLines of '%d'\n", ScanLines);
773 LinesCopied = ScanLines;
790 if (StartScan <= YSrc + bmiHeight)
796 ScanLines = bmiHeight;
800 if (StartScan >= bmiHeight)
805 if (!top_down && ScanLines > bmiHeight - StartScan)
807 ScanLines = bmiHeight - StartScan;
809 src_y = StartScan + ScanLines - (YSrc +
Height);
813 if ((src_y < 0 || src_y >= (
INT)ScanLines) &&
816 LinesCopied = ScanLines;
821 LinesCopied = ScanLines + StartScan;
826 LinesCopied = ScanLines - src_y;
829 else if (src_y < 0 || src_y >= (
INT)ScanLines)
831 if (lpbmi->bmiHeader.biHeight < 0 &&
834 ScanLines = lpbmi->bmiHeader.biHeight - StartScan;
836 DPRINT(
"Returning ScanLines of '%d'\n", ScanLines);
837 LinesCopied = ScanLines;
842 LinesCopied = ScanLines;
925 DPRINT1(
"SetDIBitsToDevice fail to read BitMapInfo: %p or Bits: %p & Size: %u\n",
926 pConvertedInfo, Bits, cjBmpScanSize);
928 DPRINT(
"SetDIBitsToDevice Allocate Bits %u!!!\n", cjBmpScanSize);
933 DPRINT1(
"SetDIBitsToDevice called on invalid DC %p (not owned?)\n",
hdc);
948 ScanLines =
min(ScanLines,
952 if (YDest >= 0 && YSrc > 0 && bmiHeight <=
MaxHeight)
967 if (!
NT_SUCCESS(RtlULongMult(cjWidth,
max(ScanLines, LinesCopied), &cjBits)))
969 DPRINT1(
"Overflow calculating size: cjWidth %lu, ScanLines %lu\n",
970 cjWidth,
max(ScanLines, LinesCopied));
977 DPRINT(
"Buffer is too small, required: %lu, got %lu\n",
994 StartScan, ScanLines, (
LPBYTE) pvSafeBits,
996 cjBmpScanSize, ConvertedInfoSize,
1003 LinesCopied = ScanLines;
1009 LinesCopied = ScanLines;
1011 LinesCopied = ScanLines - src_y;
1017 LinesCopied = bmiHeight;
1023 (YDest >= 0 && src_y < -ScanLines))
1025 LinesCopied = ScanLines + src_y;
1029 LinesCopied = ScanLines;
1034 if (Bits != pvSafeBits)
1036 if (lpbmi != pConvertedInfo)
1037 RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
1065 UINT ConvertedInfoSize = 0;
1066 INT LinesCopied = 0;
1067 UINT cjBmpScanSize = 0;
1071 DPRINT(
"StretchDIBits %p : %p : %u\n", lpBits, lpBitsInfo,
iUsage);
1093 if (!pConvertedInfo)
1119 DPRINT1(
"StretchDIBits fail to read BitMapInfo: %p or Bits: %p & Size: %u\n",
1120 pConvertedInfo, lpBits, cjBmpScanSize);
1122 DPRINT(
"StretchDIBits Allocate Bits %u!!!\n", cjBmpScanSize);
1128 DPRINT1(
"StretchDIBits called on invalid DC %p (not owned?)\n",
hdc);
1160 if (lpBitsInfo != pConvertedInfo)
1161 RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
#define NT_SUCCESS(StatCode)
static const WCHAR dwWidth[]
static const WCHAR dwHeight[]
#define ERROR_INVALID_PARAMETER
#define ERROR_INVALID_HANDLE
HDC WINAPI GdiConvertAndCheckDC(HDC hdc)
BOOL WINAPI GdiValidateHandle(HGDIOBJ)
VOID GdiSAPCallback(PLDC pldc)
#define HANDLE_METADC(_RetType, _Func, dwError, hdc,...)
LPBITMAPINFO WINAPI ConvertBitmapInfo(CONST BITMAPINFO *BitmapInfo, UINT ColorSpec, UINT *BitmapInfoSize, BOOL FollowedByData)
VOID WINAPI GdiSetLastError(DWORD dwErrCode)
PLDC FASTCALL GdiGetLDC(HDC hDC)
#define GDI_OBJECT_TYPE_DC
#define GDI_HANDLE_GET_TYPE(h)
#define GDI_OBJECT_TYPE_BITMAP
#define GDI_HANDLE_IS_STOCKOBJ(h)
@ GDILoObjType_LO_METADC16_TYPE
@ GDILoObjType_LO_DC_TYPE
GLint GLint GLsizei GLsizei height
GLint GLint GLsizei width
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
#define EXCEPTION_EXECUTE_HANDLER
static const BYTE masks[8]
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiCreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
_In_ DWORD _In_ DWORD dwOffset
__kernel_entry W32KAPI INT APIENTRY NtGdiStretchDIBitsInternal(_In_ HDC hdc, _In_ INT xDst, _In_ INT yDst, _In_ INT cxDst, _In_ INT cyDst, _In_ INT xSrc, _In_ INT ySrc, _In_ INT cxSrc, _In_ INT cySrc, _In_reads_bytes_opt_(cjMaxBits) LPBYTE pjInit, _In_ LPBITMAPINFO pbmi, _In_ DWORD dwUsage, _In_ DWORD dwRop4, _In_ UINT cjMaxInfo, _In_ UINT cjMaxBits, _In_opt_ HANDLE hcmXform)
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiSetBitmapAttributes(_In_ HBITMAP hbm, _In_ DWORD dwFlags)
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiCreateDIBSection(_In_ HDC hdc, _In_opt_ HANDLE hSectionApp, _In_ DWORD dwOffset, _In_reads_bytes_opt_(cjHeader) LPBITMAPINFO pbmi, _In_ DWORD iUsage, _In_ UINT cjHeader, _In_ FLONG fl, _In_ ULONG_PTR dwColorSpace, _Outptr_ PVOID *ppvBits)
__kernel_entry W32KAPI INT APIENTRY NtGdiSetDIBitsToDeviceInternal(_In_ HDC hdcDest, _In_ INT xDst, _In_ INT yDst, _In_ DWORD cx, _In_ DWORD cy, _In_ INT xSrc, _In_ INT ySrc, _In_ DWORD iStartScan, _In_ DWORD cNumScan, _In_reads_bytes_(cjMaxBits) LPBYTE pInitBits, _In_reads_bytes_(cjMaxInfo) LPBITMAPINFO pbmi, _In_ DWORD iUsage, _In_ UINT cjMaxBits, _In_ UINT cjMaxInfo, _In_ BOOL bTransformCoordinates, _In_opt_ HANDLE hcmXform)
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiClearBitmapAttributes(_In_ HBITMAP hbm, _In_ DWORD dwFlags)
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiCreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBPP, _In_opt_ LPBYTE pjInit)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetDCObject(_In_ HDC hdc, _In_ INT itype)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO _In_ UINT iUsage
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiCreateDIBitmapInternal(_In_ HDC hdc, _In_ INT cx, _In_ INT cy, _In_ DWORD fInit, _In_reads_bytes_opt_(cjMaxBits) LPBYTE pjInit, _In_reads_bytes_opt_(cjMaxInitInfo) LPBITMAPINFO pbmi, _In_ DWORD iUsage, _In_ UINT cjMaxInitInfo, _In_ UINT cjMaxBits, _In_ FLONG f, _In_ HANDLE hcmXform)
__kernel_entry W32KAPI HDC APIENTRY NtGdiGetDCforBitmap(_In_ HBITMAP hsurf)
#define LDC_KILL_DOCUMENT
#define _SEH2_EXCEPT(...)
BITMAPCOREHEADER bmciHeader
BITMAPINFOHEADER bmiHeader
#define RtlCopyMemory(Destination, Source, Length)
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
_In_ HFONT _Out_ PUINT Height
static int __cdecl compr(const void *a, const void *b)
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
UCHAR gajBitsPerFormat[11]
#define WIDTH_BYTES_ALIGN32(cx, bpp)
DWORD WINAPI GetBitmapAttributes(HBITMAP hbm)
ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression)
UINT FASTCALL DIB_BitmapMaxBitsSize(PBITMAPINFO Info, UINT ScanLines)
HBITMAP WINAPI SetBitmapAttributes(HBITMAP hbm, DWORD dwFlags)
int WINAPI GdiGetBitmapBitsSize(BITMAPINFO *lpbmi)
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
#define IS_ALIGNED(Pointer, Alignment)
INT FASTCALL DIB_BitmapInfoSize(const BITMAPINFO *info, WORD coloruse, BOOL max)
HBITMAP WINAPI ClearBitmapAttributes(HBITMAP hbm, DWORD dwFlags)
INT WINAPI DIB_GetBitmapInfo(const BITMAPINFOHEADER *header, PLONG width, PLONG height, PWORD planes, PWORD bpp, PLONG compr, PLONG size)
UINT WINAPI GetDIBColorTable(HDC hDC, UINT iStartIndex, UINT cEntries, RGBQUAD *pColors)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
_In_ SIZEL _In_ ULONG iFormat
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
struct _BITMAPCOREINFO * PBITMAPCOREINFO
int WINAPI SetDIBitsToDevice(_In_ HDC, _In_ int, _In_ int, _In_ DWORD, _In_ DWORD, _In_ int, _In_ int, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
HGDIOBJ WINAPI GetStockObject(_In_ int)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
int WINAPI GetObjectA(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
struct tagRGBTRIPLE RGBTRIPLE
struct tagBITMAPCOREHEADER * PBITMAPCOREHEADER
int WINAPI SetDIBits(_In_opt_ HDC, _In_ HBITMAP, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
struct tagBITMAPCOREHEADER BITMAPCOREHEADER
HBITMAP WINAPI CreateBitmapIndirect(_In_ const BITMAP *pbm)
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
HGDIOBJ WINAPI GetCurrentObject(_In_ HDC, _In_ UINT)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI RestoreDC(_In_ HDC, _In_ int)
int WINAPI StartPage(_In_ HDC)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
BOOL WINAPI DeleteDC(_In_ HDC)
HBITMAP WINAPI CreateDIBitmap(_In_ HDC hdc, _In_opt_ const BITMAPINFOHEADER *pbmih, _In_ DWORD fdwInit, _In_opt_ const VOID *pvInit, _In_opt_ const BITMAPINFO *pbmi, _In_ UINT uUsage)
int WINAPI SaveDC(_In_ HDC)
HBITMAP WINAPI CreateDiscardableBitmap(_In_ HDC, _In_ int, _In_ int)
int WINAPI StretchDIBits(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ const VOID *, _In_ const BITMAPINFO *, _In_ UINT, _In_ DWORD)