ReactOS 0.4.15-dev-7953-g1f49173
bitmaps.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

INT APIENTRY BITMAP_GetObject (SURFACE *bmp, INT count, LPVOID buffer)
 
HBITMAP FASTCALL BITMAP_CopyBitmap (HBITMAP hBitmap)
 
BOOL NTAPI GreSetBitmapOwner (_In_ HBITMAP hbmp, _In_ ULONG ulOwner)
 
HBITMAP NTAPI GreCreateBitmap (_In_ ULONG nWidth, _In_ ULONG nHeight, _In_ ULONG cPlanes, _In_ ULONG cBitsPixel, _In_opt_ PVOID 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 GreCreateDIBitmapInternal (IN HDC hDc, IN INT cx, IN INT cy, IN DWORD fInit, IN OPTIONAL LPBYTE pjInit, IN OPTIONAL PBITMAPINFO pbmi, IN DWORD iUsage, IN FLONG fl, IN UINT cjMaxBits, IN HANDLE hcmXform)
 
BOOL NTAPI GreGetBitmapDimension (_In_ HBITMAP hBitmap, _Out_ LPSIZE psizDim)
 

Function Documentation

◆ BITMAP_CopyBitmap()

HBITMAP FASTCALL BITMAP_CopyBitmap ( HBITMAP  hBitmap)

Definition at line 714 of file bitmaps.c.

715{
716 HBITMAP hbmNew;
717 SURFACE *psurfSrc, *psurfNew;
718
719 /* Fail, if no source bitmap is given */
720 if (hBitmap == NULL) return 0;
721
722 /* Lock the source bitmap */
724 if (psurfSrc == NULL)
725 {
726 return 0;
727 }
728
729 /* Allocate a new bitmap with the same dimensions as the source bmp */
730 hbmNew = GreCreateBitmapEx(psurfSrc->SurfObj.sizlBitmap.cx,
731 psurfSrc->SurfObj.sizlBitmap.cy,
732 abs(psurfSrc->SurfObj.lDelta),
733 psurfSrc->SurfObj.iBitmapFormat,
734 psurfSrc->SurfObj.fjBitmap & BMF_TOPDOWN,
735 psurfSrc->SurfObj.cjBits,
736 NULL,
737 psurfSrc->flags);
738
739 if (hbmNew)
740 {
741 /* Lock the new bitmap */
742 psurfNew = SURFACE_ShareLockSurface(hbmNew);
743 if (psurfNew)
744 {
745 /* Copy the bitmap bits to the new bitmap buffer */
746 RtlCopyMemory(psurfNew->SurfObj.pvBits,
747 psurfSrc->SurfObj.pvBits,
748 psurfNew->SurfObj.cjBits);
749
750
751 /* Reference the palette of the source bitmap and use it */
752 SURFACE_vSetPalette(psurfNew, psurfSrc->ppal);
753
754 /* Unlock the new surface */
756 }
757 else
758 {
759 /* Failed to lock the bitmap, shouldn't happen */
760 GreDeleteObject(hbmNew);
761 hbmNew = NULL;
762 }
763 }
764
765 /* Unlock the source bitmap and return the handle of the new bitmap */
767 return hbmNew;
768}
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 NULL
Definition: types.h:112
static HBITMAP hBitmap
Definition: timezone.c:26
#define abs(i)
Definition: fconv.c:206
static HBITMAP
Definition: button.c:44
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
SURFOBJ SurfObj
Definition: surface.h:8
struct _PALETTE *const ppal
Definition: surface.h:11
FLONG flags
Definition: surface.h:10
USHORT fjBitmap
Definition: winddi.h:1217
SIZEL sizlBitmap
Definition: winddi.h:1209
PVOID pvBits
Definition: winddi.h:1211
ULONG iBitmapFormat
Definition: winddi.h:1215
LONG lDelta
Definition: winddi.h:1213
ULONG cjBits
Definition: winddi.h:1210
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:136
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1158
#define BMF_TOPDOWN
Definition: winddi.h:1180

Referenced by _Success_(), and NtGdiCreatePatternBrushInternal().

◆ BITMAP_GetObject()

INT APIENTRY BITMAP_GetObject ( SURFACE bmp,
INT  count,
LPVOID  buffer 
)

Definition at line 771 of file bitmaps.c.

772{
773 PBITMAP pBitmap;
774
775 if (!buffer) return sizeof(BITMAP);
776 if ((UINT)Count < sizeof(BITMAP)) return 0;
777
778 /* Always fill a basic BITMAP structure */
779 pBitmap = buffer;
780 pBitmap->bmType = 0;
781 pBitmap->bmWidth = psurf->SurfObj.sizlBitmap.cx;
782 pBitmap->bmHeight = psurf->SurfObj.sizlBitmap.cy;
783 pBitmap->bmPlanes = 1;
784 pBitmap->bmBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
785 pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN16(pBitmap->bmWidth, pBitmap->bmBitsPixel);
786
787 /* Check for DIB section */
788 if (psurf->hSecure)
789 {
790 /* Set bmBits in this case */
791 pBitmap->bmBits = psurf->SurfObj.pvBits;
792 /* DIBs data are 32 bits aligned */
793 pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN32(pBitmap->bmWidth, pBitmap->bmBitsPixel);
794
795 if (Count >= sizeof(DIBSECTION))
796 {
797 /* Fill rest of DIBSECTION */
798 PDIBSECTION pds = buffer;
799
800 pds->dsBmih.biSize = sizeof(BITMAPINFOHEADER);
801 pds->dsBmih.biWidth = pds->dsBm.bmWidth;
802 pds->dsBmih.biHeight = pds->dsBm.bmHeight;
803 pds->dsBmih.biPlanes = pds->dsBm.bmPlanes;
804 pds->dsBmih.biBitCount = pds->dsBm.bmBitsPixel;
805
806 switch (psurf->SurfObj.iBitmapFormat)
807 {
808 case BMF_1BPP:
809 case BMF_4BPP:
810 case BMF_8BPP:
812 break;
813
814 case BMF_16BPP:
815 if (psurf->ppal->flFlags & PAL_RGB16_555)
817 else
819 break;
820
821 case BMF_24BPP:
822 case BMF_32BPP:
823 /* 24/32bpp BI_RGB is actually BGR format */
824 if (psurf->ppal->flFlags & PAL_BGR)
826 else
828 break;
829
830 case BMF_4RLE:
832 break;
833 case BMF_8RLE:
835 break;
836 case BMF_JPEG:
838 break;
839 case BMF_PNG:
841 break;
842 default:
843 ASSERT(FALSE); /* This shouldn't happen */
844 }
845
846 pds->dsBmih.biSizeImage = psurf->SurfObj.cjBits;
847 pds->dsBmih.biXPelsPerMeter = 0;
848 pds->dsBmih.biYPelsPerMeter = 0;
849 pds->dsBmih.biClrUsed = psurf->ppal->NumColors;
850 pds->dsBmih.biClrImportant = psurf->biClrImportant;
851 pds->dsBitfields[0] = psurf->ppal->RedMask;
852 pds->dsBitfields[1] = psurf->ppal->GreenMask;
853 pds->dsBitfields[2] = psurf->ppal->BlueMask;
854 pds->dshSection = psurf->hDIBSection;
855 pds->dsOffset = psurf->dwOffset;
856
857 return sizeof(DIBSECTION);
858 }
859 }
860 else
861 {
862 /* Not set according to wine test, confirmed in win2k */
863 pBitmap->bmBits = NULL;
864 }
865
866 return sizeof(BITMAP);
867}
#define FALSE
Definition: types.h:117
#define BI_RLE4
Definition: precomp.h:57
#define BI_RGB
Definition: precomp.h:56
GLuint buffer
Definition: glext.h:5915
#define BI_BITFIELDS
Definition: mmreg.h:507
#define ASSERT(a)
Definition: mode.c:44
unsigned int UINT
Definition: ndis.h:50
int Count
Definition: noreturn.cpp:7
#define BITMAP
Definition: pedump.c:503
Definition: bl.h:1331
ULONG biClrImportant
Definition: precomp.h:52
USHORT biBitCount
Definition: precomp.h:46
LONG biYPelsPerMeter
Definition: precomp.h:50
ULONG biCompression
Definition: precomp.h:47
LONG biXPelsPerMeter
Definition: precomp.h:49
LONG bmHeight
Definition: wingdi.h:1423
LONG bmWidth
Definition: wingdi.h:1422
WORD bmPlanes
Definition: wingdi.h:1425
WORD bmBitsPixel
Definition: wingdi.h:1426
DWORD dsBitfields[3]
Definition: wingdi.h:1671
DWORD dsOffset
Definition: wingdi.h:1673
HANDLE dshSection
Definition: wingdi.h:1672
BITMAP dsBm
Definition: wingdi.h:1669
BITMAPINFOHEADER dsBmih
Definition: wingdi.h:1670
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:16
#define WIDTH_BYTES_ALIGN16(cx, bpp)
Definition: swimpl.c:17
#define BitsPerFormat(Format)
Definition: surface.h:109
@ PAL_RGB16_555
Definition: palette.h:27
#define BMF_16BPP
Definition: winddi.h:358
#define BMF_8BPP
Definition: winddi.h:357
#define BMF_1BPP
Definition: winddi.h:355
#define BMF_PNG
Definition: winddi.h:364
#define BMF_24BPP
Definition: winddi.h:359
#define BMF_32BPP
Definition: winddi.h:360
#define PAL_BGR
Definition: winddi.h:1564
#define BMF_8RLE
Definition: winddi.h:362
#define BMF_4RLE
Definition: winddi.h:361
#define BMF_4BPP
Definition: winddi.h:356
#define BMF_JPEG
Definition: winddi.h:363
struct tagDIBSECTION DIBSECTION
#define BI_JPEG
Definition: wingdi.h:38
#define BI_PNG
Definition: wingdi.h:39
#define BI_RLE8
Definition: wingdi.h:35

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
@ DDB_SURFACE
Definition: surface.h:73

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;
113 PVOID pvCompressedBits = NULL;
114
115 /* Verify format */
116 if (iFormat < BMF_1BPP || iFormat > BMF_PNG) return NULL;
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;
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 */
163 return hbmp;
164}
#define DPRINT1
Definition: precomp.h:8
HBITMAP hbmp
VOID DecompressBitmap(SIZEL Size, BYTE *CompressedBits, BYTE *UncompressedBits, LONG Delta, ULONG iFormat, ULONG cjSizeImage)
Definition: rlecomp.c:21
GLbitfield flags
Definition: glext.h:7161
long LONG
Definition: pedump.c:60
HSURF hsurf
Definition: winddi.h:1206
UCHAR gajBitsPerFormat[11]
Definition: surface.c:21
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
@ API_BITMAP
Definition: surface.h:76
#define SURFACE_UnlockSurface(pBMObj)
Definition: surface.h:100
#define STYPE_BITMAP
Definition: winddi.h:1175
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3468
_In_ SIZEL sizl
Definition: winddi.h:3467

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

◆ GreCreateDIBitmapInternal()

HBITMAP NTAPI GreCreateDIBitmapInternal ( IN HDC  hDc,
IN INT  cx,
IN INT  cy,
IN DWORD  fInit,
IN OPTIONAL LPBYTE  pjInit,
IN OPTIONAL PBITMAPINFO  pbmi,
IN DWORD  iUsage,
IN FLONG  fl,
IN UINT  cjMaxBits,
IN HANDLE  hcmXform 
)

Definition at line 1718 of file dibobj.c.

1729{
1730 PDC Dc;
1731 HBITMAP Bmp;
1732 USHORT bpp, planes;
1734 HDC hdcDest;
1735
1736 if (!hDc) /* 1bpp monochrome bitmap */
1737 {
1738 // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
1739 hdcDest = NtGdiCreateCompatibleDC(0);
1740 if(!hdcDest)
1741 {
1742 DPRINT1("NtGdiCreateCompatibleDC failed\n");
1743 return NULL;
1744 }
1745 }
1746 else
1747 {
1748 hdcDest = hDc;
1749 }
1750
1751 Dc = DC_LockDc(hdcDest);
1752 if (!Dc)
1753 {
1754 DPRINT1("Failed to lock hdcDest %p\n", hdcDest);
1756 return NULL;
1757 }
1758 /* It's OK to set bpp=0 here, as IntCreateDIBitmap will create a compatible Bitmap
1759 * if bpp != 1 and ignore the real value that was passed */
1760 if (pbmi)
1761 {
1762 if (pbmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
1763 {
1765 bpp = CoreHeader->bcBitCount;
1766 planes = CoreHeader->bcPlanes ? CoreHeader->bcPlanes : 1;
1768 }
1769 else
1770 {
1772 planes = pbmi->bmiHeader.biPlanes ? pbmi->bmiHeader.biPlanes : 1;
1774 }
1775 }
1776 else
1777 {
1778 bpp = 0;
1779 planes = 0;
1780 compression = 0;
1781 }
1782 Bmp = IntCreateDIBitmap(Dc, cx, cy, planes, bpp, compression, fInit, pjInit, cjMaxBits, pbmi, iUsage);
1783 DC_UnlockDc(Dc);
1784
1785 if(!hDc)
1786 {
1787 NtGdiDeleteObjectApp(hdcDest);
1788 }
1789 return Bmp;
1790}
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ uint8_t compression
Definition: btrfs_drv.h:1365
FORCEINLINE VOID DC_UnlockDc(PDC pdc)
Definition: dc.h:238
FORCEINLINE PDC DC_LockDc(HDC hdc)
Definition: dc.h:220
HBITMAP FASTCALL IntCreateDIBitmap(PDC Dc, INT width, INT height, UINT planes, UINT bpp, ULONG compression, DWORD init, LPBYTE bits, ULONG cjMaxBits, PBITMAPINFO data, DWORD coloruse)
Definition: dibobj.c:1540
DWORD bpp
Definition: surface.c:185
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
unsigned long DWORD
Definition: ntddk_ex.h:95
static HDC
Definition: imagelist.c:92
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO _In_ UINT _In_ UINT cjMaxBits
Definition: ntgdi.h:2782
__kernel_entry W32KAPI HDC APIENTRY NtGdiCreateCompatibleDC(_In_opt_ HDC hdc)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO _In_ UINT iUsage
Definition: ntgdi.h:2781
unsigned short USHORT
Definition: pedump.c:61
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
Definition: polytest.cpp:41
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:22

Referenced by GreCreateDIBitmapFromPackedDIB(), IntSynthesizeBitmap(), NtGdiCreateDIBitmapInternal(), and UserLoadImage().

◆ GreGetBitmapDimension()

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

Definition at line 453 of file bitmaps.c.

456{
457 PSURFACE psurfBmp;
458
459 if (hBitmap == NULL)
460 return FALSE;
461
462 /* Lock the bitmap */
464 if (psurfBmp == NULL)
465 {
467 return FALSE;
468 }
469
470 *psizDim = psurfBmp->sizlDim;
471
472 /* Unlock the bitmap */
474
475 return TRUE;
476}
#define TRUE
Definition: types.h:120
SIZEL sizlDim
Definition: surface.h:21

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}
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
@ GDILoObjType_LO_BITMAP_TYPE
Definition: gdi_private.h:35
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
#define GDI_OBJ_HMGR_NONE
Definition: ntgdihdl.h:118
BOOL NTAPI GreSetObjectOwner(HGDIOBJ hobj, ULONG ulOwner)
Definition: gdiobj.c:1255
ULONG NTAPI GreGetObjectOwner(HGDIOBJ hobj)
Definition: gdiobj.c:1192

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