ReactOS  r75919
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)
 
BOOL 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)
 
VOID 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

#define NDEBUG

Definition at line 11 of file bitmaps.c.

Function Documentation

HBITMAP FASTCALL BITMAP_CopyBitmap ( HBITMAP  hBitmap)

Definition at line 675 of file bitmaps.c.

Referenced by _Success_(), and NtGdiCreatePatternBrushInternal().

676 {
677  HBITMAP hbmNew;
678  SURFACE *psurfSrc, *psurfNew;
679 
680  /* Fail, if no source bitmap is given */
681  if (hBitmap == NULL) return 0;
682 
683  /* Lock the source bitmap */
684  psurfSrc = SURFACE_ShareLockSurface(hBitmap);
685  if (psurfSrc == NULL)
686  {
687  return 0;
688  }
689 
690  /* Allocate a new bitmap with the same dimensions as the source bmp */
691  hbmNew = GreCreateBitmapEx(psurfSrc->SurfObj.sizlBitmap.cx,
692  psurfSrc->SurfObj.sizlBitmap.cy,
693  abs(psurfSrc->SurfObj.lDelta),
694  psurfSrc->SurfObj.iBitmapFormat,
695  psurfSrc->SurfObj.fjBitmap & BMF_TOPDOWN,
696  psurfSrc->SurfObj.cjBits,
697  NULL,
698  psurfSrc->flags);
699 
700  if (hbmNew)
701  {
702  /* Lock the new bitmap */
703  psurfNew = SURFACE_ShareLockSurface(hbmNew);
704  if (psurfNew)
705  {
706  /* Copy the bitmap bits to the new bitmap buffer */
707  RtlCopyMemory(psurfNew->SurfObj.pvBits,
708  psurfSrc->SurfObj.pvBits,
709  psurfNew->SurfObj.cjBits);
710 
711 
712  /* Reference the palette of the source bitmap and use it */
713  SURFACE_vSetPalette(psurfNew, psurfSrc->ppal);
714 
715  /* Unlock the new surface */
716  SURFACE_ShareUnlockSurface(psurfNew);
717  }
718  else
719  {
720  /* Failed to lock the bitmap, shouldn't happen */
721  GreDeleteObject(hbmNew);
722  hbmNew = NULL;
723  }
724  }
725 
726  /* Unlock the source bitmap and return the handle of the new bitmap */
727  SURFACE_ShareUnlockSurface(psurfSrc);
728  return hbmNew;
729 }
#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 HBITMAP
Definition: msvc.h:28
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
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:513
LONG cx
Definition: windef.h:347
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:129
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:87
PVOID pvBits
Definition: winddi.h:1211
LONG cy
Definition: windef.h:348
static HBITMAP hBitmap
Definition: timezone.c:34
INT APIENTRY BITMAP_GetObject ( SURFACE psurf,
INT  Count,
LPVOID  buffer 
)

Definition at line 732 of file bitmaps.c.

Referenced by GreGetObject(), and IntCreateCompatibleBitmap().

733 {
734  PBITMAP pBitmap;
735 
736  if (!buffer) return sizeof(BITMAP);
737  if ((UINT)Count < sizeof(BITMAP)) return 0;
738 
739  /* Always fill a basic BITMAP structure */
740  pBitmap = buffer;
741  pBitmap->bmType = 0;
742  pBitmap->bmWidth = psurf->SurfObj.sizlBitmap.cx;
743  pBitmap->bmHeight = psurf->SurfObj.sizlBitmap.cy;
744  pBitmap->bmPlanes = 1;
745  pBitmap->bmBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
746  pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN16(pBitmap->bmWidth, pBitmap->bmBitsPixel);
747 
748  /* Check for DIB section */
749  if (psurf->hSecure)
750  {
751  /* Set bmBits in this case */
752  pBitmap->bmBits = psurf->SurfObj.pvBits;
753  /* DIBs data are 32 bits aligned */
754  pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN32(pBitmap->bmWidth, pBitmap->bmBitsPixel);
755 
756  if (Count >= sizeof(DIBSECTION))
757  {
758  /* Fill rest of DIBSECTION */
759  PDIBSECTION pds = buffer;
760 
761  pds->dsBmih.biSize = sizeof(BITMAPINFOHEADER);
762  pds->dsBmih.biWidth = pds->dsBm.bmWidth;
763  pds->dsBmih.biHeight = pds->dsBm.bmHeight;
764  pds->dsBmih.biPlanes = pds->dsBm.bmPlanes;
765  pds->dsBmih.biBitCount = pds->dsBm.bmBitsPixel;
766 
767  switch (psurf->SurfObj.iBitmapFormat)
768  {
769  case BMF_1BPP:
770  case BMF_4BPP:
771  case BMF_8BPP:
772  pds->dsBmih.biCompression = BI_RGB;
773  break;
774 
775  case BMF_16BPP:
776  if (psurf->ppal->flFlags & PAL_RGB16_555)
777  pds->dsBmih.biCompression = BI_RGB;
778  else
780  break;
781 
782  case BMF_24BPP:
783  case BMF_32BPP:
784  /* 24/32bpp BI_RGB is actually BGR format */
785  if (psurf->ppal->flFlags & PAL_BGR)
786  pds->dsBmih.biCompression = BI_RGB;
787  else
789  break;
790 
791  case BMF_4RLE:
793  break;
794  case BMF_8RLE:
796  break;
797  case BMF_JPEG:
799  break;
800  case BMF_PNG:
801  pds->dsBmih.biCompression = BI_PNG;
802  break;
803  default:
804  ASSERT(FALSE); /* This shouldn't happen */
805  }
806 
807  pds->dsBmih.biSizeImage = psurf->SurfObj.cjBits;
808  pds->dsBmih.biXPelsPerMeter = 0;
809  pds->dsBmih.biYPelsPerMeter = 0;
810  pds->dsBmih.biClrUsed = psurf->ppal->NumColors;
811  pds->dsBmih.biClrImportant = psurf->biClrImportant;
812  pds->dsBitfields[0] = psurf->ppal->RedMask;
813  pds->dsBitfields[1] = psurf->ppal->GreenMask;
814  pds->dsBitfields[2] = psurf->ppal->BlueMask;
815  pds->dshSection = psurf->hDIBSection;
816  pds->dsOffset = psurf->dwOffset;
817 
818  return sizeof(DIBSECTION);
819  }
820  }
821  else
822  {
823  /* Not set according to wine test, confirmed in win2k */
824  pBitmap->bmBits = NULL;
825  }
826 
827  return sizeof(BITMAP);
828 }
#define BMF_24BPP
Definition: winddi.h:359
BITMAPINFOHEADER dsBmih
Definition: wingdi.h:1647
SIZEL sizlBitmap
Definition: winddi.h:1209
#define BMF_32BPP
Definition: winddi.h:360
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:26
DWORD biClrImportant
Definition: amvideo.idl:40
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define BitsPerFormat(Format)
Definition: surface.h:102
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
Definition: xlate.c:10
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
ULONG iBitmapFormat
Definition: winddi.h:1215
LONG biYPelsPerMeter
Definition: amvideo.idl:38
#define BI_BITFIELDS
Definition: mmreg.h:505
ULONG cjBits
Definition: winddi.h:1210
#define BMF_PNG
Definition: winddi.h:364
#define FALSE
Definition: types.h:117
SURFOBJ SurfObj
Definition: surface.h:8
DWORD biCompression
Definition: amvideo.idl:35
#define BMF_4RLE
Definition: winddi.h:361
smooth NULL
Definition: ftsmooth.c:513
LONG cx
Definition: windef.h:347
DWORD dsBitfields[3]
Definition: wingdi.h:1648
#define BMF_16BPP
Definition: winddi.h:358
DWORD dsOffset
Definition: wingdi.h:1650
DWORD biSizeImage
Definition: amvideo.idl:36
HANDLE hSecure
Definition: surface.h:32
HANDLE dshSection
Definition: wingdi.h:1649
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: surface.h:105
DWORD dwOffset
Definition: surface.h:33
#define BI_PNG
Definition: wingdi.h:39
Definition: bl.h:1253
HANDLE hDIBSection
Definition: surface.h:31
Definition: xlate.c:8
BITMAP dsBm
Definition: wingdi.h:1646
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:348
#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
HBITMAP NTAPI GreCreateBitmap ( _In_ ULONG  nWidth,
_In_ ULONG  nHeight,
_In_ ULONG  cPlanes,
_In_ ULONG  cBitsPixel,
_In_opt_ PVOID  pvBits 
)

Definition at line 158 of file bitmaps.c.

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

164 {
165  /* Call the extended function */
166  return GreCreateBitmapEx(nWidth,
167  nHeight,
168  0, /* Auto width */
169  BitmapFormat(cBitsPixel * cPlanes, BI_RGB),
170  0, /* No bitmap flags */
171  0, /* Auto size */
172  pvBits,
173  DDB_SURFACE /* DDB */);
174 }
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:87
#define BI_RGB
Definition: precomp.h:35
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 87 of file bitmaps.c.

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

96 {
97  PSURFACE psurf;
98  HBITMAP hbmp;
99  PVOID pvCompressedBits = NULL;
100 
101  /* Verify format */
103 
104  /* The infamous RLE hack */
105  if ((iFormat == BMF_4RLE) || (iFormat == BMF_8RLE))
106  {
107  pvCompressedBits = pvBits;
108  pvBits = NULL;
110  }
111 
112  /* Allocate a surface */
114  nWidth,
115  nHeight,
116  iFormat,
117  fjBitmap,
118  cjWidthBytes,
119  pvCompressedBits ? 0 : cjSizeImage,
120  pvBits);
121  if (!psurf)
122  {
123  DPRINT1("SURFACE_AllocSurface failed.\n");
124  return NULL;
125  }
126 
127  /* The infamous RLE hack */
128  if (pvCompressedBits)
129  {
130  SIZEL sizl;
131  LONG lDelta;
132 
133  sizl.cx = nWidth;
134  sizl.cy = nHeight;
135  lDelta = WIDTH_BYTES_ALIGN32(nWidth, gajBitsPerFormat[iFormat]);
136 
137  pvBits = psurf->SurfObj.pvBits;
138  DecompressBitmap(sizl, pvCompressedBits, pvBits, lDelta, iFormat, cjSizeImage);
139  }
140 
141  /* Get the handle for the bitmap */
142  hbmp = (HBITMAP)psurf->SurfObj.hsurf;
143 
144  /* Mark as API bitmap */
145  psurf->flags |= (flags | API_BITMAP);
146 
147  /* Unlock the surface and return */
148  SURFACE_UnlockSurface(psurf);
149  return hbmp;
150 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define HBITMAP
Definition: msvc.h:28
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:26
#define STYPE_BITMAP
Definition: winddi.h:1175
Definition: xlate.c:10
#define BMF_8RLE
Definition: winddi.h:362
_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:513
LONG cx
Definition: windef.h:347
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:93
FLONG flags
Definition: surface.h:10
#define DPRINT1
Definition: precomp.h:8
Definition: xlate.c:9
PVOID pvBits
Definition: winddi.h:1211
HBITMAP hbmp
Definition: msvc.h:60
LONG cy
Definition: windef.h:348
UCHAR gajBitsPerFormat[11]
Definition: surface.c:21
BOOL NTAPI GreGetBitmapDimension ( _In_ HBITMAP  hBitmap,
_Out_ LPSIZE  psizDim 
)

Definition at line 434 of file bitmaps.c.

Referenced by co_IntDrawCaret(), and NtGdiGetBitmapDimension().

437 {
438  PSURFACE psurfBmp;
439 
440  if (hBitmap == NULL)
441  return FALSE;
442 
443  /* Lock the bitmap */
444  psurfBmp = SURFACE_ShareLockSurface(hBitmap);
445  if (psurfBmp == NULL)
446  {
448  return FALSE;
449  }
450 
451  *psizDim = psurfBmp->sizlDim;
452 
453  /* Unlock the bitmap */
454  SURFACE_ShareUnlockSurface(psurfBmp);
455 
456  return TRUE;
457 }
#define TRUE
Definition: types.h:120
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:513
SIZEL sizlDim
Definition: surface.h:21
static HBITMAP hBitmap
Definition: timezone.c:34
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
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 16 of file bitmaps.c.

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

19 {
20  /* Check if we have the correct object type */
22  {
23  DPRINT1("Incorrect type for hbmp: %p\n", hbmp);
24  return FALSE;
25  }
26 
29 
30  /* Check if we set public or none */
31  if ((ulOwner == GDI_OBJ_HMGR_PUBLIC) ||
32  (ulOwner == GDI_OBJ_HMGR_NONE))
33  {
34  /* Only allow this for owned objects */
36  {
37  DPRINT1("Cannot change owner for non-powned hbmp\n");
38  return FALSE;
39  }
40  }
41 
42  return GreSetObjectOwner(hbmp, ulOwner);
43 }
BOOL NTAPI GreSetObjectOwner(HGDIOBJ hobj, ULONG ulOwner)
Definition: gdiobj.c:1250
ULONG NTAPI GreGetObjectOwner(HGDIOBJ hobj)
Definition: gdiobj.c:1187
#define FALSE
Definition: types.h:117
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#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
HBITMAP hbmp
Definition: msvc.h:60
HBITMAP FASTCALL IntCreateCompatibleBitmap ( PDC  Dc,
INT  Width,
INT  Height,
UINT  Planes,
UINT  Bpp 
)

Definition at line 259 of file bitmaps.c.

Referenced by IntCreateDIBitmap(), and NtGdiCreateCompatibleBitmap().

265 {
266  HBITMAP Bmp = NULL;
267  PPALETTE ppal;
268 
269  /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
270  if (0 == Width || 0 == Height)
271  {
273  }
274 
275  if (Dc->dctype != DC_TYPE_MEMORY)
276  {
277  PSURFACE psurf;
278 
279  Bmp = GreCreateBitmap(abs(Width),
280  abs(Height),
281  Planes ? Planes : 1,
282  Bpp ? Bpp : Dc->ppdev->gdiinfo.cBitsPixel,
283  NULL);
284  if (Bmp == NULL)
285  {
286  DPRINT1("Failed to allocate a bitmap!\n");
287  return NULL;
288  }
289 
290  psurf = SURFACE_ShareLockSurface(Bmp);
291  ASSERT(psurf);
292 
293  /* Dereference old palette and set new palette */
294  ppal = PALETTE_ShareLockPalette(Dc->ppdev->devinfo.hpalDefault);
295  ASSERT(ppal);
296  SURFACE_vSetPalette(psurf, ppal);
298 
299  /* Set flags */
300  psurf->flags = API_BITMAP;
301  psurf->hdc = NULL; // FIXME:
302  psurf->SurfObj.hdev = (HDEV)Dc->ppdev;
304  }
305  else
306  {
307  DIBSECTION dibs;
308  INT Count;
309  PSURFACE psurf = Dc->dclevel.pSurface;
310  if(!psurf) psurf = psurfDefaultBitmap;
311  Count = BITMAP_GetObject(psurf, sizeof(dibs), &dibs);
312 
313  if (Count == sizeof(BITMAP))
314  {
315  PSURFACE psurfBmp;
316 
317  Bmp = GreCreateBitmap(abs(Width),
318  abs(Height),
319  Planes ? Planes : 1,
320  Bpp ? Bpp : dibs.dsBm.bmBitsPixel,
321  NULL);
322  psurfBmp = SURFACE_ShareLockSurface(Bmp);
323  ASSERT(psurfBmp);
324 
325  /* Dereference old palette and set new palette */
326  SURFACE_vSetPalette(psurfBmp, psurf->ppal);
327 
328  /* Set flags */
329  psurfBmp->flags = API_BITMAP;
330  psurfBmp->hdc = NULL; // FIXME:
331  psurf->SurfObj.hdev = (HDEV)Dc->ppdev;
332  SURFACE_ShareUnlockSurface(psurfBmp);
333  }
334  else if (Count == sizeof(DIBSECTION))
335  {
336  /* A DIB section is selected in the DC */
337  BYTE buf[sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD)] = {0};
338  PVOID Bits;
339  BITMAPINFO* bi = (BITMAPINFO*)buf;
340 
341  bi->bmiHeader.biSize = sizeof(bi->bmiHeader);
342  bi->bmiHeader.biWidth = Width;
343  bi->bmiHeader.biHeight = Height;
344  bi->bmiHeader.biPlanes = Planes ? Planes : dibs.dsBmih.biPlanes;
345  bi->bmiHeader.biBitCount = Bpp ? Bpp : dibs.dsBmih.biBitCount;
347  bi->bmiHeader.biSizeImage = 0;
350  bi->bmiHeader.biClrUsed = dibs.dsBmih.biClrUsed;
352 
354  {
355  /* Copy the color masks */
356  RtlCopyMemory(bi->bmiColors, dibs.dsBitfields, 3*sizeof(RGBQUAD));
357  }
358  else if (bi->bmiHeader.biBitCount <= 8)
359  {
360  /* Copy the color table */
361  UINT Index;
362  PPALETTE PalGDI;
363 
364  if (!psurf->ppal)
365  {
367  return 0;
368  }
369 
370  PalGDI = psurf->ppal;
371 
372  for (Index = 0;
373  Index < 256 && Index < PalGDI->NumColors;
374  Index++)
375  {
376  bi->bmiColors[Index].rgbRed = PalGDI->IndexedColors[Index].peRed;
379  bi->bmiColors[Index].rgbReserved = 0;
380  }
381  }
382 
383  Bmp = DIB_CreateDIBSection(Dc,
384  bi,
386  &Bits,
387  NULL,
388  0,
389  0);
390  return Bmp;
391  }
392  }
393  return Bmp;
394 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define abs(i)
Definition: fconv.c:206
BITMAPINFOHEADER dsBmih
Definition: wingdi.h:1647
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
#define HBITMAP
Definition: msvc.h:28
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1453
DWORD biClrImportant
Definition: amvideo.idl:40
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
INT APIENTRY BITMAP_GetObject(SURFACE *psurf, INT Count, LPVOID buffer)
Definition: bitmaps.c:732
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
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
_Must_inspect_result_ _In_ ULONG Index
Definition: fltkernel.h:1824
LONG biYPelsPerMeter
Definition: amvideo.idl:38
int32_t INT
Definition: typedefs.h:57
#define BI_BITFIELDS
Definition: mmreg.h:505
UCHAR rgbBlue
Definition: inbv.c:96
UCHAR rgbGreen
Definition: inbv.c:97
UCHAR rgbRed
Definition: inbv.c:98
SURFOBJ SurfObj
Definition: surface.h:8
DWORD biCompression
Definition: amvideo.idl:35
#define DEFAULT_BITMAP
Definition: CreateBitmap.c:12
smooth NULL
Definition: ftsmooth.c:513
DWORD dsBitfields[3]
Definition: wingdi.h:1648
#define PALETTE_ShareLockPalette(hpal)
Definition: palette.h:57
RGBQUAD bmiColors[1]
Definition: wingdi.h:1454
DWORD biSizeImage
Definition: amvideo.idl:36
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:129
#define DC_TYPE_MEMORY
Definition: ntgdihdl.h:124
HDEV hdev
Definition: winddi.h:1208
ULONG NumColors
Definition: palette.h:41
unsigned char BYTE
Definition: ntddk_ex.h:96
FLONG flags
Definition: surface.h:10
Definition: bl.h:1253
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
BITMAP dsBm
Definition: wingdi.h:1646
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
HDC hdc
Definition: surface.h:26
UCHAR rgbReserved
Definition: inbv.c:99
#define DIB_RGB_COLORS
Definition: wingdi.h:365
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:158
HBITMAP APIENTRY NtGdiCreateBitmap ( IN INT  nWidth,
IN INT  nHeight,
IN UINT  cPlanes,
IN UINT  cBitsPixel,
IN OPTIONAL LPBYTE  pUnsafeBits 
)

Definition at line 178 of file bitmaps.c.

184 {
185  HBITMAP hbmp;
186  ULONG cRealBpp, cjWidthBytes, iFormat;
188  PSURFACE psurf;
189 
190  /* Calculate bitmap format and real bits per pixel. */
191  iFormat = BitmapFormat(cBitsPixel * cPlanes, BI_RGB);
192  cRealBpp = gajBitsPerFormat[iFormat];
193 
194  /* Calculate width and image size in bytes */
195  cjWidthBytes = WIDTH_BYTES_ALIGN16(nWidth, cRealBpp);
196  cjSize = (ULONGLONG)cjWidthBytes * nHeight;
197 
198  /* Check parameters (possible overflow of cjSize!) */
199  if ((iFormat == 0) || (nWidth <= 0) || (nWidth >= 0x8000000) || (nHeight <= 0) ||
200  (cBitsPixel > 32) || (cPlanes > 32) || (cjSize >= 0x100000000ULL))
201  {
202  DPRINT1("Invalid bitmap format! Width=%d, Height=%d, Bpp=%u, Planes=%u\n",
203  nWidth, nHeight, cBitsPixel, cPlanes);
205  return NULL;
206  }
207 
208  /* Allocate the surface (but don't set the bits) */
210  nWidth,
211  nHeight,
212  iFormat,
213  0,
214  0,
215  0,
216  NULL);
217  if (!psurf)
218  {
219  DPRINT1("SURFACE_AllocSurface failed.\n");
220  return NULL;
221  }
222 
223  /* Mark as API and DDB bitmap */
224  psurf->flags |= (API_BITMAP | DDB_SURFACE);
225 
226  /* Check if we have bits to set */
227  if (pUnsafeBits)
228  {
229  /* Protect with SEH and copy the bits */
230  _SEH2_TRY
231  {
232  ProbeForRead(pUnsafeBits, (SIZE_T)cjSize, 1);
233  UnsafeSetBitmapBits(psurf, cjSize, pUnsafeBits);
234  }
236  {
238  _SEH2_YIELD(return NULL;)
239  }
240  _SEH2_END
241  }
242  else
243  {
244  /* Zero the bits */
245  RtlZeroMemory(psurf->SurfObj.pvBits, psurf->SurfObj.cjBits);
246  }
247 
248  /* Get the handle for the bitmap */
249  hbmp = (HBITMAP)psurf->SurfObj.hsurf;
250 
251  /* Unlock the surface */
252  SURFACE_UnlockSurface(psurf);
253 
254  return hbmp;
255 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define HBITMAP
Definition: msvc.h:28
#define STYPE_BITMAP
Definition: winddi.h:1175
ULONG cjBits
Definition: winddi.h:1210
#define _SEH2_END
Definition: pseh2_64.h:7
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:513
BOOL NTAPI UnsafeSetBitmapBits(_Inout_ PSURFACE psurf, _In_ ULONG cjBits, _In_ const VOID *pvBits)
Definition: bitmaps.c:47
ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression)
Definition: surface.c:39
#define ULL(a, b)
Definition: format_msg.c:27
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:66
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:93
ULONG_PTR SIZE_T
Definition: typedefs.h:79
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: surface.h:105
FLONG flags
Definition: surface.h:10
#define _SEH2_TRY
Definition: pseh2_64.h:5
#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:262
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
HBITMAP hbmp
Definition: msvc.h:60
#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
HBITMAP APIENTRY NtGdiCreateCompatibleBitmap ( HDC  hDC,
INT  Width,
INT  Height 
)

Definition at line 397 of file bitmaps.c.

401 {
402  HBITMAP Bmp;
403  PDC Dc;
404 
405  /* Check parameters */
406  if ((Width <= 0) || (Height <= 0) || ((Width * Height) > 0x3FFFFFFF))
407  {
409  return NULL;
410  }
411 
412  if (!hDC)
413  return GreCreateBitmap(Width, Height, 1, 1, 0);
414 
415  Dc = DC_LockDc(hDC);
416 
417  DPRINT("NtGdiCreateCompatibleBitmap(%p,%d,%d, bpp:%u) = \n",
418  hDC, Width, Height, Dc->ppdev->gdiinfo.cBitsPixel);
419 
420  if (NULL == Dc)
421  {
423  return NULL;
424  }
425 
426  Bmp = IntCreateCompatibleBitmap(Dc, Width, Height, 0, 0);
427 
428  DC_UnlockDc(Dc);
429  return Bmp;
430 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define HBITMAP
Definition: msvc.h:28
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:259
smooth NULL
Definition: ftsmooth.c:513
void DPRINT(...)
Definition: polytest.cpp:61
HDC hDC
Definition: wglext.h:521
Definition: polytest.cpp:40
FORCEINLINE VOID DC_UnlockDc(PDC pdc)
Definition: dc.h:237
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:158
LONG APIENTRY NtGdiGetBitmapBits ( HBITMAP  hBitmap,
ULONG  cjBuffer,
OUT OPTIONAL PBYTE  pUnsafeBits 
)

Definition at line 518 of file bitmaps.c.

522 {
523  PSURFACE psurf;
524  ULONG cjSize;
525  LONG ret;
526 
527  /* Check parameters */
528  if (pUnsafeBits != NULL && cjBuffer == 0)
529  {
530  return 0;
531  }
532 
533  /* Lock the bitmap */
535  if (!psurf)
536  {
538  return 0;
539  }
540 
541  /* Calculate the size of the bitmap in bytes */
542  cjSize = WIDTH_BYTES_ALIGN16(psurf->SurfObj.sizlBitmap.cx,
544  abs(psurf->SurfObj.sizlBitmap.cy);
545 
546  /* If the bits vector is null, the function should return the read size */
547  if (pUnsafeBits == NULL)
548  {
550  return cjSize;
551  }
552 
553  /* Don't copy more bytes than the buffer has */
554  cjBuffer = min(cjBuffer, cjSize);
555 
556  // FIXME: Use MmSecureVirtualMemory
557  _SEH2_TRY
558  {
559  ProbeForWrite(pUnsafeBits, cjBuffer, 1);
560  UnsafeGetBitmapBits(psurf, cjBuffer, pUnsafeBits);
561  ret = cjBuffer;
562  }
564  {
565  ret = 0;
566  }
567  _SEH2_END
568 
570 
571  return ret;
572 }
#define abs(i)
Definition: fconv.c:206
SIZEL sizlBitmap
Definition: winddi.h:1209
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
#define BitsPerFormat(Format)
Definition: surface.h:102
#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
long LONG
Definition: pedump.c:60
#define _SEH2_END
Definition: pseh2_64.h:7
SURFOBJ SurfObj
Definition: surface.h:8
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:513
LONG cx
Definition: windef.h:347
VOID FASTCALL UnsafeGetBitmapBits(PSURFACE psurf, DWORD Bytes, OUT PBYTE pvBits)
Definition: bitmaps.c:488
int ret
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: surface.h:105
#define _SEH2_TRY
Definition: pseh2_64.h:5
#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:348
static HBITMAP hBitmap
Definition: timezone.c:34
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
BOOL APIENTRY NtGdiGetBitmapDimension ( HBITMAP  hBitmap,
LPSIZE  psizDim 
)

Definition at line 461 of file bitmaps.c.

464 {
465  SIZE dim;
466 
467  if (!GreGetBitmapDimension(hBitmap, &dim))
468  return FALSE;
469 
470  /* Use SEH to copy the data to the caller */
471  _SEH2_TRY
472  {
473  ProbeForWrite(psizDim, sizeof(*psizDim), 1);
474  *psizDim = dim;
475  }
477  {
478  _SEH2_YIELD(return FALSE);
479  }
480  _SEH2_END
481 
482  return TRUE;
483 }
#define TRUE
Definition: types.h:120
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
BOOL NTAPI GreGetBitmapDimension(_In_ HBITMAP hBitmap, _Out_ LPSIZE psizDim)
Definition: bitmaps.c:434
#define FALSE
Definition: types.h:117
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define _SEH2_TRY
Definition: pseh2_64.h:5
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
static HBITMAP hBitmap
Definition: timezone.c:34
HDC APIENTRY NtGdiGetDCforBitmap ( IN HBITMAP  hsurf)

Definition at line 835 of file bitmaps.c.

837 {
838  HDC hdc = NULL;
839  PSURFACE psurf = SURFACE_ShareLockSurface(hsurf);
840  if (psurf)
841  {
842  hdc = psurf->hdc;
844  }
845  return hdc;
846 }
#define HDC
Definition: msvc.h:22
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
HDC hdc
Definition: msvc.h:53
smooth NULL
Definition: ftsmooth.c:513
HDC hdc
Definition: surface.h:26
LONG APIENTRY NtGdiSetBitmapBits ( HBITMAP  hBitmap,
DWORD  Bytes,
IN PBYTE  pUnsafeBits 
)

Definition at line 576 of file bitmaps.c.

580 {
581  LONG ret;
582  PSURFACE psurf;
583 
584  if (pUnsafeBits == NULL || Bytes == 0)
585  {
586  return 0;
587  }
588 
590  {
591  return 0;
592  }
593 
595  if (psurf == NULL)
596  {
598  return 0;
599  }
600 
601  if (((psurf->flags & API_BITMAP) == 0) ||
602  (psurf->SurfObj.iBitmapFormat > BMF_32BPP))
603  {
604  DPRINT1("Invalid bitmap: iBitmapFormat = %lu, flags = 0x%lx\n",
605  psurf->SurfObj.iBitmapFormat,
606  psurf->flags);
609  return 0;
610  }
611 
612  _SEH2_TRY
613  {
614  ProbeForRead(pUnsafeBits, Bytes, sizeof(WORD));
615  ret = UnsafeSetBitmapBits(psurf, Bytes, pUnsafeBits);
616  }
618  {
619  ret = 0;
620  }
621  _SEH2_END
622 
624 
625  return ret;
626 }
unsigned short WORD
Definition: ntddk_ex.h:93
#define BMF_32BPP
Definition: winddi.h:360
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
#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
long LONG
Definition: pedump.c:60
#define _SEH2_END
Definition: pseh2_64.h:7
SURFOBJ SurfObj
Definition: surface.h:8
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:513
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
BOOL NTAPI UnsafeSetBitmapBits(_Inout_ PSURFACE psurf, _In_ ULONG cjBits, _In_ const VOID *pvBits)
Definition: bitmaps.c:47
int ret
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
FLONG flags
Definition: surface.h:10
#define _SEH2_TRY
Definition: pseh2_64.h:5
#define DPRINT1
Definition: precomp.h:8
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
static HBITMAP hBitmap
Definition: timezone.c:34
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
BOOL APIENTRY NtGdiSetBitmapDimension ( HBITMAP  hBitmap,
INT  Width,
INT  Height,
LPSIZE  Size 
)

Definition at line 629 of file bitmaps.c.

634 {
635  PSURFACE psurf;
636  BOOL Ret = TRUE;
637 
638  if (hBitmap == NULL)
639  return FALSE;
640 
642  if (psurf == NULL)
643  {
645  return FALSE;
646  }
647 
648  if (Size)
649  {
650  _SEH2_TRY
651  {
652  ProbeForWrite(Size, sizeof(SIZE), 1);
653  *Size = psurf->sizlDim;
654  }
656  {
657  Ret = FALSE;
658  }
659  _SEH2_END
660  }
661 
662  /* The dimension is changed even if writing the old value failed */
663  psurf->sizlDim.cx = Width;
664  psurf->sizlDim.cy = Height;
665 
667 
668  return Ret;
669 }
#define TRUE
Definition: types.h:120
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:95
#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
#define FALSE
Definition: types.h:117
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:513
LONG cx
Definition: windef.h:347
unsigned int BOOL
Definition: ntddk_ex.h:94
#define _SEH2_TRY
Definition: pseh2_64.h:5
SIZEL sizlDim
Definition: surface.h:21
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
LONG cy
Definition: windef.h:348
static HBITMAP hBitmap
Definition: timezone.c:34
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
VOID FASTCALL UnsafeGetBitmapBits ( PSURFACE  psurf,
DWORD  Bytes,
OUT PBYTE  pvBits 
)

Definition at line 488 of file bitmaps.c.

Referenced by NtGdiGetBitmapBits().

492 {
493  PUCHAR pjDst, pjSrc;
494  LONG lDeltaDst, lDeltaSrc;
495  ULONG nWidth, nHeight, cBitsPixel;
496 
497  nWidth = psurf->SurfObj.sizlBitmap.cx;
498  nHeight = psurf->SurfObj.sizlBitmap.cy;
499  cBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
500 
501  /* Get pointers */
502  pjSrc = psurf->SurfObj.pvScan0;
503  pjDst = pvBits;
504  lDeltaSrc = psurf->SurfObj.lDelta;
505  lDeltaDst = WIDTH_BYTES_ALIGN16(nWidth, cBitsPixel);
506 
507  while (nHeight--)
508  {
509  /* Copy one line */
510  RtlCopyMemory(pjDst, pjSrc, lDeltaDst);
511  pjSrc += lDeltaSrc;
512  pjDst += lDeltaDst;
513  }
514 }
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 BitsPerFormat(Format)
Definition: surface.h:102
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG iBitmapFormat
Definition: winddi.h:1215
long LONG
Definition: pedump.c:60
SURFOBJ SurfObj
Definition: surface.h:8
LONG cx
Definition: windef.h:347
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: surface.h:105
unsigned int ULONG
Definition: retypes.h:1
LONG cy
Definition: windef.h:348
PVOID pvScan0
Definition: winddi.h:1212
BOOL NTAPI UnsafeSetBitmapBits ( _Inout_ PSURFACE  psurf,
_In_ ULONG  cjBits,
_In_ const VOID pvBits 
)

Definition at line 47 of file bitmaps.c.

Referenced by NtGdiCreateBitmap(), and NtGdiSetBitmapBits().

51 {
52  PUCHAR pjDst;
53  const UCHAR *pjSrc;
54  LONG lDeltaDst, lDeltaSrc;
55  ULONG nWidth, nHeight, cBitsPixel;
56  NT_ASSERT(psurf->flags & API_BITMAP);
57  NT_ASSERT(psurf->SurfObj.iBitmapFormat <= BMF_32BPP);
58 
59  nWidth = psurf->SurfObj.sizlBitmap.cx;
60  nHeight = psurf->SurfObj.sizlBitmap.cy;
61  cBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
62 
63  /* Get pointers */
64  pjDst = psurf->SurfObj.pvScan0;
65  pjSrc = pvBits;
66  lDeltaDst = psurf->SurfObj.lDelta;
67  lDeltaSrc = WIDTH_BYTES_ALIGN16(nWidth, cBitsPixel);
68  NT_ASSERT(lDeltaSrc <= abs(lDeltaDst));
69 
70  /* Make sure the buffer is large enough*/
71  if (cjBits < (lDeltaSrc * nHeight))
72  return FALSE;
73 
74  while (nHeight--)
75  {
76  /* Copy one line */
77  memcpy(pjDst, pjSrc, lDeltaSrc);
78  pjSrc += lDeltaSrc;
79  pjDst += lDeltaDst;
80  }
81 
82  return TRUE;
83 }
#define abs(i)
Definition: fconv.c:206
#define TRUE
Definition: types.h:120
#define BMF_32BPP
Definition: winddi.h:360
#define BitsPerFormat(Format)
Definition: surface.h:102
unsigned char * PUCHAR
Definition: retypes.h:3
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
unsigned char UCHAR
Definition: xmlstorage.h:181
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: surface.h:105
unsigned int ULONG
Definition: retypes.h:1
#define NT_ASSERT
Definition: rtlfuncs.h:3312