ReactOS 0.4.15-dev-5669-g09dde2c
bitmap.c File Reference
#include <precomp.h>
#include <pseh/pseh2.h>
#include <debug.h>
Include dependency graph for bitmap.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define WIDTH_BYTES_ALIGN32(cx, bpp)   ((((cx) * (bpp) + 31) & ~31) >> 3)
 

Functions

INT FASTCALL DIB_BitmapInfoSize (const BITMAPINFO *info, WORD coloruse, BOOL max)
 
UINT FASTCALL DIB_BitmapMaxBitsSize (PBITMAPINFO Info, UINT ScanLines)
 
INT WINAPI DIB_GetBitmapInfo (const BITMAPINFOHEADER *header, PLONG width, PLONG height, PWORD planes, PWORD bpp, PLONG compr, PLONG size)
 
int WINAPI GdiGetBitmapBitsSize (BITMAPINFO *lpbmi)
 
HBITMAP WINAPI CreateDIBSection (HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
 
HBITMAP WINAPI CreateBitmap (INT Width, INT Height, UINT Planes, UINT BitsPixel, CONST VOID *pUnsafeBits)
 
HBITMAP WINAPI CreateBitmapIndirect (const BITMAP *pbm)
 
HBITMAP WINAPI CreateDiscardableBitmap (HDC hDC, INT Width, INT Height)
 
HBITMAP WINAPI CreateCompatibleBitmap (HDC hDC, INT Width, INT Height)
 
INT WINAPI GetDIBits (HDC hDC, HBITMAP hbmp, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT uUsage)
 
HBITMAP WINAPI CreateDIBitmap (HDC hDC, const BITMAPINFOHEADER *Header, DWORD Init, LPCVOID Bits, const BITMAPINFO *Data, UINT ColorUse)
 
INT WINAPI SetDIBits (HDC hDC, HBITMAP hBitmap, UINT uStartScan, UINT cScanLines, CONST VOID *lpvBits, CONST BITMAPINFO *lpbmi, UINT fuColorUse)
 
INT WINAPI SetDIBitsToDevice (HDC hdc, int XDest, int YDest, DWORD Width, DWORD Height, int XSrc, int YSrc, UINT StartScan, UINT ScanLines, CONST VOID *Bits, CONST BITMAPINFO *lpbmi, UINT ColorUse)
 
int WINAPI StretchDIBits (HDC hdc, int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth, int nSrcHeight, CONST VOID *lpBits, CONST BITMAPINFO *lpBitsInfo, UINT iUsage, DWORD dwRop)
 
DWORD WINAPI GetBitmapAttributes (HBITMAP hbm)
 
HBITMAP WINAPI SetBitmapAttributes (HBITMAP hbm, DWORD dwFlags)
 
HBITMAP WINAPI ClearBitmapAttributes (HBITMAP hbm, DWORD dwFlags)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 5 of file bitmap.c.

◆ WIDTH_BYTES_ALIGN32

#define WIDTH_BYTES_ALIGN32 (   cx,
  bpp 
)    ((((cx) * (bpp) + 31) & ~31) >> 3)

Definition at line 9 of file bitmap.c.

Function Documentation

◆ ClearBitmapAttributes()

HBITMAP WINAPI ClearBitmapAttributes ( HBITMAP  hbm,
DWORD  dwFlags 
)

Definition at line 943 of file bitmap.c.

944{
945 if ( dwFlags & ~SC_BB_STOCKOBJ )
946 {
947 return NULL;
948 }
950}
#define NULL
Definition: types.h:112
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiClearBitmapAttributes(_In_ HBITMAP hbm, _In_ DWORD dwFlags)
#define SC_BB_STOCKOBJ
Definition: ntgdihdl.h:199
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by Test_BitmapAttributes().

◆ CreateBitmap()

HBITMAP WINAPI CreateBitmap ( INT  Width,
INT  Height,
UINT  Planes,
UINT  BitsPixel,
CONST VOID pUnsafeBits 
)

Definition at line 254 of file bitmap.c.

260{
261 if (Width && Height)
262 {
263 return NtGdiCreateBitmap(Width, Height, Planes, BitsPixel, (LPBYTE) pUnsafeBits);
264 }
265 else
266 {
267 /* Return 1x1 bitmap */
269 }
270}
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiCreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBPP, _In_opt_ LPBYTE pjInit)
#define DEFAULT_BITMAP
Definition: ntgdityp.h:195
unsigned char * LPBYTE
Definition: typedefs.h:53
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:126
_In_ HFONT _Out_ PUINT Height
Definition: font.h:125
HGDIOBJ WINAPI GetStockObject(_In_ int)

◆ CreateBitmapIndirect()

HBITMAP WINAPI CreateBitmapIndirect ( const BITMAP pbm)

Definition at line 277 of file bitmap.c.

279{
281
282 /* Note windows xp/2003 does not check if pbm is NULL or not */
283 if ((pbm->bmWidthBytes != 0) && (!(pbm->bmWidthBytes & 1)))
284
285 {
286 bitmap = CreateBitmap(pbm->bmWidth, pbm->bmHeight, pbm->bmPlanes, pbm->bmBitsPixel,
287 pbm->bmBits);
288 }
289 else
290 {
292 }
293
294 return bitmap;
295}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
static HBITMAP
Definition: button.c:44
Definition: uimain.c:89
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)

◆ CreateCompatibleBitmap()

HBITMAP WINAPI CreateCompatibleBitmap ( HDC  hDC,
INT  Width,
INT  Height 
)

Definition at line 309 of file bitmap.c.

313{
314 PDC_ATTR pDc_Attr;
315
317 return NULL;
318
319 if (!Width || !Height)
321
322 if (!(pDc_Attr->ulDirty_ & DC_DIBSECTION))
323 {
325 }
326 else
327 {
328 HBITMAP hBmp = NULL;
329 struct
330 {
332 BITMAPINFOHEADER bmih;
333 RGBQUAD rgbquad[256];
334 } buffer;
335 DIBSECTION* pDIBs = (DIBSECTION*) &buffer;
336 BITMAPINFO* pbmi = (BITMAPINFO*) &buffer.bmih;
337
339
340 if (GetObjectA(hBmp, sizeof(DIBSECTION), pDIBs) != sizeof(DIBSECTION))
341 return NULL;
342
343 if (pDIBs->dsBm.bmBitsPixel <= 8)
344 GetDIBColorTable(hDC, 0, 256, buffer.rgbquad);
345
346 pDIBs->dsBmih.biWidth = Width;
347 pDIBs->dsBmih.biHeight = Height;
348
350 }
351 return NULL;
352}
static HDC hDC
Definition: 3dtext.c:33
ULONG RGBQUAD
Definition: precomp.h:50
#define GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:68
GLuint buffer
Definition: glext.h:5915
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiCreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetDCObject(_In_ HDC hdc, _In_ INT itype)
#define DC_DIBSECTION
Definition: ntgdihdl.h:137
Definition: bl.h:1331
WORD bmBitsPixel
Definition: wingdi.h:1426
BITMAP dsBm
Definition: wingdi.h:1669
BITMAPINFOHEADER dsBmih
Definition: wingdi.h:1670
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:199
UINT WINAPI GetDIBColorTable(HDC hDC, UINT iStartIndex, UINT cEntries, RGBQUAD *pColors)
Definition: palette.c:123
#define DIB_RGB_COLORS
Definition: wingdi.h:367
int WINAPI GetObjectA(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)

◆ CreateDIBitmap()

HBITMAP WINAPI CreateDIBitmap ( HDC  hDC,
const BITMAPINFOHEADER Header,
DWORD  Init,
LPCVOID  Bits,
const BITMAPINFO Data,
UINT  ColorUse 
)

Definition at line 400 of file bitmap.c.

407{
408 LONG Width, Height, Compression, DibSize;
409 WORD Planes, BitsPerPixel;
410// PDC_ATTR pDc_Attr;
411 UINT cjBmpScanSize = 0;
413 PBITMAPINFO pbmiConverted;
414 UINT cjInfoSize;
415
416 /* Convert the BITMAPINFO if it is a COREINFO */
417 pbmiConverted = ConvertBitmapInfo(Data, ColorUse, &cjInfoSize, FALSE);
418
419 /* Check for CBM_CREATDIB */
420 if (Init & CBM_CREATDIB)
421 {
422 if (cjInfoSize == 0)
423 {
424 goto Exit;
425 }
426 else if (Init & CBM_INIT)
427 {
428 if (Bits == NULL)
429 {
430 goto Exit;
431 }
432 }
433 else
434 {
435 Bits = NULL;
436 }
437
438 /* CBM_CREATDIB needs Data. */
439 if (pbmiConverted == NULL)
440 {
441 DPRINT1("CBM_CREATDIB needs a BITMAPINFO!\n");
442 goto Exit;
443 }
444
445 /* It only works with PAL or RGB */
446 if (ColorUse > DIB_PAL_COLORS)
447 {
448 DPRINT1("Invalid ColorUse: %lu\n", ColorUse);
450 goto Exit;
451 }
452
453 /* Use the header from the data */
454 Header = &Data->bmiHeader;
455 }
456 else
457 {
458 if (Init & CBM_INIT)
459 {
460 if (Bits != NULL)
461 {
462 if (cjInfoSize == 0)
463 {
464 goto Exit;
465 }
466 }
467 else
468 {
469 Init &= ~CBM_INIT;
470 }
471 }
472 }
473
474 /* Header is required */
475 if (!Header)
476 {
477 DPRINT1("Header is NULL\n");
479 goto Exit;
480 }
481
482 /* Get the bitmap format and dimensions */
483 if (DIB_GetBitmapInfo(Header, &Width, &Height, &Planes, &BitsPerPixel, &Compression, &DibSize) == -1)
484 {
485 DPRINT1("DIB_GetBitmapInfo failed!\n");
487 goto Exit;
488 }
489
490 /* Check if the Compr is incompatible */
491 if ((Compression == BI_JPEG) || (Compression == BI_PNG))
492 {
493 DPRINT1("Invalid compression: %lu!\n", Compression);
494 goto Exit;
495 }
496
497 /* Only DIB_RGB_COLORS (0), DIB_PAL_COLORS (1) and 2 are valid. */
498 if (ColorUse > DIB_PAL_COLORS + 1)
499 {
500 DPRINT1("Invalid compression: %lu!\n", Compression);
502 goto Exit;
503 }
504
505 /* If some Bits are given, only DIB_PAL_COLORS and DIB_RGB_COLORS are valid */
506 if (Bits && (ColorUse > DIB_PAL_COLORS))
507 {
508 DPRINT1("Invalid ColorUse: %lu\n", ColorUse);
510 goto Exit;
511 }
512
513 /* Negative width is not allowed */
514 if (Width < 0)
515 {
516 DPRINT1("Negative width: %li\n", Width);
517 goto Exit;
518 }
519
520 /* Top-down DIBs have a negative height. */
521 Height = abs(Height);
522
523// For Icm support.
524// GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID)&pDc_Attr))
525
526 cjBmpScanSize = GdiGetBitmapBitsSize(pbmiConverted);
527
528 DPRINT("pBMI %p, Size bpp %u, dibsize %d, Conv %u, BSS %u\n",
529 Data, BitsPerPixel, DibSize, cjInfoSize, cjBmpScanSize);
530
531 if (!Width || !Height)
532 {
534 }
535 else
536 {
538 Width,
539 Height,
540 Init,
541 (LPBYTE)Bits,
542 (LPBITMAPINFO)pbmiConverted,
543 ColorUse,
544 cjInfoSize,
545 cjBmpScanSize,
546 0, 0);
547 }
548
549Exit:
550 /* Cleanup converted BITMAPINFO */
551 if ((pbmiConverted != NULL) && (pbmiConverted != Data))
552 {
553 RtlFreeHeap(RtlGetProcessHeap(), 0, pbmiConverted);
554 }
555
556 return hBitmap;
557}
#define CBM_CREATDIB
#define DPRINT1
Definition: precomp.h:8
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
Definition: Header.h:9
#define FALSE
Definition: types.h:117
static HBITMAP hBitmap
Definition: timezone.c:26
#define abs(i)
Definition: fconv.c:206
unsigned short WORD
Definition: ntddk_ex.h:93
LPBITMAPINFO WINAPI ConvertBitmapInfo(CONST BITMAPINFO *BitmapInfo, UINT ColorSpec, UINT *BitmapInfoSize, BOOL FollowedByData)
Definition: utils.c:178
VOID WINAPI GdiSetLastError(DWORD dwErrCode)
Definition: misc.c:873
unsigned int UINT
Definition: ndis.h:50
__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)
long LONG
Definition: pedump.c:60
#define DPRINT
Definition: sndvol32.h:71
static void Exit(void)
Definition: sock.c:1330
int WINAPI GdiGetBitmapBitsSize(BITMAPINFO *lpbmi)
Definition: bitmap.c:163
INT WINAPI DIB_GetBitmapInfo(const BITMAPINFOHEADER *header, PLONG width, PLONG height, PWORD planes, PWORD bpp, PLONG compr, PLONG size)
Definition: bitmap.c:99
#define DIB_PAL_COLORS
Definition: wingdi.h:366
#define BI_JPEG
Definition: wingdi.h:38
#define CBM_INIT
Definition: wingdi.h:365
#define BI_PNG
Definition: wingdi.h:39

◆ CreateDIBSection()

HBITMAP WINAPI CreateDIBSection ( HDC  hDC,
CONST BITMAPINFO BitmapInfo,
UINT  Usage,
VOID **  Bits,
HANDLE  hSection,
DWORD  dwOffset 
)

Definition at line 199 of file bitmap.c.

206{
207 PBITMAPINFO pConvertedInfo;
208 UINT ConvertedInfoSize;
210 PVOID bmBits = NULL;
211
212 pConvertedInfo = ConvertBitmapInfo(BitmapInfo, Usage, &ConvertedInfoSize,
213 FALSE);
214
215 if (pConvertedInfo)
216 {
217 // Verify header due to converted may == info.
218 if (pConvertedInfo->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER))
219 {
220 if (pConvertedInfo->bmiHeader.biCompression == BI_JPEG
221 || pConvertedInfo->bmiHeader.biCompression == BI_PNG)
222 {
224 return NULL;
225 }
226 }
227 bmBits = Bits;
229 ConvertedInfoSize, 0, // fl
230 0, // dwColorSpace
231 &bmBits);
232
233 if (BitmapInfo != pConvertedInfo)
234 RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
235
236 if (!hBitmap)
237 {
238 bmBits = NULL;
239 }
240 }
241
242 if (Bits)
243 *Bits = bmBits;
244
245 return hBitmap;
246}
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
_In_ DWORD _In_ DWORD dwOffset
Definition: ntgdi.h:2033
__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)
ULONG biCompression
Definition: precomp.h:38
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3239

Referenced by alpha_blend_hdc_pixels(), alpha_blend_image(), ARGB2BMP(), BITMAP_CopyImage(), BITMAP_LoadImageW(), ConvertBitmapTo32Bpp(), Create24BppBitmap(), Create32BitHBITMAP(), create_bitmap(), create_dib(), create_dib_section(), create_hatch_bitmap(), create_render_dc(), create_test_bitmap(), create_test_icon(), CreateCompatibleBitmap(), CreateDIBWithProperties(), CreateFrameBufferBitmap(), ATL::CImage::CreateInternal(), CShellLink::CreateShortcutIcon(), CreateStarBitmap(), draw_graphics(), DrawDibBegin(), DrawShadowText(), GdipCreateBitmapFromScan0(), GdipCreateHBITMAPFromBitmap(), GdipDrawImagePointsRect(), GdipGetDC(), get_bitmap_info(), ImageList_CreateImage(), Imm32LoadBitmapFromBytes(), InitBitmap(), InitLogo(), InitPerBitDepth(), IntCreate32BppBitmap(), mi_paint_rect(), mstsc_ProtocolIOThread(), OLEPictureImpl_LoadWICSource(), PaintCells(), PlayEnhMetaFileRecord(), START_TEST(), test_32bit_ddb(), test_alpha_hdc(), test_BitBlt(), test_bitmap_colors(), test_bitmap_font_glyph_index(), test_bitmap_rendering(), test_bitmapinfoheadersize(), test_boundsrect(), test_clipping(), test_color_table(), test_CopyImage_Bitmap(), test_CreateIcon(), test_data_handles(), test_device_caps(), test_dib_formats(), test_DIB_PAL_COLORS(), Test_Dibsection(), test_dibsections(), test_DrawDib_sizeimage(), test_DrawIcon(), test_DrawIconEx(), test_DrawState(), test_emf_BitBlt(), test_GdiAlphaBlend(), test_GdiGradientFill(), test_GdipCreateBitmapFromHBITMAP(), test_GetCursorFrameInfo(), Test_GetDIBColorTable(), test_GetDIBits_BI_BITFIELDS(), test_GetDIBits_scanlines(), test_GetDIBits_selected_DIB(), test_GetDIBits_top_down(), test_hdc_caching(), test_Image_StretchMode(), test_ImageList_DrawIndirect(), Test_MaskBlt_16bpp(), Test_MaskBlt_1bpp(), Test_MaskBlt_32bpp(), Test_MaskBlt_Brush(), test_mono_dibsection(), Test_NtGdiDoPalette_SetDIBColorTable(), test_palette_brush(), test_path_state(), test_pattern_brush(), Test_SelectDIBSection(), Test_SetDIBits(), test_SetDIBits(), test_SetDIBits_RLE4(), test_SetDIBits_RLE8(), test_SetDIBitsToDevice(), test_SetDIBitsToDevice_RLE8(), Test_SetPixel_PAL(), test_simple_graphics(), Test_SrcMono(), test_StretchBlt(), test_StretchBlt_TopDownOptions(), test_StretchDIBits(), test_WICCreateBitmapFromSectionEx(), UXTHEME_DrawThemePartToDib(), and WinGCreateBitmap().

◆ CreateDiscardableBitmap()

HBITMAP WINAPI CreateDiscardableBitmap ( HDC  hDC,
INT  Width,
INT  Height 
)

Definition at line 299 of file bitmap.c.

303{
305}
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)

◆ DIB_BitmapInfoSize()

INT FASTCALL DIB_BitmapInfoSize ( const BITMAPINFO info,
WORD  coloruse,
BOOL  max 
)

Definition at line 19 of file bitmap.c.

23{
24 unsigned int colors, size, masks = 0;
25
26 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
27 {
28 const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *) info;
29 size = sizeof(BITMAPCOREHEADER);
30 if (core->bcBitCount <= 8)
31 {
32 colors = 1 << core->bcBitCount;
33 if (coloruse == DIB_RGB_COLORS)
34 size += colors * sizeof(RGBTRIPLE);
35 else
36 size += colors * sizeof(WORD);
37 }
38 return size;
39 }
40 else /* assume BITMAPINFOHEADER */
41 {
42 colors = max ? (1 << info->bmiHeader.biBitCount) : info->bmiHeader.biClrUsed;
43 if (colors > 256)
44 colors = 256;
45 if (!colors && (info->bmiHeader.biBitCount <= 8))
46 colors = 1 << info->bmiHeader.biBitCount;
47 if (info->bmiHeader.biCompression == BI_BITFIELDS)
48 masks = 3;
49 size = max(info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD));
50 return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
51 }
52}
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
if(dx< 0)
Definition: linetemp.h:194
#define BI_BITFIELDS
Definition: mmreg.h:507
static const BYTE masks[8]
Definition: dib.c:2760
#define max(a, b)
Definition: svc.c:63
struct tagRGBTRIPLE RGBTRIPLE
struct tagBITMAPCOREHEADER BITMAPCOREHEADER
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

Referenced by GetDIBits(), IntSynthesizeBitmap(), and IntSynthesizeDib().

◆ DIB_BitmapMaxBitsSize()

UINT FASTCALL DIB_BitmapMaxBitsSize ( PBITMAPINFO  Info,
UINT  ScanLines 
)

Definition at line 61 of file bitmap.c.

64{
65 UINT Ret;
66
67 if (!Info)
68 return 0;
69
70 if (Info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
71 {
73 Ret = WIDTH_BYTES_ALIGN32(Core->bcWidth * Core->bcPlanes,
74 Core->bcBitCount) * ScanLines;
75 }
76 else /* assume BITMAPINFOHEADER */
77 {
78 if ((Info->bmiHeader.biCompression == BI_RGB) || (Info->bmiHeader.biCompression == BI_BITFIELDS))
79 {
81 Info->bmiHeader.biWidth * Info->bmiHeader.biPlanes,
82 Info->bmiHeader.biBitCount) * ScanLines;
83 }
84 else
85 {
86 Ret = Info->bmiHeader.biSizeImage;
87 }
88 }
89 return Ret;
90}
#define BI_RGB
Definition: precomp.h:47
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: bitmap.c:9
struct tagBITMAPCOREHEADER * PBITMAPCOREHEADER

Referenced by GetDIBits(), and SetDIBitsToDevice().

◆ DIB_GetBitmapInfo()

INT WINAPI DIB_GetBitmapInfo ( const BITMAPINFOHEADER header,
PLONG  width,
PLONG  height,
PWORD  planes,
PWORD  bpp,
PLONG  compr,
PLONG  size 
)

Definition at line 99 of file bitmap.c.

107{
108 if (header->biSize == sizeof(BITMAPCOREHEADER))
109 {
111 *width = core->bcWidth;
112 *height = core->bcHeight;
113 *planes = core->bcPlanes;
114 *bpp = core->bcBitCount;
115 *compr = 0;
116 *size = 0;
117 return 0;
118 }
119
120 if (header->biSize == sizeof(BITMAPINFOHEADER))
121 {
122 *width = header->biWidth;
123 *height = header->biHeight;
124 *planes = header->biPlanes;
125 *bpp = header->biBitCount;
126 *compr = header->biCompression;
127 *size = header->biSizeImage;
128 return 1;
129 }
130
131 if (header->biSize == sizeof(BITMAPV4HEADER))
132 {
134 *width = v4hdr->bV4Width;
135 *height = v4hdr->bV4Height;
136 *planes = v4hdr->bV4Planes;
137 *bpp = v4hdr->bV4BitCount;
138 *compr = v4hdr->bV4V4Compression;
139 *size = v4hdr->bV4SizeImage;
140 return 4;
141 }
142
143 if (header->biSize == sizeof(BITMAPV5HEADER))
144 {
145 BITMAPV5HEADER *v5hdr = (BITMAPV5HEADER *) header;
146 *width = v5hdr->bV5Width;
147 *height = v5hdr->bV5Height;
148 *planes = v5hdr->bV5Planes;
149 *bpp = v5hdr->bV5BitCount;
150 *compr = v5hdr->bV5Compression;
151 *size = v5hdr->bV5SizeImage;
152 return 5;
153 }
154 DPRINT("(%lu): wrong size for header\n", header->biSize);
155 return -1;
156}
DWORD bpp
Definition: surface.c:185
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
WORD bV4Planes
Definition: wingdi.h:1495
DWORD bV4SizeImage
Definition: wingdi.h:1498
DWORD bV4V4Compression
Definition: wingdi.h:1497
LONG bV4Height
Definition: wingdi.h:1494
LONG bV4Width
Definition: wingdi.h:1493
WORD bV4BitCount
Definition: wingdi.h:1496
static int __cdecl compr(const void *a, const void *b)
Definition: bidi.c:641

Referenced by CreateDIBitmap().

◆ GdiGetBitmapBitsSize()

int WINAPI GdiGetBitmapBitsSize ( BITMAPINFO lpbmi)

Definition at line 163 of file bitmap.c.

165{
166 UINT Ret;
167
168 if (!lpbmi)
169 return 0;
170
171 if (lpbmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
172 {
174 Ret =
176 Core->bcBitCount) * Core->bcHeight;
177 }
178 else /* assume BITMAPINFOHEADER */
179 {
180 if (!(lpbmi->bmiHeader.biCompression) || (lpbmi->bmiHeader.biCompression == BI_BITFIELDS))
181 {
183 lpbmi->bmiHeader.biWidth * lpbmi->bmiHeader.biPlanes,
184 lpbmi->bmiHeader.biBitCount) * abs(lpbmi->bmiHeader.biHeight);
185 }
186 else
187 {
188 Ret = lpbmi->bmiHeader.biSizeImage;
189 }
190 }
191 return Ret;
192}
USHORT biBitCount
Definition: precomp.h:37

Referenced by ConvertBitmapInfo(), CreateDIBitmap(), and StretchDIBits().

◆ GetBitmapAttributes()

DWORD WINAPI GetBitmapAttributes ( HBITMAP  hbm)

Definition at line 915 of file bitmap.c.

916{
918 {
919 return SC_BB_STOCKOBJ;
920 }
921 return 0;
922}
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37

Referenced by Test_BitmapAttributes().

◆ GetDIBits()

INT WINAPI GetDIBits ( HDC  hDC,
HBITMAP  hbmp,
UINT  uStartScan,
UINT  cScanLines,
LPVOID  lpvBits,
LPBITMAPINFO  lpbmi,
UINT  uUsage 
)

Definition at line 356 of file bitmap.c.

364{
365 UINT cjBmpScanSize;
366 UINT cjInfoSize;
367
368 if (!hDC || !GdiValidateHandle((HGDIOBJ) hDC) || !lpbmi)
369 {
371 return 0;
372 }
373
374 cjBmpScanSize = DIB_BitmapMaxBitsSize(lpbmi, cScanLines);
375 /* Caller must provide maximum size possible */
376 cjInfoSize = DIB_BitmapInfoSize(lpbmi, uUsage, TRUE);
377
378 if (lpvBits)
379 {
380 if (lpbmi->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER))
381 {
382 if (lpbmi->bmiHeader.biCompression == BI_JPEG
383 || lpbmi->bmiHeader.biCompression == BI_PNG)
384 {
386 return 0;
387 }
388 }
389 }
390
391 return NtGdiGetDIBitsInternal(hDC, hbmp, uStartScan, cScanLines, lpvBits, lpbmi, uUsage,
392 cjBmpScanSize, cjInfoSize);
393}
HBITMAP hbmp
#define TRUE
Definition: types.h:120
BOOL WINAPI GdiValidateHandle(HGDIOBJ)
Definition: misc.c:712
UINT FASTCALL DIB_BitmapMaxBitsSize(PBITMAPINFO Info, UINT ScanLines)
Definition: bitmap.c:61
INT FASTCALL DIB_BitmapInfoSize(const BITMAPINFO *info, WORD coloruse, BOOL max)
Definition: bitmap.c:19

◆ SetBitmapAttributes()

HBITMAP WINAPI SetBitmapAttributes ( HBITMAP  hbm,
DWORD  dwFlags 
)

Definition at line 929 of file bitmap.c.

930{
931 if ( dwFlags & ~SC_BB_STOCKOBJ )
932 {
933 return NULL;
934 }
936}
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiSetBitmapAttributes(_In_ HBITMAP hbm, _In_ DWORD dwFlags)

Referenced by Test_BitmapAttributes().

◆ SetDIBits()

INT WINAPI SetDIBits ( HDC  hDC,
HBITMAP  hBitmap,
UINT  uStartScan,
UINT  cScanLines,
CONST VOID lpvBits,
CONST BITMAPINFO lpbmi,
UINT  fuColorUse 
)

Definition at line 564 of file bitmap.c.

572{
573 HDC hDCc, SavehDC, nhDC;
575 HGDIOBJ hOldBitmap;
576 HPALETTE hPal = NULL;
577 INT LinesCopied = 0;
578 BOOL newDC = FALSE;
579
581 return 0;
582
583 if (lpbmi->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER))
584 {
585 if (lpbmi->bmiHeader.biCompression == BI_JPEG
586 || lpbmi->bmiHeader.biCompression == BI_PNG)
587 {
589 return 0;
590 }
591 }
592
593 hDCc = NtGdiGetDCforBitmap(hBitmap); // hDC can be NULL, so, get it from the bitmap.
594 SavehDC = hDCc;
595 if (!hDCc) // No DC associated with bitmap, Clone or Create one.
596 {
597 nhDC = CreateCompatibleDC(hDC);
598 if (!nhDC)
599 return 0;
600 newDC = TRUE;
601 SavehDC = nhDC;
602 }
603 else if (!SaveDC(hDCc))
604 return 0;
605
606 hOldBitmap = SelectObject(SavehDC, hBitmap);
607
608 if (hOldBitmap)
609 {
610 if (hDC)
611 hPal = SelectPalette(SavehDC, (HPALETTE) GetCurrentObject(hDC, OBJ_PAL), FALSE);
612
613 if (lpbmi->bmiHeader.biSize < sizeof(BITMAPINFOHEADER))
614 {
615 PBITMAPCOREINFO pbci = (PBITMAPCOREINFO) lpbmi;
616 dwWidth = pbci->bmciHeader.bcWidth;
618 }
619 else
620 {
621 dwWidth = lpbmi->bmiHeader.biWidth;
622 dwHeight = abs(lpbmi->bmiHeader.biHeight);
623 }
624
625 LinesCopied = SetDIBitsToDevice(SavehDC, 0, 0, dwWidth, dwHeight, 0, 0, uStartScan,
626 cScanLines, (void *) lpvBits, (LPBITMAPINFO) lpbmi, fuColorUse);
627
628 if (hDC)
629 SelectPalette(SavehDC, hPal, FALSE);
630
631 SelectObject(SavehDC, hOldBitmap);
632 }
633
634 if (newDC)
635 DeleteDC(SavehDC);
636 else
637 RestoreDC(SavehDC, -1);
638
639 return LinesCopied;
640}
static const WCHAR dwWidth[]
Definition: provider.c:62
static const WCHAR dwHeight[]
Definition: provider.c:63
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
static HDC
Definition: bitmap.c:44
__kernel_entry W32KAPI HDC APIENTRY NtGdiGetDCforBitmap(_In_ HBITMAP hsurf)
#define OBJ_PAL
Definition: objidl.idl:1413
BITMAPCOREHEADER bmciHeader
Definition: wingdi.h:1453
int32_t INT
Definition: typedefs.h:58
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)
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
HGDIOBJ WINAPI GetCurrentObject(_In_ HDC, _In_ UINT)
Definition: dc.c:428
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI RestoreDC(_In_ HDC, _In_ int)
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI SaveDC(_In_ HDC)

◆ SetDIBitsToDevice()

INT WINAPI SetDIBitsToDevice ( HDC  hdc,
int  XDest,
int  YDest,
DWORD  Width,
DWORD  Height,
int  XSrc,
int  YSrc,
UINT  StartScan,
UINT  ScanLines,
CONST VOID Bits,
CONST BITMAPINFO lpbmi,
UINT  ColorUse 
)

Definition at line 648 of file bitmap.c.

661{
662 PDC_ATTR pDc_Attr;
663 PBITMAPINFO pConvertedInfo;
664 UINT ConvertedInfoSize;
665 INT LinesCopied = 0;
666 UINT cjBmpScanSize = 0;
667 BOOL Hit = FALSE;
668 PVOID pvSafeBits = (PVOID) Bits;
669
670 if (!ScanLines || !lpbmi || !Bits)
671 return 0;
672
673 if (ColorUse && ColorUse != DIB_PAL_COLORS && ColorUse != DIB_PAL_COLORS + 1)
674 return 0;
675
676 pConvertedInfo = ConvertBitmapInfo(lpbmi, ColorUse, &ConvertedInfoSize, FALSE);
677 if (!pConvertedInfo)
678 return 0;
679
682 0,
683 hdc,
684 XDest,
685 YDest,
686 Width,
687 Height,
688 XSrc,
689 YSrc,
690 StartScan,
691 ScanLines,
692 Bits,
693 lpbmi,
694 ColorUse);
695
696 // Handle the "Special Case"!
697 {
698 PLDC pldc;
701 {
702 pldc = GdiGetLDC(hdc);
703 if (pldc)
704 {
705 if (pldc->Flags & LDC_STARTPAGE) StartPage(hdc);
706
707 if (pldc->Flags & LDC_SAPCALLBACK) GdiSAPCallback(pldc);
708
709 if (pldc->Flags & LDC_KILL_DOCUMENT)
710 {
711 LinesCopied = 0;
712 goto Exit;
713 }
714 }
715 else
716 {
718 LinesCopied = 0;
719 goto Exit;
720 }
721 }
722 }
723
724 if ((pConvertedInfo->bmiHeader.biCompression == BI_RLE8) ||
725 (pConvertedInfo->bmiHeader.biCompression == BI_RLE4))
726 {
727 /* For compressed data, we must set the whole thing */
728 StartScan = 0;
729 ScanLines = pConvertedInfo->bmiHeader.biHeight;
730 }
731
732 cjBmpScanSize = DIB_BitmapMaxBitsSize((LPBITMAPINFO) lpbmi, ScanLines);
733
734 pvSafeBits = RtlAllocateHeap(GetProcessHeap(), 0, cjBmpScanSize);
735 if (pvSafeBits)
736 {
738 {
739 RtlCopyMemory(pvSafeBits, Bits, cjBmpScanSize);
740 }
742 {
743 Hit = TRUE;
744 }
746
747 if (Hit)
748 {
749 // We don't die, we continue on with a allocated safe pointer to kernel
750 // space.....
751 DPRINT1("SetDIBitsToDevice fail to read BitMapInfo: %p or Bits: %p & Size: %u\n",
752 pConvertedInfo, Bits, cjBmpScanSize);
753 }
754 DPRINT("SetDIBitsToDevice Allocate Bits %u!!!\n", cjBmpScanSize);
755 }
756
758 {
759 DPRINT1("SetDIBitsToDevice called on invalid DC %p (not owned?)\n", hdc);
761 LinesCopied = 0;
762 goto Exit;
763 }
764 /*
765 if ( !pDc_Attr || // DC is Public
766 ColorUse == DIB_PAL_COLORS ||
767 ((pConvertedInfo->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER)) &&
768 (pConvertedInfo->bmiHeader.biCompression == BI_JPEG ||
769 pConvertedInfo->bmiHeader.biCompression == BI_PNG )) )*/
770 {
771 LinesCopied = NtGdiSetDIBitsToDeviceInternal(hdc, XDest, YDest, Width, Height, XSrc, YSrc,
772 StartScan, ScanLines, (LPBYTE) pvSafeBits, (LPBITMAPINFO) pConvertedInfo, ColorUse,
773 cjBmpScanSize, ConvertedInfoSize,
774 TRUE,
775 NULL);
776 }
777Exit:
778 if (Bits != pvSafeBits)
779 RtlFreeHeap(RtlGetProcessHeap(), 0, pvSafeBits);
780 if (lpbmi != pConvertedInfo)
781 RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
782
783 return LinesCopied;
784}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define BI_RLE4
Definition: precomp.h:48
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
VOID GdiSAPCallback(PLDC pldc)
Definition: misc.c:819
#define HANDLE_METADC(_RetType, _Func, dwError, hdc,...)
Definition: gdi32p.h:589
PLDC FASTCALL GdiGetLDC(HDC hDC)
Definition: misc.c:785
@ GDILoObjType_LO_METADC16_TYPE
Definition: gdi_private.h:49
@ GDILoObjType_LO_DC_TYPE
Definition: gdi_private.h:34
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
HDC hdc
Definition: main.c:9
__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)
#define LDC_KILL_DOCUMENT
Definition: ntgdihdl.h:158
#define LDC_SAPCALLBACK
Definition: ntgdihdl.h:150
#define LDC_STARTPAGE
Definition: ntgdihdl.h:153
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
Definition: ntgdihdl.h:263
ULONG Flags
Definition: ntgdihdl.h:265
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
int WINAPI StartPage(_In_ HDC)
#define BI_RLE8
Definition: wingdi.h:35

◆ StretchDIBits()

int WINAPI StretchDIBits ( HDC  hdc,
int  XDest,
int  YDest,
int  nDestWidth,
int  nDestHeight,
int  XSrc,
int  YSrc,
int  nSrcWidth,
int  nSrcHeight,
CONST VOID lpBits,
CONST BITMAPINFO lpBitsInfo,
UINT  iUsage,
DWORD  dwRop 
)

Definition at line 791 of file bitmap.c.

806{
807 PDC_ATTR pDc_Attr;
808 PBITMAPINFO pConvertedInfo = NULL;
809 UINT ConvertedInfoSize = 0;
810 INT LinesCopied = 0;
811 UINT cjBmpScanSize = 0;
812 PVOID pvSafeBits = NULL;
813 BOOL Hit = FALSE;
814
815 DPRINT("StretchDIBits %p : %p : %u\n", lpBits, lpBitsInfo, iUsage);
816
817 HANDLE_METADC( int,
819 0,
820 hdc,
821 XDest,
822 YDest,
823 nDestWidth,
824 nDestHeight,
825 XSrc,
826 YSrc,
827 nSrcWidth,
828 nSrcHeight,
829 lpBits,
830 lpBitsInfo,
831 iUsage,
832 dwRop );
833
834 if ( GdiConvertAndCheckDC(hdc) == NULL ) return 0;
835
836 pConvertedInfo = ConvertBitmapInfo(lpBitsInfo, iUsage, &ConvertedInfoSize, FALSE);
837 if (!pConvertedInfo)
838 {
839 return 0;
840 }
841
842 cjBmpScanSize = GdiGetBitmapBitsSize((BITMAPINFO *) pConvertedInfo);
843
844 if (lpBits)
845 {
846 pvSafeBits = RtlAllocateHeap(GetProcessHeap(), 0, cjBmpScanSize);
847 if (pvSafeBits)
848 {
850 {
851 RtlCopyMemory(pvSafeBits, lpBits, cjBmpScanSize);
852 }
854 {
855 Hit = TRUE;
856 }
858
859 if (Hit)
860 {
861 // We don't die, we continue on with a allocated safe pointer to kernel
862 // space.....
863 DPRINT1("StretchDIBits fail to read BitMapInfo: %p or Bits: %p & Size: %u\n",
864 pConvertedInfo, lpBits, cjBmpScanSize);
865 }
866 DPRINT("StretchDIBits Allocate Bits %u!!!\n", cjBmpScanSize);
867 }
868 }
869
871 {
872 DPRINT1("StretchDIBits called on invalid DC %p (not owned?)\n", hdc);
874 LinesCopied = 0;
875 goto Exit;
876 }
877 /*
878 if ( !pDc_Attr ||
879 iUsage == DIB_PAL_COLORS ||
880 ((pConvertedInfo->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER)) &&
881 (pConvertedInfo->bmiHeader.biCompression == BI_JPEG ||
882 pConvertedInfo->bmiHeader.biCompression == BI_PNG )) )*/
883 {
884 LinesCopied = NtGdiStretchDIBitsInternal( hdc,
885 XDest,
886 YDest,
887 nDestWidth,
888 nDestHeight,
889 XSrc,
890 YSrc,
891 nSrcWidth,
892 nSrcHeight,
893 pvSafeBits,
894 pConvertedInfo,
895 (DWORD) iUsage,
896 dwRop,
897 ConvertedInfoSize,
898 cjBmpScanSize,
899 NULL );
900 }
901Exit:
902 if (pvSafeBits)
903 RtlFreeHeap(RtlGetProcessHeap(), 0, pvSafeBits);
904 if (lpBitsInfo != pConvertedInfo)
905 RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
906
907 return LinesCopied;
908}
HDC WINAPI GdiConvertAndCheckDC(HDC hdc)
Definition: dc.c:403
__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)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO _In_ UINT iUsage
Definition: ntgdi.h:2781
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)