ReactOS  0.4.13-dev-79-gcd489d8
bitmaps.c File Reference
#include <win32k.h>
#include <debug.h>
Include dependency graph for bitmaps.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOL NTAPI GreSetBitmapOwner (_In_ HBITMAP hbmp, _In_ ULONG ulOwner)
 
LONG NTAPI UnsafeSetBitmapBits (_Inout_ PSURFACE psurf, _In_ ULONG cjBits, _In_ const VOID *pvBits)
 
HBITMAP NTAPI GreCreateBitmapEx (_In_ ULONG nWidth, _In_ ULONG nHeight, _In_ ULONG cjWidthBytes, _In_ ULONG iFormat, _In_ USHORT fjBitmap, _In_ ULONG cjSizeImage, _In_opt_ PVOID pvBits, _In_ FLONG flags)
 
HBITMAP NTAPI GreCreateBitmap (_In_ ULONG nWidth, _In_ ULONG nHeight, _In_ ULONG cPlanes, _In_ ULONG cBitsPixel, _In_opt_ PVOID pvBits)
 
HBITMAP APIENTRY NtGdiCreateBitmap (IN INT nWidth, IN INT nHeight, IN UINT cPlanes, IN UINT cBitsPixel, IN OPTIONAL LPBYTE pUnsafeBits)
 
HBITMAP FASTCALL IntCreateCompatibleBitmap (PDC Dc, INT Width, INT Height, UINT Planes, UINT Bpp)
 
HBITMAP APIENTRY NtGdiCreateCompatibleBitmap (HDC hDC, INT Width, INT Height)
 
BOOL NTAPI GreGetBitmapDimension (_In_ HBITMAP hBitmap, _Out_ LPSIZE psizDim)
 
BOOL APIENTRY NtGdiGetBitmapDimension (HBITMAP hBitmap, LPSIZE psizDim)
 
LONG FASTCALL UnsafeGetBitmapBits (PSURFACE psurf, DWORD Bytes, OUT PBYTE pvBits)
 
LONG APIENTRY NtGdiGetBitmapBits (HBITMAP hBitmap, ULONG cjBuffer, OUT OPTIONAL PBYTE pUnsafeBits)
 
LONG APIENTRY NtGdiSetBitmapBits (HBITMAP hBitmap, DWORD Bytes, IN PBYTE pUnsafeBits)
 
BOOL APIENTRY NtGdiSetBitmapDimension (HBITMAP hBitmap, INT Width, INT Height, LPSIZE Size)
 
HBITMAP FASTCALL BITMAP_CopyBitmap (HBITMAP hBitmap)
 
INT APIENTRY BITMAP_GetObject (SURFACE *psurf, INT Count, LPVOID buffer)
 
HDC APIENTRY NtGdiGetDCforBitmap (IN HBITMAP hsurf)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file bitmaps.c.

Function Documentation

◆ BITMAP_CopyBitmap()

HBITMAP FASTCALL BITMAP_CopyBitmap ( HBITMAP  hBitmap)

Definition at line 709 of file bitmaps.c.

710 {
711  HBITMAP hbmNew;
712  SURFACE *psurfSrc, *psurfNew;
713 
714  /* Fail, if no source bitmap is given */
715  if (hBitmap == NULL) return 0;
716 
717  /* Lock the source bitmap */
718  psurfSrc = SURFACE_ShareLockSurface(hBitmap);
719  if (psurfSrc == NULL)
720  {
721  return 0;
722  }
723 
724  /* Allocate a new bitmap with the same dimensions as the source bmp */
725  hbmNew = GreCreateBitmapEx(psurfSrc->SurfObj.sizlBitmap.cx,
726  psurfSrc->SurfObj.sizlBitmap.cy,
727  abs(psurfSrc->SurfObj.lDelta),
728  psurfSrc->SurfObj.iBitmapFormat,
729  psurfSrc->SurfObj.fjBitmap & BMF_TOPDOWN,
730  psurfSrc->SurfObj.cjBits,
731  NULL,
732  psurfSrc->flags);
733 
734  if (hbmNew)
735  {
736  /* Lock the new bitmap */
737  psurfNew = SURFACE_ShareLockSurface(hbmNew);
738  if (psurfNew)
739  {
740  /* Copy the bitmap bits to the new bitmap buffer */
741  RtlCopyMemory(psurfNew->SurfObj.pvBits,
742  psurfSrc->SurfObj.pvBits,
743  psurfNew->SurfObj.cjBits);
744 
745 
746  /* Reference the palette of the source bitmap and use it */
747  SURFACE_vSetPalette(psurfNew, psurfSrc->ppal);
748 
749  /* Unlock the new surface */
750  SURFACE_ShareUnlockSurface(psurfNew);
751  }
752  else
753  {
754  /* Failed to lock the bitmap, shouldn't happen */
755  GreDeleteObject(hbmNew);
756  hbmNew = NULL;
757  }
758  }
759 
760  /* Unlock the source bitmap and return the handle of the new bitmap */
761  SURFACE_ShareUnlockSurface(psurfSrc);
762  return hbmNew;
763 }
#define abs(i)
Definition: fconv.c:206
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1153
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
SIZEL sizlBitmap
Definition: winddi.h:1209
LONG lDelta
Definition: winddi.h:1213
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
struct _PALETTE *const ppal
Definition: surface.h:11
#define BMF_TOPDOWN
Definition: winddi.h:1180
ULONG iBitmapFormat
Definition: winddi.h:1215
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
ULONG cjBits
Definition: winddi.h:1210
SURFOBJ SurfObj
Definition: surface.h:8
smooth NULL
Definition: ftsmooth.c:416
LONG cx
Definition: windef.h:319
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:136
USHORT fjBitmap
Definition: winddi.h:1217
FLONG flags
Definition: surface.h:10
HBITMAP NTAPI GreCreateBitmapEx(_In_ ULONG nWidth, _In_ ULONG nHeight, _In_ ULONG cjWidthBytes, _In_ ULONG iFormat, _In_ USHORT fjBitmap, _In_ ULONG cjSizeImage, _In_opt_ PVOID pvBits, _In_ FLONG flags)
Definition: bitmaps.c:101
PVOID pvBits
Definition: winddi.h:1211
static HBITMAP
Definition: button.c:44
LONG cy
Definition: windef.h:320
static HBITMAP hBitmap
Definition: timezone.c:35

Referenced by _Success_(), and NtGdiCreatePatternBrushInternal().

◆ BITMAP_GetObject()

INT APIENTRY BITMAP_GetObject ( SURFACE psurf,
INT  Count,
LPVOID  buffer 
)

Definition at line 766 of file bitmaps.c.

767 {
768  PBITMAP pBitmap;
769 
770  if (!buffer) return sizeof(BITMAP);
771  if ((UINT)Count < sizeof(BITMAP)) return 0;
772 
773  /* Always fill a basic BITMAP structure */
774  pBitmap = buffer;
775  pBitmap->bmType = 0;
776  pBitmap->bmWidth = psurf->SurfObj.sizlBitmap.cx;
777  pBitmap->bmHeight = psurf->SurfObj.sizlBitmap.cy;
778  pBitmap->bmPlanes = 1;
779  pBitmap->bmBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
780  pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN16(pBitmap->bmWidth, pBitmap->bmBitsPixel);
781 
782  /* Check for DIB section */
783  if (psurf->hSecure)
784  {
785  /* Set bmBits in this case */
786  pBitmap->bmBits = psurf->SurfObj.pvBits;
787  /* DIBs data are 32 bits aligned */
788  pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN32(pBitmap->bmWidth, pBitmap->bmBitsPixel);
789 
790  if (Count >= sizeof(DIBSECTION))
791  {
792  /* Fill rest of DIBSECTION */
793  PDIBSECTION pds = buffer;
794 
795  pds->dsBmih.biSize = sizeof(BITMAPINFOHEADER);
796  pds->dsBmih.biWidth = pds->dsBm.bmWidth;
797  pds->dsBmih.biHeight = pds->dsBm.bmHeight;
798  pds->dsBmih.biPlanes = pds->dsBm.bmPlanes;
799  pds->dsBmih.biBitCount = pds->dsBm.bmBitsPixel;
800 
801  switch (psurf->SurfObj.iBitmapFormat)
802  {
803  case BMF_1BPP:
804  case BMF_4BPP:
805  case BMF_8BPP:
806  pds->dsBmih.biCompression = BI_RGB;
807  break;
808 
809  case BMF_16BPP:
810  if (psurf->ppal->flFlags & PAL_RGB16_555)
811  pds->dsBmih.biCompression = BI_RGB;
812  else
814  break;
815 
816  case BMF_24BPP:
817  case BMF_32BPP:
818  /* 24/32bpp BI_RGB is actually BGR format */
819  if (psurf->ppal->flFlags & PAL_BGR)
820  pds->dsBmih.biCompression = BI_RGB;
821  else
823  break;
824 
825  case BMF_4RLE:
827  break;
828  case BMF_8RLE:
830  break;
831  case BMF_JPEG:
833  break;
834  case BMF_PNG:
835  pds->dsBmih.biCompression = BI_PNG;
836  break;
837  default:
838  ASSERT(FALSE); /* This shouldn't happen */
839  }
840 
841  pds->dsBmih.biSizeImage = psurf->SurfObj.cjBits;
842  pds->dsBmih.biXPelsPerMeter = 0;
843  pds->dsBmih.biYPelsPerMeter = 0;
844  pds->dsBmih.biClrUsed = psurf->ppal->NumColors;
845  pds->dsBmih.biClrImportant = psurf->biClrImportant;
846  pds->dsBitfields[0] = psurf->ppal->RedMask;
847  pds->dsBitfields[1] = psurf->ppal->GreenMask;
848  pds->dsBitfields[2] = psurf->ppal->BlueMask;
849  pds->dshSection = psurf->hDIBSection;
850  pds->dsOffset = psurf->dwOffset;
851 
852  return sizeof(DIBSECTION);
853  }
854  }
855  else
856  {
857  /* Not set according to wine test, confirmed in win2k */
858  pBitmap->bmBits = NULL;
859  }
860 
861  return sizeof(BITMAP);
862 }
#define BMF_24BPP
Definition: winddi.h:359
BITMAPINFOHEADER dsBmih
Definition: wingdi.h:1648
SIZEL sizlBitmap
Definition: winddi.h:1209
#define BMF_32BPP
Definition: winddi.h:360
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:16
DWORD biClrImportant
Definition: amvideo.idl:40
#define BitsPerFormat(Format)
Definition: surface.h:109
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
struct _PALETTE *const ppal
Definition: surface.h:11
#define BI_JPEG
Definition: wingdi.h:38
#define BMF_8RLE
Definition: winddi.h:362
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
GLuint buffer
Definition: glext.h:5915
Definition: xlate.c:10
ULONG iBitmapFormat
Definition: winddi.h:1215
LONG biYPelsPerMeter
Definition: amvideo.idl:38
#define BI_BITFIELDS
Definition: mmreg.h:507
ULONG cjBits
Definition: winddi.h:1210
#define BMF_PNG
Definition: winddi.h:364
SURFOBJ SurfObj
Definition: surface.h:8
DWORD biCompression
Definition: amvideo.idl:35
#define BMF_4RLE
Definition: winddi.h:361
smooth NULL
Definition: ftsmooth.c:416
LONG cx
Definition: windef.h:319
DWORD dsBitfields[3]
Definition: wingdi.h:1649
#define BMF_16BPP
Definition: winddi.h:358
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: swimpl.c:17
DWORD dsOffset
Definition: wingdi.h:1651
DWORD biSizeImage
Definition: amvideo.idl:36
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
HANDLE hSecure
Definition: surface.h:32
HANDLE dshSection
Definition: wingdi.h:1650
DWORD dwOffset
Definition: surface.h:33
#define BI_PNG
Definition: wingdi.h:39
Definition: bl.h:1331
Definition: xlate.c:8
HANDLE hDIBSection
Definition: surface.h:31
BITMAP dsBm
Definition: wingdi.h:1647
unsigned int UINT
Definition: ndis.h:50
#define BI_RLE4
Definition: precomp.h:36
Definition: xlate.c:9
PVOID pvBits
Definition: winddi.h:1211
struct tagDIBSECTION DIBSECTION
#define BI_RLE8
Definition: wingdi.h:35
LONG cy
Definition: windef.h:320
#define BI_RGB
Definition: precomp.h:35
#define BITMAP
Definition: pedump.c:503
#define BMF_JPEG
Definition: winddi.h:363
DWORD biClrImportant
Definition: surface.h:37

Referenced by GreGetObject(), and IntCreateCompatibleBitmap().

◆ GreCreateBitmap()

HBITMAP NTAPI GreCreateBitmap ( _In_ ULONG  nWidth,
_In_ ULONG  nHeight,
_In_ ULONG  cPlanes,
_In_ ULONG  cBitsPixel,
_In_opt_ PVOID  pvBits 
)

Definition at line 172 of file bitmaps.c.

178 {
179  /* Call the extended function */
180  return GreCreateBitmapEx(nWidth,
181  nHeight,
182  0, /* Auto width */
183  BitmapFormat(cBitsPixel * cPlanes, BI_RGB),
184  0, /* No bitmap flags */
185  0, /* Auto size */
186  pvBits,
187  DDB_SURFACE /* DDB */);
188 }
ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression)
Definition: surface.c:39
HBITMAP NTAPI GreCreateBitmapEx(_In_ ULONG nWidth, _In_ ULONG nHeight, _In_ ULONG cjWidthBytes, _In_ ULONG iFormat, _In_ USHORT fjBitmap, _In_ ULONG cjSizeImage, _In_opt_ PVOID pvBits, _In_ FLONG flags)
Definition: bitmaps.c:101
#define BI_RGB
Definition: precomp.h:35

Referenced by CreateStockObjects(), IntCreateCompatibleBitmap(), IntCreateDIBitmap(), NtGdiCreateCompatibleBitmap(), and UserInitialize().

◆ GreCreateBitmapEx()

HBITMAP NTAPI GreCreateBitmapEx ( _In_ ULONG  nWidth,
_In_ ULONG  nHeight,
_In_ ULONG  cjWidthBytes,
_In_ ULONG  iFormat,
_In_ USHORT  fjBitmap,
_In_ ULONG  cjSizeImage,
_In_opt_ PVOID  pvBits,
_In_ FLONG  flags 
)

Definition at line 101 of file bitmaps.c.

110 {
111  PSURFACE psurf;
112  HBITMAP hbmp;
113  PVOID pvCompressedBits = NULL;
114 
115  /* Verify format */
117 
118  /* The infamous RLE hack */
119  if ((iFormat == BMF_4RLE) || (iFormat == BMF_8RLE))
120  {
121  pvCompressedBits = pvBits;
122  pvBits = NULL;
124  }
125 
126  /* Allocate a surface */
128  nWidth,
129  nHeight,
130  iFormat,
131  fjBitmap,
132  cjWidthBytes,
133  pvCompressedBits ? 0 : cjSizeImage,
134  pvBits);
135  if (!psurf)
136  {
137  DPRINT1("SURFACE_AllocSurface failed.\n");
138  return NULL;
139  }
140 
141  /* The infamous RLE hack */
142  if (pvCompressedBits)
143  {
144  SIZEL sizl;
145  LONG lDelta;
146 
147  sizl.cx = nWidth;
148  sizl.cy = nHeight;
149  lDelta = WIDTH_BYTES_ALIGN32(nWidth, gajBitsPerFormat[iFormat]);
150 
151  pvBits = psurf->SurfObj.pvBits;
152  DecompressBitmap(sizl, pvCompressedBits, pvBits, lDelta, iFormat, cjSizeImage);
153  }
154 
155  /* Get the handle for the bitmap */
156  hbmp = (HBITMAP)psurf->SurfObj.hsurf;
157 
158  /* Mark as API bitmap */
159  psurf->flags |= (flags | API_BITMAP);
160 
161  /* Unlock the surface and return */
162  SURFACE_UnlockSurface(psurf);
163  return hbmp;
164 }
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:16
#define STYPE_BITMAP
Definition: winddi.h:1175
#define BMF_8RLE
Definition: winddi.h:362
Definition: xlate.c:10
_In_ SIZEL sizl
Definition: winddi.h:3467
#define BMF_PNG
Definition: winddi.h:364
long LONG
Definition: pedump.c:60
SURFOBJ SurfObj
Definition: surface.h:8
#define BMF_4RLE
Definition: winddi.h:361
HSURF hsurf
Definition: winddi.h:1206
smooth NULL
Definition: ftsmooth.c:416
LONG cx
Definition: windef.h:319
HBITMAP hbmp
PSURFACE NTAPI SURFACE_AllocSurface(_In_ USHORT iType, _In_ ULONG cx, _In_ ULONG cy, _In_ ULONG iFormat, _In_ ULONG fjBitmap, _In_opt_ ULONG cjWidth, _In_opt_ ULONG cjBufSize, _In_opt_ PVOID pvBits)
Definition: surface.c:116
GLbitfield flags
Definition: glext.h:7161
VOID DecompressBitmap(SIZEL Size, BYTE *CompressedBits, BYTE *UncompressedBits, LONG Delta, ULONG iFormat, ULONG cjSizeImage)
Definition: rlecomp.c:21
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
#define SURFACE_UnlockSurface(pBMObj)
Definition: surface.h:100
FLONG flags
Definition: surface.h:10
#define DPRINT1
Definition: precomp.h:8
Definition: xlate.c:9
PVOID pvBits
Definition: winddi.h:1211
static HBITMAP
Definition: button.c:44
UCHAR gajBitsPerFormat[11]
Definition: surface.c:21

Referenced by BITMAP_CopyBitmap(), DIB_CreateDIBSection(), GreCreateBitmap(), IntGdiCreateMaskFromRLE(), IntSetDIBits(), NtGdiSetDIBitsToDeviceInternal(), and NtGdiStretchDIBitsInternal().

◆ GreGetBitmapDimension()

BOOL NTAPI GreGetBitmapDimension ( _In_ HBITMAP  hBitmap,
_Out_ LPSIZE  psizDim 
)

Definition at line 448 of file bitmaps.c.

451 {
452  PSURFACE psurfBmp;
453 
454  if (hBitmap == NULL)
455  return FALSE;
456 
457  /* Lock the bitmap */
458  psurfBmp = SURFACE_ShareLockSurface(hBitmap);
459  if (psurfBmp == NULL)
460  {
462  return FALSE;
463  }
464 
465  *psizDim = psurfBmp->sizlDim;
466 
467  /* Unlock the bitmap */
468  SURFACE_ShareUnlockSurface(psurfBmp);
469 
470  return TRUE;
471 }
#define TRUE
Definition: types.h:120
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
smooth NULL
Definition: ftsmooth.c:416
SIZEL sizlDim
Definition: surface.h:21
static HBITMAP hBitmap
Definition: timezone.c:35
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27

Referenced by co_IntDrawCaret(), and NtGdiGetBitmapDimension().

◆ GreSetBitmapOwner()

BOOL NTAPI GreSetBitmapOwner ( _In_ HBITMAP  hbmp,
_In_ ULONG  ulOwner 
)

FIXME: this is a hack and doesn't handle a race condition properly. It needs to be done in GDIOBJ_vSetObjectOwner atomically.

Definition at line 17 of file bitmaps.c.

20 {
21  /* Check if we have the correct object type */
23  {
24  DPRINT1("Incorrect type for hbmp: %p\n", hbmp);
25  return FALSE;
26  }
27 
30 
31  /* Check if we set public or none */
32  if ((ulOwner == GDI_OBJ_HMGR_PUBLIC) ||
33  (ulOwner == GDI_OBJ_HMGR_NONE))
34  {
35  /* Only allow this for owned objects */
37  {
38  DPRINT1("Cannot change owner for non-powned hbmp\n");
39  return FALSE;
40  }
41  }
42 
43  return GreSetObjectOwner(hbmp, ulOwner);
44 }
BOOL NTAPI GreSetObjectOwner(HGDIOBJ hobj, ULONG ulOwner)
Definition: gdiobj.c:1250
ULONG NTAPI GreGetObjectOwner(HGDIOBJ hobj)
Definition: gdiobj.c:1187
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
HBITMAP hbmp
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
#define DPRINT1
Definition: precomp.h:8
#define GDI_OBJ_HMGR_NONE
Definition: ntgdihdl.h:118

Referenced by CreateBrushInternal(), IntGdiCreatePatternBrush(), IntSetCursorData(), and BRUSH::~BRUSH().

◆ IntCreateCompatibleBitmap()

HBITMAP FASTCALL IntCreateCompatibleBitmap ( PDC  Dc,
INT  Width,
INT  Height,
UINT  Planes,
UINT  Bpp 
)

Definition at line 273 of file bitmaps.c.

279 {
280  HBITMAP Bmp = NULL;
281  PPALETTE ppal;
282 
283  /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
284  if (0 == Width || 0 == Height)
285  {
287  }
288 
289  if (Dc->dctype != DC_TYPE_MEMORY)
290  {
291  PSURFACE psurf;
292 
293  Bmp = GreCreateBitmap(abs(Width),
294  abs(Height),
295  Planes ? Planes : 1,
296  Bpp ? Bpp : Dc->ppdev->gdiinfo.cBitsPixel,
297  NULL);
298  if (Bmp == NULL)
299  {
300  DPRINT1("Failed to allocate a bitmap!\n");
301  return NULL;
302  }
303 
304  psurf = SURFACE_ShareLockSurface(Bmp);
305  ASSERT(psurf);
306 
307  /* Dereference old palette and set new palette */
308  ppal = PALETTE_ShareLockPalette(Dc->ppdev->devinfo.hpalDefault);
309  ASSERT(ppal);
310  SURFACE_vSetPalette(psurf, ppal);
312 
313  /* Set flags */
314  psurf->flags = API_BITMAP;
315  psurf->hdc = NULL; // FIXME:
316  psurf->SurfObj.hdev = (HDEV)Dc->ppdev;
318  }
319  else
320  {
321  DIBSECTION dibs;
322  INT Count;
323  PSURFACE psurf = Dc->dclevel.pSurface;
324  if(!psurf) psurf = psurfDefaultBitmap;
325  Count = BITMAP_GetObject(psurf, sizeof(dibs), &dibs);
326 
327  if (Count == sizeof(BITMAP))
328  {
329  PSURFACE psurfBmp;
330 
331  Bmp = GreCreateBitmap(abs(Width),
332  abs(Height),
333  Planes ? Planes : 1,
334  Bpp ? Bpp : dibs.dsBm.bmBitsPixel,
335  NULL);
336  psurfBmp = SURFACE_ShareLockSurface(Bmp);
337  ASSERT(psurfBmp);
338 
339  /* Dereference old palette and set new palette */
340  SURFACE_vSetPalette(psurfBmp, psurf->ppal);
341 
342  /* Set flags */
343  psurfBmp->flags = API_BITMAP;
344  psurfBmp->hdc = NULL; // FIXME:
345  psurf->SurfObj.hdev = (HDEV)Dc->ppdev;
346  SURFACE_ShareUnlockSurface(psurfBmp);
347  }
348  else if (Count == sizeof(DIBSECTION))
349  {
350  /* A DIB section is selected in the DC */
351  BYTE buf[sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD)] = {0};
352  PVOID Bits;
353  BITMAPINFO* bi = (BITMAPINFO*)buf;
354 
355  bi->bmiHeader.biSize = sizeof(bi->bmiHeader);
356  bi->bmiHeader.biWidth = Width;
357  bi->bmiHeader.biHeight = Height;
358  bi->bmiHeader.biPlanes = Planes ? Planes : dibs.dsBmih.biPlanes;
359  bi->bmiHeader.biBitCount = Bpp ? Bpp : dibs.dsBmih.biBitCount;
361  bi->bmiHeader.biSizeImage = 0;
364  bi->bmiHeader.biClrUsed = dibs.dsBmih.biClrUsed;
366 
368  {
369  /* Copy the color masks */
370  RtlCopyMemory(bi->bmiColors, dibs.dsBitfields, 3*sizeof(RGBQUAD));
371  }
372  else if (bi->bmiHeader.biBitCount <= 8)
373  {
374  /* Copy the color table */
375  UINT Index;
376  PPALETTE PalGDI;
377 
378  if (!psurf->ppal)
379  {
381  return 0;
382  }
383 
384  PalGDI = psurf->ppal;
385 
386  for (Index = 0;
387  Index < 256 && Index < PalGDI->NumColors;
388  Index++)
389  {
390  bi->bmiColors[Index].rgbRed = PalGDI->IndexedColors[Index].peRed;
393  bi->bmiColors[Index].rgbReserved = 0;
394  }
395  }
396 
397  Bmp = DIB_CreateDIBSection(Dc,
398  bi,
400  &Bits,
401  NULL,
402  0,
403  0);
404  return Bmp;
405  }
406  }
407  return Bmp;
408 }
#define abs(i)
Definition: fconv.c:206
BITMAPINFOHEADER dsBmih
Definition: wingdi.h:1648
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
HBITMAP APIENTRY DIB_CreateDIBSection(PDC dc, CONST BITMAPINFO *bmi, UINT usage, LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch)
Definition: dibobj.c:1725
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1454
DWORD biClrImportant
Definition: amvideo.idl:40
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
INT APIENTRY BITMAP_GetObject(SURFACE *psurf, INT Count, LPVOID buffer)
Definition: bitmaps.c:766
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
_Notnull_ PSURFACE psurfDefaultBitmap
Definition: dclife.c:17
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetStockObject(_In_ INT iObject)
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
PALETTEENTRY * IndexedColors
Definition: palette.h:42
struct _PALETTE *const ppal
Definition: surface.h:11
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
LONG biYPelsPerMeter
Definition: amvideo.idl:38
int32_t INT
Definition: typedefs.h:56
#define BI_BITFIELDS
Definition: mmreg.h:507
UCHAR rgbBlue
Definition: inbv.c:122
UCHAR rgbGreen
Definition: inbv.c:123
UCHAR rgbRed
Definition: inbv.c:124
SURFOBJ SurfObj
Definition: surface.h:8
DWORD biCompression
Definition: amvideo.idl:35
smooth NULL
Definition: ftsmooth.c:416
#define DEFAULT_BITMAP
Definition: ntgdityp.h:192
DWORD dsBitfields[3]
Definition: wingdi.h:1649
#define PALETTE_ShareLockPalette(hpal)
Definition: palette.h:57
RGBQUAD bmiColors[1]
Definition: wingdi.h:1455
static const UCHAR Index[8]
Definition: usbohci.c:18
DWORD biSizeImage
Definition: amvideo.idl:36
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:136
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DC_TYPE_MEMORY
Definition: ntgdihdl.h:124
HDEV hdev
Definition: winddi.h:1208
unsigned char BYTE
Definition: mem.h:68
ULONG NumColors
Definition: palette.h:41
FLONG flags
Definition: surface.h:10
Definition: bl.h:1331
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
BITMAP dsBm
Definition: wingdi.h:1647
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
HDC hdc
Definition: surface.h:26
static HBITMAP
Definition: button.c:44
UCHAR rgbReserved
Definition: inbv.c:125
#define DIB_RGB_COLORS
Definition: wingdi.h:366
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
HBITMAP NTAPI GreCreateBitmap(_In_ ULONG nWidth, _In_ ULONG nHeight, _In_ ULONG cPlanes, _In_ ULONG cBitsPixel, _In_opt_ PVOID pvBits)
Definition: bitmaps.c:172

Referenced by IntCreateDIBitmap(), and NtGdiCreateCompatibleBitmap().

◆ NtGdiCreateBitmap()

HBITMAP APIENTRY NtGdiCreateBitmap ( IN INT  nWidth,
IN INT  nHeight,
IN UINT  cPlanes,
IN UINT  cBitsPixel,
IN OPTIONAL LPBYTE  pUnsafeBits 
)

Definition at line 192 of file bitmaps.c.

198 {
199  HBITMAP hbmp;
200  ULONG cRealBpp, cjWidthBytes, iFormat;
202  PSURFACE psurf;
203 
204  /* Calculate bitmap format and real bits per pixel. */
205  iFormat = BitmapFormat(cBitsPixel * cPlanes, BI_RGB);
206  cRealBpp = gajBitsPerFormat[iFormat];
207 
208  /* Calculate width and image size in bytes */
209  cjWidthBytes = WIDTH_BYTES_ALIGN16(nWidth, cRealBpp);
210  cjSize = (ULONGLONG)cjWidthBytes * nHeight;
211 
212  /* Check parameters (possible overflow of cjSize!) */
213  if ((iFormat == 0) || (nWidth <= 0) || (nWidth >= 0x8000000) || (nHeight <= 0) ||
214  (cBitsPixel > 32) || (cPlanes > 32) || (cjSize >= 0x100000000ULL))
215  {
216  DPRINT1("Invalid bitmap format! Width=%d, Height=%d, Bpp=%u, Planes=%u\n",
217  nWidth, nHeight, cBitsPixel, cPlanes);
219  return NULL;
220  }
221 
222  /* Allocate the surface (but don't set the bits) */
224  nWidth,
225  nHeight,
226  iFormat,
227  0,
228  0,
229  0,
230  NULL);
231  if (!psurf)
232  {
233  DPRINT1("SURFACE_AllocSurface failed.\n");
234  return NULL;
235  }
236 
237  /* Mark as API and DDB bitmap */
238  psurf->flags |= (API_BITMAP | DDB_SURFACE);
239 
240  /* Check if we have bits to set */
241  if (pUnsafeBits)
242  {
243  /* Protect with SEH and copy the bits */
244  _SEH2_TRY
245  {
246  ProbeForRead(pUnsafeBits, (SIZE_T)cjSize, 1);
247  UnsafeSetBitmapBits(psurf, cjSize, pUnsafeBits);
248  }
250  {
252  _SEH2_YIELD(return NULL;)
253  }
254  _SEH2_END
255  }
256  else
257  {
258  /* Zero the bits */
259  RtlZeroMemory(psurf->SurfObj.pvBits, psurf->SurfObj.cjBits);
260  }
261 
262  /* Get the handle for the bitmap */
263  hbmp = (HBITMAP)psurf->SurfObj.hsurf;
264 
265  /* Unlock the surface */
266  SURFACE_UnlockSurface(psurf);
267 
268  return hbmp;
269 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define STYPE_BITMAP
Definition: winddi.h:1175
_SEH2_TRY
Definition: create.c:4250
ULONG cjBits
Definition: winddi.h:1210
SURFOBJ SurfObj
Definition: surface.h:8
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
HSURF hsurf
Definition: winddi.h:1206
smooth NULL
Definition: ftsmooth.c:416
ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression)
Definition: surface.c:39
HBITMAP hbmp
BASEOBJECT BaseObject
Definition: surface.h:6
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1106
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
uint64_t ULONGLONG
Definition: typedefs.h:65
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: swimpl.c:17
PSURFACE NTAPI SURFACE_AllocSurface(_In_ USHORT iType, _In_ ULONG cx, _In_ ULONG cy, _In_ ULONG iFormat, _In_ ULONG fjBitmap, _In_opt_ ULONG cjWidth, _In_opt_ ULONG cjBufSize, _In_opt_ PVOID pvBits)
Definition: surface.c:116
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
#define SURFACE_UnlockSurface(pBMObj)
Definition: surface.h:100
ULONG_PTR SIZE_T
Definition: typedefs.h:78
_SEH2_END
Definition: create.c:4424
FLONG flags
Definition: surface.h:10
#define DPRINT1
Definition: precomp.h:8
PVOID pvBits
Definition: winddi.h:1211
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG cjSize
Definition: winddi.h:3634
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
static HBITMAP
Definition: button.c:44
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
LONG NTAPI UnsafeSetBitmapBits(_Inout_ PSURFACE psurf, _In_ ULONG cjBits, _In_ const VOID *pvBits)
Definition: bitmaps.c:48
#define BI_RGB
Definition: precomp.h:35
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
UCHAR gajBitsPerFormat[11]
Definition: surface.c:21

◆ NtGdiCreateCompatibleBitmap()

HBITMAP APIENTRY NtGdiCreateCompatibleBitmap ( HDC  hDC,
INT  Width,
INT  Height 
)

Definition at line 411 of file bitmaps.c.

415 {
416  HBITMAP Bmp;
417  PDC Dc;
418 
419  /* Check parameters */
420  if ((Width <= 0) || (Height <= 0) || ((Width * Height) > 0x3FFFFFFF))
421  {
423  return NULL;
424  }
425 
426  if (!hDC)
427  return GreCreateBitmap(Width, Height, 1, 1, 0);
428 
429  Dc = DC_LockDc(hDC);
430 
431  DPRINT("NtGdiCreateCompatibleBitmap(%p,%d,%d, bpp:%u) = \n",
432  hDC, Width, Height, Dc->ppdev->gdiinfo.cBitsPixel);
433 
434  if (NULL == Dc)
435  {
437  return NULL;
438  }
439 
440  Bmp = IntCreateCompatibleBitmap(Dc, Width, Height, 0, 0);
441 
442  DC_UnlockDc(Dc);
443  return Bmp;
444 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
FORCEINLINE PDC DC_LockDc(HDC hdc)
Definition: dc.h:219
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
HBITMAP FASTCALL IntCreateCompatibleBitmap(PDC Dc, INT Width, INT Height, UINT Planes, UINT Bpp)
Definition: bitmaps.c:273
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: polytest.cpp:40
static HDC hDC
Definition: 3dtext.c:33
FORCEINLINE VOID DC_UnlockDc(PDC pdc)
Definition: dc.h:237
static HBITMAP
Definition: button.c:44
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
HBITMAP NTAPI GreCreateBitmap(_In_ ULONG nWidth, _In_ ULONG nHeight, _In_ ULONG cPlanes, _In_ ULONG cBitsPixel, _In_opt_ PVOID pvBits)
Definition: bitmaps.c:172

◆ NtGdiGetBitmapBits()

LONG APIENTRY NtGdiGetBitmapBits ( HBITMAP  hBitmap,
ULONG  cjBuffer,
OUT OPTIONAL PBYTE  pUnsafeBits 
)

Definition at line 552 of file bitmaps.c.

556 {
557  PSURFACE psurf;
558  ULONG cjSize;
559  LONG ret;
560 
561  /* Check parameters */
562  if (pUnsafeBits != NULL && cjBuffer == 0)
563  {
564  return 0;
565  }
566 
567  /* Lock the bitmap */
569  if (!psurf)
570  {
572  return 0;
573  }
574 
575  /* Calculate the size of the bitmap in bytes */
578  abs(psurf->SurfObj.sizlBitmap.cy);
579 
580  /* If the bits vector is null, the function should return the read size */
581  if (pUnsafeBits == NULL)
582  {
584  return cjSize;
585  }
586 
587  /* Don't copy more bytes than the buffer has */
589 
590  // FIXME: Use MmSecureVirtualMemory
591  _SEH2_TRY
592  {
593  ProbeForWrite(pUnsafeBits, cjBuffer, 1);
594  ret = UnsafeGetBitmapBits(psurf, cjBuffer, pUnsafeBits);
595  }
597  {
598  ret = 0;
599  }
600  _SEH2_END
601 
603 
604  return ret;
605 }
#define abs(i)
Definition: fconv.c:206
SIZEL sizlBitmap
Definition: winddi.h:1209
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
#define BitsPerFormat(Format)
Definition: surface.h:109
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
ULONG iBitmapFormat
Definition: winddi.h:1215
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4250
long LONG
Definition: pedump.c:60
SURFOBJ SurfObj
Definition: surface.h:8
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
LONG cx
Definition: windef.h:319
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: swimpl.c:17
int ret
LONG FASTCALL UnsafeGetBitmapBits(PSURFACE psurf, DWORD Bytes, OUT PBYTE pvBits)
Definition: bitmaps.c:502
_SEH2_END
Definition: create.c:4424
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG cjSize
Definition: winddi.h:3634
_In_ ULONG cjBuffer
Definition: ntgdi.h:2860
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
LONG cy
Definition: windef.h:320
static HBITMAP hBitmap
Definition: timezone.c:35
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27

◆ NtGdiGetBitmapDimension()

BOOL APIENTRY NtGdiGetBitmapDimension ( HBITMAP  hBitmap,
LPSIZE  psizDim 
)

Definition at line 475 of file bitmaps.c.

478 {
479  SIZE dim;
480 
481  if (!GreGetBitmapDimension(hBitmap, &dim))
482  return FALSE;
483 
484  /* Use SEH to copy the data to the caller */
485  _SEH2_TRY
486  {
487  ProbeForWrite(psizDim, sizeof(*psizDim), 1);
488  *psizDim = dim;
489  }
491  {
492  _SEH2_YIELD(return FALSE);
493  }
494  _SEH2_END
495 
496  return TRUE;
497 }
#define TRUE
Definition: types.h:120
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4250
BOOL NTAPI GreGetBitmapDimension(_In_ HBITMAP hBitmap, _Out_ LPSIZE psizDim)
Definition: bitmaps.c:448
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
_SEH2_END
Definition: create.c:4424
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
static HBITMAP hBitmap
Definition: timezone.c:35

◆ NtGdiGetDCforBitmap()

HDC APIENTRY NtGdiGetDCforBitmap ( IN HBITMAP  hsurf)

Definition at line 869 of file bitmaps.c.

871 {
872  HDC hdc = NULL;
873  PSURFACE psurf = SURFACE_ShareLockSurface(hsurf);
874  if (psurf)
875  {
876  hdc = psurf->hdc;
878  }
879  return hdc;
880 }
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
static HDC
Definition: imagelist.c:92
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
smooth NULL
Definition: ftsmooth.c:416
HDC hdc
Definition: main.c:9
HDC hdc
Definition: surface.h:26

◆ NtGdiSetBitmapBits()

LONG APIENTRY NtGdiSetBitmapBits ( HBITMAP  hBitmap,
DWORD  Bytes,
IN PBYTE  pUnsafeBits 
)

Definition at line 609 of file bitmaps.c.

613 {
614  LONG ret;
615  PSURFACE psurf;
616 
617  if (pUnsafeBits == NULL || Bytes == 0)
618  {
619  return 0;
620  }
621 
623  {
624  return 0;
625  }
626 
628  if (psurf == NULL)
629  {
631  return 0;
632  }
633 
634  if (((psurf->flags & API_BITMAP) == 0) ||
635  (psurf->SurfObj.iBitmapFormat > BMF_32BPP))
636  {
637  DPRINT1("Invalid bitmap: iBitmapFormat = %lu, flags = 0x%lx\n",
638  psurf->SurfObj.iBitmapFormat,
639  psurf->flags);
642  return 0;
643  }
644 
645  _SEH2_TRY
646  {
647  /* NOTE: Win2k3 doesn't check WORD alignment here. */
648  ProbeForWrite(pUnsafeBits, Bytes, 1);
649  ret = UnsafeSetBitmapBits(psurf, Bytes, pUnsafeBits);
650  }
652  {
653  ret = 0;
654  }
655  _SEH2_END
656 
658 
659  return ret;
660 }
#define BMF_32BPP
Definition: winddi.h:360
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
_In_ UINT Bytes
Definition: mmcopy.h:9
ULONG iBitmapFormat
Definition: winddi.h:1215
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4250
long LONG
Definition: pedump.c:60
SURFOBJ SurfObj
Definition: surface.h:8
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
int ret
_SEH2_END
Definition: create.c:4424
FLONG flags
Definition: surface.h:10
#define DPRINT1
Definition: precomp.h:8
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
LONG NTAPI UnsafeSetBitmapBits(_Inout_ PSURFACE psurf, _In_ ULONG cjBits, _In_ const VOID *pvBits)
Definition: bitmaps.c:48
static HBITMAP hBitmap
Definition: timezone.c:35
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27

◆ NtGdiSetBitmapDimension()

BOOL APIENTRY NtGdiSetBitmapDimension ( HBITMAP  hBitmap,
INT  Width,
INT  Height,
LPSIZE  Size 
)

Definition at line 663 of file bitmaps.c.

668 {
669  PSURFACE psurf;
670  BOOL Ret = TRUE;
671 
672  if (hBitmap == NULL)
673  return FALSE;
674 
676  if (psurf == NULL)
677  {
679  return FALSE;
680  }
681 
682  if (Size)
683  {
684  _SEH2_TRY
685  {
686  ProbeForWrite(Size, sizeof(SIZE), 1);
687  *Size = psurf->sizlDim;
688  }
690  {
691  Ret = FALSE;
692  }
693  _SEH2_END
694  }
695 
696  /* The dimension is changed even if writing the old value failed */
697  psurf->sizlDim.cx = Width;
698  psurf->sizlDim.cy = Height;
699 
701 
702  return Ret;
703 }
#define TRUE
Definition: types.h:120
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4250
unsigned int BOOL
Definition: ntddk_ex.h:94
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
LONG cx
Definition: windef.h:319
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
_SEH2_END
Definition: create.c:4424
SIZEL sizlDim
Definition: surface.h:21
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
LONG cy
Definition: windef.h:320
static HBITMAP hBitmap
Definition: timezone.c:35
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27

◆ UnsafeGetBitmapBits()

LONG FASTCALL UnsafeGetBitmapBits ( PSURFACE  psurf,
DWORD  Bytes,
OUT PBYTE  pvBits 
)

Definition at line 502 of file bitmaps.c.

506 {
507  PUCHAR pjDst, pjSrc;
508  LONG lDeltaDst, lDeltaSrc, lDeltaSrcAbs;
509  ULONG Y, iSrc, iDst, cbSrc, cbDst, nWidth, nHeight, cBitsPixel;
510 
511  nWidth = psurf->SurfObj.sizlBitmap.cx;
512  nHeight = labs(psurf->SurfObj.sizlBitmap.cy);
513  cBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
514 
515  /* Get pointers */
516  pjSrc = psurf->SurfObj.pvScan0;
517  pjDst = pvBits;
518  lDeltaSrc = psurf->SurfObj.lDelta;
519  lDeltaSrcAbs = labs(lDeltaSrc);
520  lDeltaDst = WIDTH_BYTES_ALIGN16(nWidth, cBitsPixel);
521  NT_ASSERT(lDeltaSrcAbs >= lDeltaDst);
522 
523  cbSrc = nHeight * lDeltaSrcAbs;
524  cbDst = nHeight * lDeltaDst;
525  Bytes = min(Bytes, cbDst);
526 
527  iSrc = iDst = 0;
528  for (Y = 0; Y < nHeight; Y++)
529  {
530  if (iSrc + lDeltaSrcAbs > cbSrc || iDst + lDeltaDst > Bytes)
531  {
532  LONG lDelta = min(cbSrc - iSrc, Bytes - iDst);
533  NT_ASSERT(lDelta >= 0);
534  RtlCopyMemory(pjDst, pjSrc, lDelta);
535  iDst += lDelta;
536  break;
537  }
538 
539  /* Copy one line */
540  RtlCopyMemory(pjDst, pjSrc, lDeltaDst);
541  pjSrc += lDeltaSrc;
542  pjDst += lDeltaDst;
543  iSrc += lDeltaSrcAbs;
544  iDst += lDeltaDst;
545  }
546 
547  return iDst;
548 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
SIZEL sizlBitmap
Definition: winddi.h:1209
LONG lDelta
Definition: winddi.h:1213
#define Y(I)
#define BitsPerFormat(Format)
Definition: surface.h:109
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ UINT Bytes
Definition: mmcopy.h:9
ULONG iBitmapFormat
Definition: winddi.h:1215
long LONG
Definition: pedump.c:60
SURFOBJ SurfObj
Definition: surface.h:8
LONG cx
Definition: windef.h:319
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: swimpl.c:17
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
_Check_return_ long __cdecl labs(_In_ long x)
LONG cy
Definition: windef.h:320
PVOID pvScan0
Definition: winddi.h:1212
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by NtGdiGetBitmapBits().

◆ UnsafeSetBitmapBits()

LONG NTAPI UnsafeSetBitmapBits ( _Inout_ PSURFACE  psurf,
_In_ ULONG  cjBits,
_In_ const VOID pvBits 
)

Definition at line 48 of file bitmaps.c.

52 {
53  PUCHAR pjDst;
54  const UCHAR *pjSrc;
55  LONG lDeltaDst, lDeltaSrc, lDeltaDstAbs;
56  ULONG Y, iSrc, iDst, cbSrc, cbDst, nWidth, nHeight, cBitsPixel;
57 
58  NT_ASSERT(psurf->flags & API_BITMAP);
59  NT_ASSERT(psurf->SurfObj.iBitmapFormat <= BMF_32BPP);
60 
61  nWidth = psurf->SurfObj.sizlBitmap.cx;
62  nHeight = labs(psurf->SurfObj.sizlBitmap.cy);
63  cBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
64 
65  pjDst = psurf->SurfObj.pvScan0;
66  pjSrc = pvBits;
67  lDeltaDst = psurf->SurfObj.lDelta;
68  lDeltaDstAbs = labs(lDeltaDst);
69  lDeltaSrc = WIDTH_BYTES_ALIGN16(nWidth, cBitsPixel);
70  NT_ASSERT(lDeltaSrc <= lDeltaDstAbs);
71 
72  cbDst = lDeltaDstAbs * nHeight;
73  cbSrc = lDeltaSrc * nHeight;
74  cjBits = min(cjBits, cbSrc);
75 
76  iSrc = iDst = 0;
77  for (Y = 0; Y < nHeight; Y++)
78  {
79  if (iSrc + lDeltaSrc > cjBits || iDst + lDeltaDstAbs > cbDst)
80  {
81  LONG lDelta = min(cjBits - iSrc, cbDst - iDst);
82  NT_ASSERT(lDelta >= 0);
83  RtlCopyMemory(pjDst, pjSrc, lDelta);
84  iSrc += lDelta;
85  break;
86  }
87 
88  /* Copy one line */
89  RtlCopyMemory(pjDst, pjSrc, lDeltaSrc);
90  pjSrc += lDeltaSrc;
91  pjDst += lDeltaDst;
92  iSrc += lDeltaSrc;
93  iDst += lDeltaDstAbs;
94  }
95 
96  return iSrc;
97 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define BMF_32BPP
Definition: winddi.h:360
#define Y(I)
#define BitsPerFormat(Format)
Definition: surface.h:109
unsigned char * PUCHAR
Definition: retypes.h:3
long LONG
Definition: pedump.c:60
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: swimpl.c:17
unsigned char UCHAR
Definition: xmlstorage.h:181
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
_Check_return_ long __cdecl labs(_In_ long x)
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by NtGdiCreateBitmap(), and NtGdiSetBitmapBits().