ReactOS  0.4.15-dev-2721-g5912c11
bitmap.c File Reference
#include <precomp.h>
#include <pseh/pseh2.h>
#include <debug.h>
Include dependency graph for bitmap.c:
This graph shows which files directly or indirectly include this file:

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)
 
HBITMAP WINAPI GdiConvertBitmapV5 (HBITMAP in_format_BitMap, HBITMAP src_BitMap, INT bpp, INT unuse)
 

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 952 of file bitmap.c.

953 {
956  return 0;
957 }
#define SetLastError(x)
Definition: compat.h:611
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define UNIMPLEMENTED
Definition: debug.h:115

◆ 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 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiCreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBPP, _In_opt_ LPBYTE pjInit)
unsigned char * LPBYTE
Definition: typedefs.h:53
#define DEFAULT_BITMAP
Definition: ntgdityp.h:195

Referenced by CreateBitmapIndirect(), test_32bit_ddb(), test_bitmap(), test_bitmap_colors(), test_bmBits(), test_CreateBitmap(), test_CreateBitmapFromHICON(), test_GdiAlphaBlend(), test_get16dibits(), test_GetDIBits(), test_GetDIBits_selected_DDB(), test_mono_bitmap(), test_select_object(), and test_StretchBlt().

◆ CreateBitmapIndirect()

HBITMAP WINAPI CreateBitmapIndirect ( const BITMAP pbm)

Definition at line 277 of file bitmap.c.

279 {
280  HBITMAP bitmap = NULL;
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
HBITMAP WINAPI CreateBitmap(INT Width, INT Height, UINT Planes, UINT BitsPixel, CONST VOID *pUnsafeBits)
Definition: bitmap.c:254
Definition: uimain.c:88
#define SetLastError(x)
Definition: compat.h:611
#define NULL
Definition: types.h:112
static HBITMAP bitmap
Definition: clipboard.c:1344
static HBITMAP
Definition: button.c:44

Referenced by test_CreateBitmap().

◆ 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 
316  if (!GdiGetHandleUserData(hDC, GDI_OBJECT_TYPE_DC, (PVOID) & pDc_Attr))
317  return NULL;
318 
319  if (!Width || !Height)
321 
322  if (!(pDc_Attr->ulDirty_ & DC_DIBSECTION))
323  {
324  return NtGdiCreateCompatibleBitmap(hDC, Width, Height);
325  }
326  else
327  {
328  HBITMAP hBmp = NULL;
329  struct
330  {
331  BITMAP bitmap;
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 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI GetObjectA(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
BITMAPINFOHEADER dsBmih
Definition: wingdi.h:1669
__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
#define DC_DIBSECTION
Definition: ntgdihdl.h:159
GLuint buffer
Definition: glext.h:5915
#define DEFAULT_BITMAP
Definition: ntgdityp.h:195
UINT WINAPI GetDIBColorTable(HDC hDC, UINT iStartIndex, UINT cEntries, RGBQUAD *pColors)
Definition: palette.c:123
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetDCObject(_In_ HDC hdc, _In_ INT itype)
ULONG RGBQUAD
Definition: precomp.h:50
#define GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
static HDC hDC
Definition: 3dtext.c:33
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:68
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:199
Definition: bl.h:1331
BITMAP dsBm
Definition: wingdi.h:1668
#define NULL
Definition: types.h:112
static HBITMAP bitmap
Definition: clipboard.c:1344
static HBITMAP
Definition: button.c:44
#define DIB_RGB_COLORS
Definition: wingdi.h:366

Referenced by CreateDiscardableBitmap(), test_CreateBitmap(), test_createdibitmap(), test_D3DKMTCreateDCFromMemory(), test_dib_formats(), test_GdiAlphaBlend(), test_GetDIBits(), test_GetDIBits_BI_BITFIELDS(), test_GetDIBits_selected_DDB(), test_GetSetDIBits_rtl(), and test_select_object().

◆ 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;
412  HBITMAP hBitmap = NULL;
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 
549 Exit:
550  /* Cleanup converted BITMAPINFO */
551  if ((pbmiConverted != NULL) && (pbmiConverted != Data))
552  {
553  RtlFreeHeap(RtlGetProcessHeap(), 0, pbmiConverted);
554  }
555 
556  return hBitmap;
557 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define abs(i)
Definition: fconv.c:206
__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)
#define DIB_PAL_COLORS
Definition: wingdi.h:365
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define BI_JPEG
Definition: wingdi.h:38
#define CBM_INIT
Definition: wingdi.h:364
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
Definition: Header.h:8
long LONG
Definition: pedump.c:60
#define DEFAULT_BITMAP
Definition: ntgdityp.h:195
static void Exit(void)
Definition: sock.c:1331
unsigned short WORD
Definition: ntddk_ex.h:93
static HDC hDC
Definition: 3dtext.c:33
VOID WINAPI GdiSetLastError(DWORD dwErrCode)
Definition: misc.c:873
int WINAPI GdiGetBitmapBitsSize(BITMAPINFO *lpbmi)
Definition: bitmap.c:163
#define BI_PNG
Definition: wingdi.h:39
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define CBM_CREATDIB
INT WINAPI DIB_GetBitmapInfo(const BITMAPINFOHEADER *header, PLONG width, PLONG height, PWORD planes, PWORD bpp, PLONG compr, PLONG size)
Definition: bitmap.c:99
LPBITMAPINFO WINAPI ConvertBitmapInfo(CONST BITMAPINFO *BitmapInfo, UINT ColorSpec, UINT *BitmapInfoSize, BOOL FollowedByData)
Definition: utils.c:178
static HBITMAP
Definition: button.c:44
#define DPRINT
Definition: sndvol32.h:71
static HBITMAP hBitmap
Definition: timezone.c:26

Referenced by test_createdibitmap(), and test_dib_formats().

◆ 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;
209  HBITMAP hBitmap = NULL;
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 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:382
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define BI_JPEG
Definition: wingdi.h:38
_In_ DWORD _In_ DWORD dwOffset
Definition: ntgdi.h:2032
__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)
#define FALSE
Definition: types.h:117
DWORD biCompression
Definition: amvideo.idl:35
#define SetLastError(x)
Definition: compat.h:611
static HDC hDC
Definition: 3dtext.c:33
#define BI_PNG
Definition: wingdi.h:39
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
LPBITMAPINFO WINAPI ConvertBitmapInfo(CONST BITMAPINFO *BitmapInfo, UINT ColorSpec, UINT *BitmapInfoSize, BOOL FollowedByData)
Definition: utils.c:178
static HBITMAP
Definition: button.c:44
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3238
static HBITMAP hBitmap
Definition: timezone.c:26

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(), ImageList_CreateImage(), InitBitmap(), InitLogo(), InitPerBitDepth(), IntCreate32BppBitmap(), LoadDIBImage(), 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 {
304  return CreateCompatibleBitmap(hDC, Width, Height);
305 }
HBITMAP WINAPI CreateCompatibleBitmap(HDC hDC, INT Width, INT Height)
Definition: bitmap.c:309
static HDC hDC
Definition: 3dtext.c:33

Referenced by test_CreateBitmap().

◆ 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 }
#define max(a, b)
Definition: svc.c:63
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define BI_BITFIELDS
Definition: mmreg.h:507
struct tagRGBTRIPLE RGBTRIPLE
GLsizeiptr size
Definition: glext.h:5919
ULONG RGBQUAD
Definition: precomp.h:50
struct tagBITMAPCOREHEADER BITMAPCOREHEADER
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DIB_RGB_COLORS
Definition: wingdi.h:366
static const BYTE masks[8]
Definition: dib.c:2760

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  {
80  Ret = WIDTH_BYTES_ALIGN32(
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 WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: bitmap.c:9
#define BI_BITFIELDS
Definition: mmreg.h:507
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
struct tagBITMAPCOREHEADER * PBITMAPCOREHEADER
unsigned int UINT
Definition: ndis.h:50
#define BI_RGB
Definition: precomp.h:47

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  {
133  BITMAPV4HEADER *v4hdr = (BITMAPV4HEADER *) header;
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 }
GLint GLint GLsizei width
Definition: gl.h:1546
DWORD bV4SizeImage
Definition: wingdi.h:1497
LONG bV4Height
Definition: wingdi.h:1493
static int __cdecl compr(const void *a, const void *b)
Definition: bidi.c:641
WORD bV4BitCount
Definition: wingdi.h:1495
DWORD bV4V4Compression
Definition: wingdi.h:1496
WORD bV4Planes
Definition: wingdi.h:1494
LONG bV4Width
Definition: wingdi.h:1492
GLsizeiptr size
Definition: glext.h:5919
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
DWORD bpp
Definition: surface.c:185
#define DPRINT
Definition: sndvol32.h:71

Referenced by CreateDIBitmap().

◆ GdiConvertBitmapV5()

HBITMAP WINAPI GdiConvertBitmapV5 ( HBITMAP  in_format_BitMap,
HBITMAP  src_BitMap,
INT  bpp,
INT  unuse 
)

Definition at line 965 of file bitmap.c.

970 {
971  /* FIXME guessing the prototypes */
972 
973  /*
974  * it have create a new bitmap with desired in format,
975  * then convert it src_bitmap to new format
976  * and return it as HBITMAP
977  */
978 
979  return FALSE;
980 }
#define FALSE
Definition: types.h:117

◆ 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  {
173  PBITMAPCOREHEADER Core = (PBITMAPCOREHEADER) lpbmi;
174  Ret =
175  WIDTH_BYTES_ALIGN32(Core->bcWidth * Core->bcPlanes,
176  Core->bcBitCount) * Core->bcHeight;
177  }
178  else /* assume BITMAPINFOHEADER */
179  {
180  if (!(lpbmi->bmiHeader.biCompression) || (lpbmi->bmiHeader.biCompression == BI_BITFIELDS))
181  {
182  Ret = WIDTH_BYTES_ALIGN32(
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 }
#define abs(i)
Definition: fconv.c:206
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: bitmap.c:9
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
#define BI_BITFIELDS
Definition: mmreg.h:507
DWORD biCompression
Definition: amvideo.idl:35
DWORD biSizeImage
Definition: amvideo.idl:36
struct tagBITMAPCOREHEADER * PBITMAPCOREHEADER
unsigned int UINT
Definition: ndis.h:50

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

◆ GetBitmapAttributes()

DWORD WINAPI GetBitmapAttributes ( HBITMAP  hbm)

Definition at line 928 of file bitmap.c.

929 {
932  return 0;
933 }
#define SetLastError(x)
Definition: compat.h:611
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define UNIMPLEMENTED
Definition: debug.h:115

◆ 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 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
#define TRUE
Definition: types.h:120
#define BI_JPEG
Definition: wingdi.h:38
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
DWORD biCompression
Definition: amvideo.idl:35
HBITMAP hbmp
#define SetLastError(x)
Definition: compat.h:611
static HDC hDC
Definition: 3dtext.c:33
VOID WINAPI GdiSetLastError(DWORD dwErrCode)
Definition: misc.c:873
#define BI_PNG
Definition: wingdi.h:39
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI GdiValidateHandle(HGDIOBJ)
Definition: misc.c:712

Referenced by test_createdibitmap(), test_dib_formats(), test_dibsections(), test_get16dibits(), test_GetDIBits(), test_GetDIBits_BI_BITFIELDS(), test_GetDIBits_scanlines(), test_GetDIBits_selected_DDB(), test_GetDIBits_selected_DIB(), test_GetDIBits_top_down(), and test_GetSetDIBits_rtl().

◆ SetBitmapAttributes()

HBITMAP WINAPI SetBitmapAttributes ( HBITMAP  hbm,
DWORD  dwFlags 
)

Definition at line 940 of file bitmap.c.

941 {
944  return 0;
945 }
#define SetLastError(x)
Definition: compat.h:611
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define UNIMPLEMENTED
Definition: debug.h:115

◆ 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 
580  if (!lpvBits || (GDI_HANDLE_GET_TYPE(hBitmap) != GDI_OBJECT_TYPE_BITMAP))
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;
617  dwHeight = pbci->bmciHeader.bcHeight;
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 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define abs(i)
Definition: fconv.c:206
#define TRUE
Definition: types.h:120
struct _BITMAPCOREINFO * PBITMAPCOREINFO
#define BI_JPEG
Definition: wingdi.h:38
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int32_t INT
Definition: typedefs.h:58
BITMAPCOREHEADER bmciHeader
Definition: wingdi.h:1452
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
__kernel_entry W32KAPI HDC APIENTRY NtGdiGetDCforBitmap(_In_ HBITMAP hsurf)
static const WCHAR dwHeight[]
Definition: provider.c:63
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
#define OBJ_PAL
Definition: objidl.idl:1413
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI DeleteDC(_In_ HDC)
#define BI_PNG
Definition: wingdi.h:39
static HDC
Definition: bitmap.c:44
int WINAPI SaveDC(_In_ HDC)
#define NULL
Definition: types.h:112
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: bitmap.c:648
BOOL WINAPI RestoreDC(_In_ HDC, _In_ int)
static HBITMAP hBitmap
Definition: timezone.c:26
HGDIOBJ WINAPI GetCurrentObject(_In_ HDC, _In_ UINT)
Definition: dc.c:441
static const WCHAR dwWidth[]
Definition: provider.c:62

Referenced by test_dib_bits_access(), test_dib_formats(), test_GetDIBits(), test_GetSetDIBits_rtl(), test_SetDIBits(), test_SetDIBits_RLE4(), and test_SetDIBits_RLE8().

◆ 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;
699  ULONG hType = GDI_HANDLE_GET_TYPE(hdc);
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  {
737  _SEH2_TRY
738  {
739  RtlCopyMemory(pvSafeBits, Bits, cjBmpScanSize);
740  }
742  {
743  Hit = TRUE;
744  }
745  _SEH2_END
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 
757  if (!GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID) & pDc_Attr))
758  {
760  return 0;
761  }
762  /*
763  if ( !pDc_Attr || // DC is Public
764  ColorUse == DIB_PAL_COLORS ||
765  ((pConvertedInfo->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER)) &&
766  (pConvertedInfo->bmiHeader.biCompression == BI_JPEG ||
767  pConvertedInfo->bmiHeader.biCompression == BI_PNG )) )*/
768  {
769  LinesCopied = NtGdiSetDIBitsToDeviceInternal(hdc, XDest, YDest, Width, Height, XSrc, YSrc,
770  StartScan, ScanLines, (LPBYTE) pvSafeBits, (LPBITMAPINFO) pConvertedInfo, ColorUse,
771  cjBmpScanSize, ConvertedInfoSize,
772  TRUE,
773  NULL);
774  }
775 Exit:
776  if (Bits != pvSafeBits)
777  RtlFreeHeap(RtlGetProcessHeap(), 0, pvSafeBits);
778  if (lpbmi != pConvertedInfo)
779  RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
780 
781  return LinesCopied;
782 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
#define DIB_PAL_COLORS
Definition: wingdi.h:365
#define TRUE
Definition: types.h:120
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
UINT FASTCALL DIB_BitmapMaxBitsSize(PBITMAPINFO Info, UINT ScanLines)
Definition: bitmap.c:61
int32_t INT
Definition: typedefs.h:58
#define HANDLE_METADC(_RetType, _Func, dwError, hdc,...)
Definition: gdi32p.h:616
ULONG Flags
Definition: ntgdihdl.h:278
_SEH2_TRY
Definition: create.c:4226
int WINAPI StartPage(_In_ HDC)
#define LDC_KILL_DOCUMENT
Definition: ntgdihdl.h:178
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD biCompression
Definition: amvideo.idl:35
void * PVOID
Definition: retypes.h:9
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define LDC_STARTPAGE
Definition: ntgdihdl.h:175
VOID GdiSAPCallback(PLDC pldc)
Definition: misc.c:819
PLDC FASTCALL GdiGetLDC(HDC hDC)
Definition: misc.c:785
#define GetProcessHeap()
Definition: compat.h:595
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static void Exit(void)
Definition: sock.c:1331
#define SetLastError(x)
Definition: compat.h:611
Definition: ntgdihdl.h:275
__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 GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
HDC hdc
Definition: main.c:9
#define LDC_SAPCALLBACK
Definition: ntgdihdl.h:172
_SEH2_END
Definition: create.c:4400
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:68
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define BI_RLE4
Definition: precomp.h:48
#define DPRINT1
Definition: precomp.h:8
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: bitmap.c:648
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
LPBITMAPINFO WINAPI ConvertBitmapInfo(CONST BITMAPINFO *BitmapInfo, UINT ColorSpec, UINT *BitmapInfoSize, BOOL FollowedByData)
Definition: utils.c:178
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define DPRINT
Definition: sndvol32.h:71
#define BI_RLE8
Definition: wingdi.h:35

Referenced by SetDIBits(), test_dib_formats(), test_mono_dibsection(), test_SetDIBitsToDevice(), and test_SetDIBitsToDevice_RLE8().

◆ 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 789 of file bitmap.c.

804 {
805  PDC_ATTR pDc_Attr;
806  PBITMAPINFO pConvertedInfo = NULL;
807  UINT ConvertedInfoSize = 0;
808  INT LinesCopied = 0;
809  UINT cjBmpScanSize = 0;
810  PVOID pvSafeBits = NULL;
811  BOOL Hit = FALSE;
812 
813  DPRINT("StretchDIBits %p : %p : %u\n", lpBits, lpBitsInfo, iUsage);
814 #if 0
815 // Handle something other than a normal dc object.
817  {
819  return MFDRV_StretchBlt( hdc,
820  XDest,
821  YDest,
822  nDestWidth,
823  nDestHeight,
824  XSrc,
825  YSrc,
826  nSrcWidth,
827  nSrcHeight,
828  lpBits,
829  lpBitsInfo,
830  iUsage,
831  dwRop);
832  else
833  {
834  PLDC pLDC = GdiGetLDC(hdc);
835  if ( !pLDC )
836  {
838  return 0;
839  }
840  if (pLDC->iType == LDC_EMFLDC)
841  {
842  return EMFDRV_StretchBlt(hdc,
843  XDest,
844  YDest,
845  nDestWidth,
846  nDestHeight,
847  XSrc,
848  YSrc,
849  nSrcWidth,
850  nSrcHeight,
851  lpBits,
852  lpBitsInfo,
853  iUsage,
854  dwRop);
855  }
856  return 0;
857  }
858  }
859 #endif
860 
861  if ( GdiConvertAndCheckDC(hdc) == NULL ) return 0;
862 
863  pConvertedInfo = ConvertBitmapInfo(lpBitsInfo, iUsage, &ConvertedInfoSize,
864  FALSE);
865  if (!pConvertedInfo)
866  {
867  return 0;
868  }
869 
870  cjBmpScanSize = GdiGetBitmapBitsSize((BITMAPINFO *) pConvertedInfo);
871 
872  if (lpBits)
873  {
874  pvSafeBits = RtlAllocateHeap(GetProcessHeap(), 0, cjBmpScanSize);
875  if (pvSafeBits)
876  {
877  _SEH2_TRY
878  {
879  RtlCopyMemory(pvSafeBits, lpBits, cjBmpScanSize);
880  }
882  {
883  Hit = TRUE;
884  }
885  _SEH2_END
886 
887  if (Hit)
888  {
889  // We don't die, we continue on with a allocated safe pointer to kernel
890  // space.....
891  DPRINT1("StretchDIBits fail to read BitMapInfo: %p or Bits: %p & Size: %u\n",
892  pConvertedInfo, lpBits, cjBmpScanSize);
893  }
894  DPRINT("StretchDIBits Allocate Bits %u!!!\n", cjBmpScanSize);
895  }
896  }
897 
898  if (!GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID) & pDc_Attr))
899  {
901  return 0;
902  }
903  /*
904  if ( !pDc_Attr ||
905  iUsage == DIB_PAL_COLORS ||
906  ((pConvertedInfo->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER)) &&
907  (pConvertedInfo->bmiHeader.biCompression == BI_JPEG ||
908  pConvertedInfo->bmiHeader.biCompression == BI_PNG )) )*/
909  {
910  LinesCopied = NtGdiStretchDIBitsInternal(hdc, XDest, YDest, nDestWidth, nDestHeight, XSrc,
911  YSrc, nSrcWidth, nSrcHeight, pvSafeBits, pConvertedInfo, (DWORD) iUsage, dwRop,
912  ConvertedInfoSize, cjBmpScanSize,
913  NULL);
914  }
915  if (pvSafeBits)
916  RtlFreeHeap(RtlGetProcessHeap(), 0, pvSafeBits);
917  if (lpBitsInfo != pConvertedInfo)
918  RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
919 
920  return LinesCopied;
921 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
HDC WINAPI GdiConvertAndCheckDC(HDC hdc)
Definition: dc.c:416
__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)
#define TRUE
Definition: types.h:120
BOOL MFDRV_StretchBlt(PHYSDEV devDst, struct bitblt_coords *dst, PHYSDEV devSrc, struct bitblt_coords *src, DWORD rop)
Definition: bitblt.c:47
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
BOOL EMFDRV_StretchBlt(PHYSDEV devDst, struct bitblt_coords *dst, PHYSDEV devSrc, struct bitblt_coords *src, DWORD rop)
Definition: bitblt.c:67
int32_t INT
Definition: typedefs.h:58
_SEH2_TRY
Definition: create.c:4226
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
PLDC FASTCALL GdiGetLDC(HDC hDC)
Definition: misc.c:785
#define GetProcessHeap()
Definition: compat.h:595
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
#define GDI_OBJECT_TYPE_METADC
Definition: gdi.h:57
Definition: ntgdihdl.h:275
INT iType
Definition: ntgdihdl.h:279
#define GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
HDC hdc
Definition: main.c:9
_SEH2_END
Definition: create.c:4400
int WINAPI GdiGetBitmapBitsSize(BITMAPINFO *lpbmi)
Definition: bitmap.c:163
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:68
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO _In_ UINT iUsage
Definition: ntgdi.h:2780
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
LPBITMAPINFO WINAPI ConvertBitmapInfo(CONST BITMAPINFO *BitmapInfo, UINT ColorSpec, UINT *BitmapInfoSize, BOOL FollowedByData)
Definition: utils.c:178
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define DPRINT
Definition: sndvol32.h:71
#define LDC_EMFLDC
Definition: gdi_private.h:57

Referenced by check_StretchDIBits_pixel(), check_StretchDIBits_stretch(), and test_dib_formats().