ReactOS  0.4.15-dev-5137-g826bd41
dib.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DIB_PAL_BRUSHHACK   3
 

Functions

INT FASTCALL DIB_BitmapInfoSize (const BITMAPINFO *info, WORD coloruse)
 
HBITMAP APIENTRY DIB_CreateDIBSection (PDC dc, CONST BITMAPINFO *bmi, UINT usage, LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch)
 
int FASTCALL DIB_GetBitmapInfo (const BITMAPINFOHEADER *header, LONG *width, LONG *height, WORD *planes, WORD *bpp, DWORD *compr, DWORD *size)
 
INT APIENTRY DIB_GetDIBImageBytes (INT width, INT height, INT depth)
 
HPALETTE FASTCALL DIB_MapPaletteColors (PPALETTE ppal, CONST BITMAPINFO *lpbmi)
 
HPALETTE FASTCALL BuildDIBPalette (CONST BITMAPINFO *bmi)
 
BITMAPINFO *FASTCALL DIB_ConvertBitmapInfo (CONST BITMAPINFO *bmi, DWORD Usage)
 
VOID FASTCALL DIB_FreeConvertedBitmapInfo (BITMAPINFO *converted, BITMAPINFO *orig, DWORD Usage)
 
INT APIENTRY GreGetDIBitsInternal (HDC hDC, HBITMAP hBitmap, UINT StartScan, UINT ScanLines, LPBYTE Bits, LPBITMAPINFO Info, UINT Usage, UINT MaxBits, UINT MaxInfo)
 
HBITMAP NTAPI GreCreateDIBitmapFromPackedDIB (_In_reads_(cjPackedDIB) PVOID pvPackedDIB, _In_ UINT cjPackedDIB, _In_ ULONG uUsage)
 

Macro Definition Documentation

◆ DIB_PAL_BRUSHHACK

#define DIB_PAL_BRUSHHACK   3

Definition at line 36 of file dib.h.

Function Documentation

◆ BuildDIBPalette()

HPALETTE FASTCALL BuildDIBPalette ( CONST BITMAPINFO bmi)

◆ DIB_BitmapInfoSize()

INT FASTCALL DIB_BitmapInfoSize ( const BITMAPINFO info,
WORD  coloruse 
)

Definition at line 2139 of file dibobj.c.

2140 {
2141  unsigned int colors, size, masks = 0;
2142  unsigned int colorsize;
2143 
2144  colorsize = (coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) :
2145  (coloruse == DIB_PAL_INDICES) ? 0 :
2146  sizeof(WORD);
2147 
2148  if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
2149  {
2150  const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)info;
2151  colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
2152  return sizeof(BITMAPCOREHEADER) + colors * colorsize;
2153  }
2154  else /* Assume BITMAPINFOHEADER */
2155  {
2156  colors = info->bmiHeader.biClrUsed;
2157  if (colors > 256) colors = 256;
2158  if (!colors && (info->bmiHeader.biBitCount <= 8))
2159  colors = 1 << info->bmiHeader.biBitCount;
2160  if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
2161  size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) );
2162  return size + colors * colorsize;
2163  }
2164 }
#define max(a, b)
Definition: svc.c:63
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define BI_BITFIELDS
Definition: mmreg.h:507
GLsizeiptr size
Definition: glext.h:5919
ULONG RGBQUAD
Definition: precomp.h:50
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DIB_PAL_INDICES
#define DIB_RGB_COLORS
Definition: wingdi.h:367
static const BYTE masks[8]
Definition: dib.c:2760

Referenced by _Success_(), GreCreateDIBitmapFromPackedDIB(), and NtGdiCreateDIBSection().

◆ DIB_ConvertBitmapInfo()

BITMAPINFO* FASTCALL DIB_ConvertBitmapInfo ( CONST BITMAPINFO bmi,
DWORD  Usage 
)

Definition at line 2212 of file dibobj.c.

2213 {
2215  BITMAPINFO* pNewBmi ;
2216  UINT numColors = 0, ColorsSize = 0;
2217 
2218  if(pbmi->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER)) return (BITMAPINFO*)pbmi;
2219  if(pbmi->bmiHeader.biSize != sizeof(BITMAPCOREHEADER)) return NULL;
2220 
2221  if(pbmci->bmciHeader.bcBitCount <= 8)
2222  {
2223  numColors = 1 << pbmci->bmciHeader.bcBitCount;
2224  if(Usage == DIB_PAL_COLORS)
2225  {
2226  ColorsSize = numColors * sizeof(WORD);
2227  }
2228  else
2229  {
2230  ColorsSize = numColors * sizeof(RGBQUAD);
2231  }
2232  }
2233  else if (Usage == DIB_PAL_COLORS)
2234  {
2235  /* Invalid at high-res */
2236  return NULL;
2237  }
2238 
2239  pNewBmi = ExAllocatePoolWithTag(PagedPool, sizeof(BITMAPINFOHEADER) + ColorsSize, TAG_DIB);
2240  if(!pNewBmi) return NULL;
2241 
2242  RtlZeroMemory(pNewBmi, sizeof(BITMAPINFOHEADER) + ColorsSize);
2243 
2244  pNewBmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2245  pNewBmi->bmiHeader.biBitCount = pbmci->bmciHeader.bcBitCount;
2246  pNewBmi->bmiHeader.biWidth = pbmci->bmciHeader.bcWidth;
2247  pNewBmi->bmiHeader.biHeight = pbmci->bmciHeader.bcHeight;
2248  pNewBmi->bmiHeader.biPlanes = pbmci->bmciHeader.bcPlanes;
2249  pNewBmi->bmiHeader.biCompression = BI_RGB ;
2251  pNewBmi->bmiHeader.biHeight,
2252  pNewBmi->bmiHeader.biBitCount);
2253  pNewBmi->bmiHeader.biClrUsed = numColors;
2254 
2255  if(Usage == DIB_PAL_COLORS)
2256  {
2257  RtlCopyMemory(pNewBmi->bmiColors, pbmci->bmciColors, ColorsSize);
2258  }
2259  else
2260  {
2261  UINT i;
2262  for(i=0; i<numColors; i++)
2263  {
2264  pNewBmi->bmiColors[i].rgbRed = pbmci->bmciColors[i].rgbtRed;
2265  pNewBmi->bmiColors[i].rgbGreen = pbmci->bmciColors[i].rgbtGreen;
2266  pNewBmi->bmiColors[i].rgbBlue = pbmci->bmciColors[i].rgbtBlue;
2267  }
2268  }
2269 
2270  return pNewBmi ;
2271 }
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
#define DIB_PAL_COLORS
Definition: wingdi.h:366
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:382
DWORD biCompression
Definition: amvideo.idl:35
ULONG RGBQUAD
Definition: precomp.h:50
RGBQUAD bmiColors[1]
Definition: wingdi.h:1477
unsigned short WORD
Definition: ntddk_ex.h:93
DWORD biSizeImage
Definition: amvideo.idl:36
INT APIENTRY DIB_GetDIBImageBytes(INT width, INT height, INT depth)
Definition: dibobj.c:2127
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define BI_RGB
Definition: precomp.h:47
#define CONST
Definition: pedump.c:81
#define TAG_DIB
Definition: tags.h:17

Referenced by GreGetDIBitsInternal(), IntSynthesizeBitmap(), and UserLoadImage().

◆ DIB_CreateDIBSection()

HBITMAP APIENTRY DIB_CreateDIBSection ( PDC  dc,
CONST BITMAPINFO bmi,
UINT  usage,
LPVOID bits,
HANDLE  section,
DWORD  offset,
DWORD  ovr_pitch 
)

Definition at line 1885 of file dibobj.c.

1893 {
1894  HBITMAP res = 0;
1895  SURFACE *bmp = NULL;
1896  void *mapBits = NULL;
1897  PPALETTE ppalDIB = NULL;
1898 
1899  // Fill BITMAP32 structure with DIB data
1900  CONST BITMAPINFOHEADER *bi = &bmi->bmiHeader;
1901  INT effHeight;
1902  ULONG totalSize;
1903  BITMAP bm;
1904  //SIZEL Size;
1905  HANDLE hSecure;
1906 
1907  DPRINT("format (%ld,%ld), planes %u, bpp %u, size %lu, colors %lu (%s)\n",
1908  bi->biWidth, bi->biHeight, bi->biPlanes, bi->biBitCount,
1909  bi->biSizeImage, bi->biClrUsed, usage == DIB_PAL_COLORS? "PAL" : "RGB");
1910 
1911  /* CreateDIBSection should fail for compressed formats */
1912  if (bi->biCompression == BI_RLE4 || bi->biCompression == BI_RLE8)
1913  {
1914  DPRINT1("no compressed format allowed\n");
1915  return (HBITMAP)NULL;
1916  }
1917 
1918  effHeight = bi->biHeight >= 0 ? bi->biHeight : -bi->biHeight;
1919  bm.bmType = 0;
1920  bm.bmWidth = bi->biWidth;
1921  bm.bmHeight = effHeight;
1922  bm.bmWidthBytes = ovr_pitch ? ovr_pitch : WIDTH_BYTES_ALIGN32(bm.bmWidth, bi->biBitCount);
1923 
1924  bm.bmPlanes = bi->biPlanes;
1925  bm.bmBitsPixel = bi->biBitCount;
1926  bm.bmBits = NULL;
1927 
1928  // Get storage location for DIB bits. Only use biSizeImage if it's valid and
1929  // we're dealing with a compressed bitmap. Otherwise, use width * height.
1930  totalSize = (bi->biSizeImage && (bi->biCompression != BI_RGB) && (bi->biCompression != BI_BITFIELDS))
1931  ? bi->biSizeImage : (ULONG)(bm.bmWidthBytes * effHeight);
1932 
1933  if (section)
1934  {
1936  NTSTATUS Status;
1937  DWORD mapOffset;
1939  SIZE_T mapSize;
1940 
1942  &Sbi,
1943  sizeof Sbi,
1944  0);
1945  if (!NT_SUCCESS(Status))
1946  {
1947  DPRINT1("ZwQuerySystemInformation failed (0x%lx)\n", Status);
1948  return NULL;
1949  }
1950 
1951  mapOffset = offset - (offset % Sbi.AllocationGranularity);
1952  mapSize = totalSize + (offset - mapOffset);
1953 
1954  SectionOffset.LowPart = mapOffset;
1955  SectionOffset.HighPart = 0;
1956 
1957  Status = ZwMapViewOfSection(section,
1958  NtCurrentProcess(),
1959  &mapBits,
1960  0,
1961  0,
1962  &SectionOffset,
1963  &mapSize,
1964  ViewShare,
1965  0,
1966  PAGE_READWRITE);
1967  if (!NT_SUCCESS(Status))
1968  {
1969  DPRINT1("ZwMapViewOfSection failed (0x%lx)\n", Status);
1971  return NULL;
1972  }
1973 
1974  if (mapBits) bm.bmBits = (char *)mapBits + (offset - mapOffset);
1975  }
1976  else if (ovr_pitch && offset)
1977  bm.bmBits = UlongToPtr(offset);
1978  else
1979  {
1980  offset = 0;
1981  bm.bmBits = EngAllocUserMem(totalSize, 0);
1982  if(!bm.bmBits)
1983  {
1984  DPRINT1("Failed to allocate memory\n");
1985  goto cleanup;
1986  }
1987  }
1988 
1989 // hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE);
1990  hSecure = (HANDLE)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
1991 
1992 
1993  // Create Device Dependent Bitmap and add DIB pointer
1994  //Size.cx = bm.bmWidth;
1995  //Size.cy = abs(bm.bmHeight);
1996  res = GreCreateBitmapEx(bm.bmWidth,
1997  abs(bm.bmHeight),
1998  bm.bmWidthBytes,
1999  BitmapFormat(bi->biBitCount * bi->biPlanes, bi->biCompression),
2001  ((bi->biHeight < 0) ? BMF_TOPDOWN : 0),
2002  totalSize,
2003  bm.bmBits,
2004  0);
2005  if (!res)
2006  {
2007  DPRINT1("GreCreateBitmapEx failed\n");
2009  goto cleanup;
2010  }
2011  bmp = SURFACE_ShareLockSurface(res); // HACK
2012  if (NULL == bmp)
2013  {
2014  DPRINT1("SURFACE_LockSurface failed\n");
2016  goto cleanup;
2017  }
2018 
2019  /* WINE NOTE: WINE makes use of a colormap, which is a color translation
2020  table between the DIB and the X physical device. Obviously,
2021  this is left out of the ReactOS implementation. Instead,
2022  we call NtGdiSetDIBColorTable. */
2023  bmp->hDIBSection = section;
2024  bmp->hSecure = hSecure;
2025  bmp->dwOffset = offset;
2026  bmp->flags = API_BITMAP;
2027  bmp->biClrImportant = bi->biClrImportant;
2028 
2029  /* Create a palette for the DIB */
2030  ppalDIB = CreateDIBPalette(bmi, dc, usage);
2031 
2032  // Clean up in case of errors
2033 cleanup:
2034  if (!res || !bmp || !bm.bmBits || !ppalDIB)
2035  {
2036  DPRINT("Got an error res=%p, bmp=%p, bm.bmBits=%p\n", res, bmp, bm.bmBits);
2037  if (bm.bmBits)
2038  {
2039  // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this!
2040  if (section)
2041  {
2042  ZwUnmapViewOfSection(NtCurrentProcess(), mapBits);
2043  bm.bmBits = NULL;
2044  }
2045  else if (!offset)
2046  EngFreeUserMem(bm.bmBits), bm.bmBits = NULL;
2047  }
2048 
2049  if (bmp)
2050  {
2052  bmp = NULL;
2053  }
2054 
2055  if (res)
2056  {
2058  res = 0;
2059  }
2060 
2061  if(ppalDIB)
2062  {
2063  PALETTE_ShareUnlockPalette(ppalDIB);
2064  }
2065  }
2066 
2067  if (bmp)
2068  {
2069  /* If we're here, everything went fine */
2070  SURFACE_vSetPalette(bmp, ppalDIB);
2071  PALETTE_ShareUnlockPalette(ppalDIB);
2073  }
2074 
2075  // Return BITMAP handle and storage location
2076  if (NULL != bm.bmBits && NULL != bits)
2077  {
2078  *bits = bm.bmBits;
2079  }
2080 
2081  return res;
2082 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define abs(i)
Definition: fconv.c:206
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1158
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:16
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
#define DIB_PAL_COLORS
Definition: wingdi.h:366
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
LONG NTSTATUS
Definition: precomp.h:26
#define BMF_TOPDOWN
Definition: winddi.h:1180
#define SURFACE_ShareLockSurface(hBMObj)
Definition: surface.h:91
Definition: parser.c:55
PPALETTE NTAPI CreateDIBPalette(_In_ const BITMAPINFO *pbmi, _In_ PDC pdc, _In_ ULONG iUsage)
Definition: dibobj.c:41
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
int32_t INT
Definition: typedefs.h:58
#define BI_BITFIELDS
Definition: mmreg.h:507
#define ERROR_NO_SYSTEM_RESOURCES
Definition: winerror.h:931
static IMAGE_SECTION_HEADER section
Definition: loader.c:152
NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
#define BMF_DONTCACHE
Definition: winddi.h:1182
ENGAPI VOID APIENTRY EngFreeUserMem(_Pre_notnull_ __drv_freesMem(UserMem) PVOID pv)
ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression)
Definition: surface.c:39
#define UlongToPtr(u)
Definition: config.h:106
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER SectionOffset
Definition: mmfuncs.h:404
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define BMF_USERMEM
Definition: winddi.h:1183
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
GLintptr offset
Definition: glext.h:5920
PVOID HANDLE
Definition: typedefs.h:73
unsigned long DWORD
Definition: ntddk_ex.h:95
#define BMF_NOZEROINIT
Definition: winddi.h:1181
BITMAP bmp
Definition: alphablend.c:62
FORCEINLINE VOID SURFACE_vSetPalette(_Inout_ PSURFACE psurf, _In_ PPALETTE ppal)
Definition: surface.h:136
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
ULONG_PTR SIZE_T
Definition: typedefs.h:80
Definition: bl.h:1330
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
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
#define BI_RLE4
Definition: precomp.h:48
#define DPRINT1
Definition: precomp.h:8
GLuint res
Definition: glext.h:9613
unsigned int ULONG
Definition: retypes.h:1
char * cleanup(char *str)
Definition: wpickclick.c:99
static const WCHAR dc[]
static HBITMAP
Definition: button.c:44
#define DPRINT
Definition: sndvol32.h:71
#define BI_RLE8
Definition: wingdi.h:35
#define BI_RGB
Definition: precomp.h:47
#define CONST
Definition: pedump.c:81
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by GreGetDIBitsInternal(), IntCreateCompatibleBitmap(), and NtGdiCreateDIBSection().

◆ DIB_FreeConvertedBitmapInfo()

VOID FASTCALL DIB_FreeConvertedBitmapInfo ( BITMAPINFO converted,
BITMAPINFO orig,
DWORD  Usage 
)

Definition at line 2276 of file dibobj.c.

2277 {
2278  BITMAPCOREINFO* pbmci;
2279  if(converted == orig)
2280  return;
2281 
2282  if(usage == -1)
2283  {
2284  /* Caller don't want any conversion */
2285  ExFreePoolWithTag(converted, TAG_DIB);
2286  return;
2287  }
2288 
2289  /* Perform inverse conversion */
2290  pbmci = (BITMAPCOREINFO*)orig;
2291 
2292  ASSERT(pbmci->bmciHeader.bcSize == sizeof(BITMAPCOREHEADER));
2293  pbmci->bmciHeader.bcBitCount = converted->bmiHeader.biBitCount;
2294  pbmci->bmciHeader.bcWidth = converted->bmiHeader.biWidth;
2295  pbmci->bmciHeader.bcHeight = converted->bmiHeader.biHeight;
2296  pbmci->bmciHeader.bcPlanes = converted->bmiHeader.biPlanes;
2297 
2298  if(pbmci->bmciHeader.bcBitCount <= 8)
2299  {
2300  UINT numColors = converted->bmiHeader.biClrUsed;
2301  if(!numColors) numColors = 1 << pbmci->bmciHeader.bcBitCount;
2302  if(usage == DIB_PAL_COLORS)
2303  {
2304  RtlZeroMemory(pbmci->bmciColors, (1 << pbmci->bmciHeader.bcBitCount) * sizeof(WORD));
2305  RtlCopyMemory(pbmci->bmciColors, converted->bmiColors, numColors * sizeof(WORD));
2306  }
2307  else
2308  {
2309  UINT i;
2310  RtlZeroMemory(pbmci->bmciColors, (1 << pbmci->bmciHeader.bcBitCount) * sizeof(RGBTRIPLE));
2311  for(i=0; i<numColors; i++)
2312  {
2313  pbmci->bmciColors[i].rgbtRed = converted->bmiColors[i].rgbRed;
2314  pbmci->bmciColors[i].rgbtGreen = converted->bmiColors[i].rgbGreen;
2315  pbmci->bmciColors[i].rgbtBlue = converted->bmiColors[i].rgbBlue;
2316  }
2317  }
2318  }
2319  /* Now free it, it's not needed anymore */
2320  ExFreePoolWithTag(converted, TAG_DIB);
2321 }
BYTE rgbtBlue
Definition: wingdi.h:1438
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
#define DIB_PAL_COLORS
Definition: wingdi.h:366
BITMAPCOREHEADER bmciHeader
Definition: wingdi.h:1453
RGBTRIPLE bmciColors[1]
Definition: wingdi.h:1454
#define ASSERT(a)
Definition: mode.c:44
RGBQUAD bmiColors[1]
Definition: wingdi.h:1477
unsigned short WORD
Definition: ntddk_ex.h:93
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
BYTE rgbtRed
Definition: wingdi.h:1440
unsigned int UINT
Definition: ndis.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
BYTE rgbtGreen
Definition: wingdi.h:1439
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define TAG_DIB
Definition: tags.h:17

Referenced by GreGetDIBitsInternal(), IntSynthesizeBitmap(), and UserLoadImage().

◆ DIB_GetBitmapInfo()

int FASTCALL DIB_GetBitmapInfo ( const BITMAPINFOHEADER header,
LONG width,
LONG height,
WORD planes,
WORD bpp,
DWORD compr,
DWORD size 
)

Definition at line 2092 of file dibobj.c.

2094 {
2095  if (header->biSize == sizeof(BITMAPCOREHEADER))
2096  {
2097  const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)header;
2098  *width = core->bcWidth;
2099  *height = core->bcHeight;
2100  *planes = core->bcPlanes;
2101  *bpp = core->bcBitCount;
2102  *compr = BI_RGB;
2103  *size = 0;
2104  return 0;
2105  }
2106  if (header->biSize >= sizeof(BITMAPINFOHEADER)) /* Assume BITMAPINFOHEADER */
2107  {
2108  *width = header->biWidth;
2109  *height = header->biHeight;
2110  *planes = header->biPlanes;
2111  *bpp = header->biBitCount;
2112  *compr = header->biCompression;
2113  *size = header->biSizeImage;
2114  return 1;
2115  }
2116  DPRINT1("(%u): unknown/wrong size for header\n", header->biSize );
2117  return -1;
2118 }
GLint GLint GLsizei width
Definition: gl.h:1546
static int __cdecl compr(const void *a, const void *b)
Definition: bidi.c:641
GLsizeiptr size
Definition: glext.h:5919
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define DPRINT1
Definition: precomp.h:8
DWORD bpp
Definition: surface.c:185
#define BI_RGB
Definition: precomp.h:47

Referenced by GreGetDIBitsInternal().

◆ DIB_GetDIBImageBytes()

INT APIENTRY DIB_GetDIBImageBytes ( INT  width,
INT  height,
INT  depth 
)

Definition at line 2127 of file dibobj.c.

2128 {
2129  return WIDTH_BYTES_ALIGN32(width, depth) * (height < 0 ? -height : height);
2130 }
GLint GLint GLsizei width
Definition: gl.h:1546
#define WIDTH_BYTES_ALIGN32(cx, bpp)
Definition: swimpl.c:16
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546

Referenced by DIB_ConvertBitmapInfo(), GreGetDIBitsInternal(), and IntSetDIBits().

◆ DIB_MapPaletteColors()

HPALETTE FASTCALL DIB_MapPaletteColors ( PPALETTE  ppal,
CONST BITMAPINFO lpbmi 
)

Definition at line 2168 of file dibobj.c.

2169 {
2170  PPALETTE ppalNew;
2171  ULONG nNumColors,i;
2172  USHORT *lpIndex;
2173  HPALETTE hpal;
2174 
2175  if (!(ppalDc->flFlags & PAL_INDEXED))
2176  {
2177  return NULL;
2178  }
2179 
2180  nNumColors = 1 << lpbmi->bmiHeader.biBitCount;
2181  if (lpbmi->bmiHeader.biClrUsed)
2182  {
2183  nNumColors = min(nNumColors, lpbmi->bmiHeader.biClrUsed);
2184  }
2185 
2186  ppalNew = PALETTE_AllocPalWithHandle(PAL_INDEXED, nNumColors, NULL, 0, 0, 0);
2187  if (ppalNew == NULL)
2188  {
2189  DPRINT1("Could not allocate palette\n");
2190  return NULL;
2191  }
2192 
2193  lpIndex = (USHORT *)((PBYTE)lpbmi + lpbmi->bmiHeader.biSize);
2194 
2195  for (i = 0; i < nNumColors; i++)
2196  {
2197  ULONG iColorIndex = *lpIndex % ppalDc->NumColors;
2198  ppalNew->IndexedColors[i] = ppalDc->IndexedColors[iColorIndex];
2199  lpIndex++;
2200  }
2201 
2202  hpal = ppalNew->BaseObject.hHmgr;
2203  PALETTE_UnlockPalette(ppalNew);
2204 
2205  return hpal;
2206 }
PALETTEENTRY * IndexedColors
Definition: palette.h:42
#define PALETTE_UnlockPalette(pPalette)
Definition: palette.h:56
HGDIOBJ hHmgr(VOID)
Definition: baseobj.hpp:95
PPALETTE NTAPI PALETTE_AllocPalWithHandle(_In_ ULONG iMode, _In_ ULONG cColors, _In_opt_ const PALETTEENTRY *pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue)
Definition: palette.c:209
BASEOBJECT BaseObject
Definition: palette.h:36
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned short USHORT
Definition: pedump.c:61
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
BYTE * PBYTE
Definition: pedump.c:66

◆ GreCreateDIBitmapFromPackedDIB()

HBITMAP NTAPI GreCreateDIBitmapFromPackedDIB ( _In_reads_(cjPackedDIB) PVOID  pvPackedDIB,
_In_ UINT  cjPackedDIB,
_In_ ULONG  uUsage 
)

Definition at line 1767 of file dibobj.c.

1771 {
1772  PBITMAPINFO pbmi;
1773  PBYTE pjBits;
1774  UINT cjInfo, cjBits;
1775  HBITMAP hbm;
1776 
1777  /* We only support BITMAPINFOHEADER, make sure the size is ok */
1778  if (cjPackedDIB < sizeof(BITMAPINFOHEADER))
1779  {
1780  return NULL;
1781  }
1782 
1783  /* The packed DIB starts with the BITMAPINFOHEADER */
1784  pbmi = pvPackedDIB;
1785 
1786  if (cjPackedDIB < pbmi->bmiHeader.biSize)
1787  {
1788  return NULL;
1789  }
1790 
1791  /* Calculate the info size and make sure the packed DIB is large enough */
1792  cjInfo = DIB_BitmapInfoSize(pbmi, uUsage);
1793  if (cjPackedDIB <= cjInfo)
1794  {
1795  return NULL;
1796  }
1797 
1798  /* The bitmap bits start after the header */
1799  pjBits = (PBYTE)pvPackedDIB + cjInfo;
1800  cjBits = cjPackedDIB - cjInfo;
1801 
1806  pjBits,
1807  pbmi,
1808  uUsage,
1809  0,
1810  cjBits,
1811  NULL);
1812 
1813  return hbm;
1814 }
#define abs(i)
Definition: fconv.c:206
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: dibobj.c:1691
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
INT FASTCALL DIB_BitmapInfoSize(const BITMAPINFO *info, WORD coloruse)
Definition: dibobj.c:2139
#define CBM_INIT
Definition: wingdi.h:365
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define CBM_CREATDIB
static HBITMAP
Definition: button.c:44
BYTE * PBYTE
Definition: pedump.c:66

Referenced by NtGdiCreateDIBBrush().

◆ GreGetDIBitsInternal()

INT APIENTRY GreGetDIBitsInternal ( HDC  hDC,
HBITMAP  hBitmap,
UINT  StartScan,
UINT  ScanLines,
LPBYTE  Bits,
LPBITMAPINFO  Info,
UINT  Usage,
UINT  MaxBits,
UINT  MaxInfo 
)

Definition at line 694 of file dibobj.c.

704 {
705  BITMAPCOREINFO* pbmci = NULL;
706  PSURFACE psurf = NULL;
707  PDC pDC;
708  LONG width, height;
709  WORD planes, bpp;
710  DWORD compr, size ;
711  USHORT i;
712  int bitmap_type;
713  RGBQUAD* rgbQuads;
714  VOID* colorPtr;
715 
716  DPRINT("Entered GreGetDIBitsInternal()\n");
717 
718  if ((Usage && Usage != DIB_PAL_COLORS) || !Info || !hBitmap)
719  return 0;
720 
721  pDC = DC_LockDc(hDC);
722  if (pDC == NULL || pDC->dctype == DCTYPE_INFO)
723  {
724  ScanLines = 0;
725  goto done;
726  }
727 
728  /* Get a pointer to the source bitmap object */
730  if (psurf == NULL)
731  {
732  ScanLines = 0;
733  goto done;
734  }
735 
736  colorPtr = (LPBYTE)Info + Info->bmiHeader.biSize;
737  rgbQuads = colorPtr;
738 
739  bitmap_type = DIB_GetBitmapInfo(&Info->bmiHeader,
740  &width,
741  &height,
742  &planes,
743  &bpp,
744  &compr,
745  &size);
746  if(bitmap_type == -1)
747  {
748  DPRINT1("Wrong bitmap format\n");
750  ScanLines = 0;
751  goto done;
752  }
753  else if(bitmap_type == 0)
754  {
755  /* We need a BITMAPINFO to create a DIB, but we have to fill
756  * the BITMAPCOREINFO we're provided */
757  pbmci = (BITMAPCOREINFO*)Info;
758  /* fill in the the bit count, so we can calculate the right ColorsSize during the conversion */
761  if(Info == NULL)
762  {
763  DPRINT1("Error, could not convert the BITMAPCOREINFO!\n");
764  ScanLines = 0;
765  goto done;
766  }
767  rgbQuads = Info->bmiColors;
768  }
769 
770  /* Validate input:
771  - negative width is always an invalid value
772  - non-null Bits and zero bpp is an invalid combination
773  - only check the rest of the input params if either bpp is non-zero or Bits are set */
774  if (width < 0 || (bpp == 0 && Bits))
775  {
776  ScanLines = 0;
777  goto done;
778  }
779 
780  if (Bits || bpp)
781  {
782  if ((height == 0 || width == 0) || (compr && compr != BI_BITFIELDS && compr != BI_RGB))
783  {
784  ScanLines = 0;
785  goto done;
786  }
787  }
788 
789  Info->bmiHeader.biClrUsed = 0;
790  Info->bmiHeader.biClrImportant = 0;
791 
792  /* Fill in the structure */
793  switch(bpp)
794  {
795  case 0: /* Only info */
796  Info->bmiHeader.biWidth = psurf->SurfObj.sizlBitmap.cx;
797  Info->bmiHeader.biHeight = (psurf->SurfObj.fjBitmap & BMF_TOPDOWN) ?
798  -psurf->SurfObj.sizlBitmap.cy :
799  psurf->SurfObj.sizlBitmap.cy;
800  Info->bmiHeader.biPlanes = 1;
801  Info->bmiHeader.biBitCount = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
802  Info->bmiHeader.biSizeImage = DIB_GetDIBImageBytes( Info->bmiHeader.biWidth,
803  Info->bmiHeader.biHeight,
804  Info->bmiHeader.biBitCount);
805  Info->bmiHeader.biCompression = (Info->bmiHeader.biBitCount == 16 || Info->bmiHeader.biBitCount == 32) ?
807  Info->bmiHeader.biXPelsPerMeter = 0;
808  Info->bmiHeader.biYPelsPerMeter = 0;
809 
810  if (Info->bmiHeader.biBitCount <= 8 && Info->bmiHeader.biClrUsed == 0)
811  Info->bmiHeader.biClrUsed = 1 << Info->bmiHeader.biBitCount;
812 
813  ScanLines = 1;
814  goto done;
815 
816  case 1:
817  case 4:
818  case 8:
819  Info->bmiHeader.biClrUsed = 1 << bpp;
820 
821  /* If the bitmap is a DIB section and has the same format as what
822  * is requested, go ahead! */
823  if((psurf->hSecure) &&
824  (BitsPerFormat(psurf->SurfObj.iBitmapFormat) == bpp))
825  {
826  if(Usage == DIB_RGB_COLORS)
827  {
828  ULONG colors = min(psurf->ppal->NumColors, 256);
829  if(colors != 256) Info->bmiHeader.biClrUsed = colors;
830  for(i = 0; i < colors; i++)
831  {
832  rgbQuads[i].rgbRed = psurf->ppal->IndexedColors[i].peRed;
833  rgbQuads[i].rgbGreen = psurf->ppal->IndexedColors[i].peGreen;
834  rgbQuads[i].rgbBlue = psurf->ppal->IndexedColors[i].peBlue;
835  rgbQuads[i].rgbReserved = 0;
836  }
837  }
838  else
839  {
840  for(i = 0; i < 256; i++)
841  ((WORD*)rgbQuads)[i] = i;
842  }
843  }
844  else
845  {
846  if(Usage == DIB_PAL_COLORS)
847  {
848  for(i = 0; i < 256; i++)
849  {
850  ((WORD*)rgbQuads)[i] = i;
851  }
852  }
853  else if(bpp > 1 && bpp == BitsPerFormat(psurf->SurfObj.iBitmapFormat))
854  {
855  /* For color DDBs in native depth (mono DDBs always have
856  a black/white palette):
857  Generate the color map from the selected palette */
858  PPALETTE pDcPal = PALETTE_ShareLockPalette(pDC->dclevel.hpal);
859  if(!pDcPal)
860  {
861  ScanLines = 0 ;
862  goto done ;
863  }
864  for (i = 0; i < pDcPal->NumColors; i++)
865  {
866  rgbQuads[i].rgbRed = pDcPal->IndexedColors[i].peRed;
867  rgbQuads[i].rgbGreen = pDcPal->IndexedColors[i].peGreen;
868  rgbQuads[i].rgbBlue = pDcPal->IndexedColors[i].peBlue;
869  rgbQuads[i].rgbReserved = 0;
870  }
872  }
873  else
874  {
875  switch (bpp)
876  {
877  case 1:
878  rgbQuads[0].rgbRed = rgbQuads[0].rgbGreen = rgbQuads[0].rgbBlue = 0;
879  rgbQuads[0].rgbReserved = 0;
880  rgbQuads[1].rgbRed = rgbQuads[1].rgbGreen = rgbQuads[1].rgbBlue = 0xff;
881  rgbQuads[1].rgbReserved = 0;
882  break;
883 
884  case 4:
885  /* The EGA palette is the first and last 8 colours of the default palette
886  with the innermost pair swapped */
887  RtlCopyMemory(rgbQuads, DefLogPaletteQuads, 7 * sizeof(RGBQUAD));
888  RtlCopyMemory(rgbQuads + 7, DefLogPaletteQuads + 12, 1 * sizeof(RGBQUAD));
889  RtlCopyMemory(rgbQuads + 8, DefLogPaletteQuads + 7, 1 * sizeof(RGBQUAD));
890  RtlCopyMemory(rgbQuads + 9, DefLogPaletteQuads + 13, 7 * sizeof(RGBQUAD));
891  break;
892 
893  case 8:
894  {
895  INT i;
896 
897  memcpy(rgbQuads, DefLogPaletteQuads, 10 * sizeof(RGBQUAD));
898  memcpy(rgbQuads + 246, DefLogPaletteQuads + 10, 10 * sizeof(RGBQUAD));
899 
900  for (i = 10; i < 246; i++)
901  {
902  rgbQuads[i].rgbRed = (i & 0x07) << 5;
903  rgbQuads[i].rgbGreen = (i & 0x38) << 2;
904  rgbQuads[i].rgbBlue = i & 0xc0;
905  rgbQuads[i].rgbReserved = 0;
906  }
907  }
908  }
909  }
910  }
911  break;
912 
913  case 15:
914  if (Info->bmiHeader.biCompression == BI_BITFIELDS)
915  {
916  ((PDWORD)Info->bmiColors)[0] = 0x7c00;
917  ((PDWORD)Info->bmiColors)[1] = 0x03e0;
918  ((PDWORD)Info->bmiColors)[2] = 0x001f;
919  }
920  break;
921 
922  case 16:
923  if (Info->bmiHeader.biCompression == BI_BITFIELDS)
924  {
925  if (psurf->hSecure)
926  {
927  ((PDWORD)Info->bmiColors)[0] = psurf->ppal->RedMask;
928  ((PDWORD)Info->bmiColors)[1] = psurf->ppal->GreenMask;
929  ((PDWORD)Info->bmiColors)[2] = psurf->ppal->BlueMask;
930  }
931  else
932  {
933  ((PDWORD)Info->bmiColors)[0] = 0xf800;
934  ((PDWORD)Info->bmiColors)[1] = 0x07e0;
935  ((PDWORD)Info->bmiColors)[2] = 0x001f;
936  }
937  }
938  break;
939 
940  case 24:
941  case 32:
942  if (Info->bmiHeader.biCompression == BI_BITFIELDS)
943  {
944  if (psurf->hSecure)
945  {
946  ((PDWORD)Info->bmiColors)[0] = psurf->ppal->RedMask;
947  ((PDWORD)Info->bmiColors)[1] = psurf->ppal->GreenMask;
948  ((PDWORD)Info->bmiColors)[2] = psurf->ppal->BlueMask;
949  }
950  else
951  {
952  ((PDWORD)Info->bmiColors)[0] = 0xff0000;
953  ((PDWORD)Info->bmiColors)[1] = 0x00ff00;
954  ((PDWORD)Info->bmiColors)[2] = 0x0000ff;
955  }
956  }
957  break;
958 
959  default:
960  ScanLines = 0;
961  goto done;
962  }
963 
964  Info->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(width, height, bpp);
965  Info->bmiHeader.biPlanes = 1;
966 
967  if(Bits && ScanLines)
968  {
969  /* Create a DIBSECTION, blt it, profit */
970  PVOID pDIBits ;
971  HBITMAP hBmpDest;
972  PSURFACE psurfDest;
973  EXLATEOBJ exlo;
974  RECT rcDest;
975  POINTL srcPoint;
976  BOOL ret ;
977  int newLines = -1;
978 
979  if (StartScan >= abs(Info->bmiHeader.biHeight))
980  {
981  ScanLines = 1;
982  goto done;
983  }
984  else
985  {
986  ScanLines = min(ScanLines, abs(Info->bmiHeader.biHeight) - StartScan);
987  }
988 
989  if (abs(Info->bmiHeader.biHeight) < psurf->SurfObj.sizlBitmap.cy)
990  {
991  StartScan += psurf->SurfObj.sizlBitmap.cy - abs(Info->bmiHeader.biHeight);
992  }
993  /* Fixup values */
994  Info->bmiHeader.biHeight = (height < 0) ?
995  -(LONG)ScanLines : ScanLines;
996  /* Create the DIB */
997  hBmpDest = DIB_CreateDIBSection(pDC, Info, Usage, &pDIBits, NULL, 0, 0);
998  /* Restore them */
999  Info->bmiHeader.biHeight = height;
1000 
1001  if(!hBmpDest)
1002  {
1003  DPRINT1("Unable to create a DIB Section!\n");
1005  ScanLines = 0;
1006  goto done ;
1007  }
1008 
1009  psurfDest = SURFACE_ShareLockSurface(hBmpDest);
1010 
1011  RECTL_vSetRect(&rcDest, 0, 0, Info->bmiHeader.biWidth, ScanLines);
1012  Info->bmiHeader.biWidth = width;
1013  srcPoint.x = 0;
1014 
1015  if (abs(Info->bmiHeader.biHeight) <= psurf->SurfObj.sizlBitmap.cy)
1016  {
1017  srcPoint.y = psurf->SurfObj.sizlBitmap.cy - StartScan - ScanLines;
1018  }
1019  else
1020  {
1021  /* Determine the actual number of lines copied from the */
1022  /* original bitmap. It might be different from ScanLines. */
1023  newLines = abs(Info->bmiHeader.biHeight) - psurf->SurfObj.sizlBitmap.cy;
1024  newLines = min((int)(StartScan + ScanLines - newLines), psurf->SurfObj.sizlBitmap.cy);
1025  if (newLines > 0)
1026  {
1027  srcPoint.y = psurf->SurfObj.sizlBitmap.cy - newLines;
1028  if (StartScan > psurf->SurfObj.sizlBitmap.cy)
1029  {
1030  newLines -= (StartScan - psurf->SurfObj.sizlBitmap.cy);
1031  }
1032  }
1033  else
1034  {
1035  newLines = 0;
1036  srcPoint.y = psurf->SurfObj.sizlBitmap.cy;
1037  }
1038  }
1039 
1040  EXLATEOBJ_vInitialize(&exlo, psurf->ppal, psurfDest->ppal, 0xffffff, 0xffffff, 0);
1041 
1042  ret = IntEngCopyBits(&psurfDest->SurfObj,
1043  &psurf->SurfObj,
1044  NULL,
1045  &exlo.xlo,
1046  &rcDest,
1047  &srcPoint);
1048 
1049  SURFACE_ShareUnlockSurface(psurfDest);
1050 
1051  if(!ret)
1052  ScanLines = 0;
1053  else
1054  {
1055  RtlCopyMemory(Bits, pDIBits, DIB_GetDIBImageBytes (width, ScanLines, bpp));
1056  }
1057  /* Update if line count has changed */
1058  if (newLines != -1)
1059  {
1060  ScanLines = (UINT)newLines;
1061  }
1062  GreDeleteObject(hBmpDest);
1063  EXLATEOBJ_vCleanup(&exlo);
1064  }
1065  else
1066  {
1067  /* Signals success and not the actual number of scan lines*/
1068  ScanLines = 1;
1069  }
1070 
1071 done:
1072 
1073  if (pbmci)
1075 
1076  if (psurf)
1078 
1079  if (pDC)
1080  DC_UnlockDc(pDC);
1081 
1082  return ScanLines;
1083 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define abs(i)
Definition: fconv.c:206
GLint GLint GLsizei width
Definition: gl.h:1546
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1158
SIZEL sizlBitmap
Definition: winddi.h:1209
FORCEINLINE PDC DC_LockDc(HDC hdc)
Definition: dc.h:217
#define SURFACE_ShareUnlockSurface(pBMObj)
Definition: surface.h:102
#define DIB_PAL_COLORS
Definition: wingdi.h:366
HBITMAP APIENTRY DIB_CreateDIBSection(PDC dc, CONST BITMAPINFO *bmi, UINT usage, LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch)
Definition: dibobj.c:1885
#define BitsPerFormat(Format)
Definition: surface.h:109
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:382
static const RGBQUAD DefLogPaletteQuads[20]
Definition: dibobj.c:14
PALETTEENTRY * IndexedColors
Definition: palette.h:42
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
int32_t INT
Definition: typedefs.h:58
#define BI_BITFIELDS
Definition: mmreg.h:507
LONG y
Definition: windef.h:330
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
BITMAPCOREHEADER bmciHeader
Definition: wingdi.h:1453
XLATEOBJ xlo
Definition: xlateobj.h:21
BITMAPINFO *FASTCALL DIB_ConvertBitmapInfo(CONST BITMAPINFO *pbmi, DWORD Usage)
Definition: dibobj.c:2212
VOID NTAPI EXLATEOBJ_vInitialize(_Out_ PEXLATEOBJ pexlo, _In_opt_ PALETTE *ppalSrc, _In_opt_ PALETTE *ppalDst, _In_ COLORREF crSrcBackColor, _In_ COLORREF crDstBackColor, _In_ COLORREF crDstForeColor)
Definition: xlateobj.c:358
unsigned char * LPBYTE
Definition: typedefs.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
int FASTCALL DIB_GetBitmapInfo(const BITMAPINFOHEADER *header, LONG *width, LONG *height, WORD *planes, WORD *bpp, DWORD *compr, DWORD *size)
Definition: dibobj.c:2092
SURFOBJ SurfObj
Definition: surface.h:8
static int __cdecl compr(const void *a, const void *b)
Definition: bidi.c:641
LONG cx
Definition: windef.h:334
BOOL APIENTRY IntEngCopyBits(SURFOBJ *psoTrg, SURFOBJ *psoSrc, CLIPOBJ *pco, XLATEOBJ *pxlo, RECTL *prclTrg, POINTL *pptlSrc)
Definition: bitblt_new.c:678
VOID NTAPI EXLATEOBJ_vCleanup(_Inout_ PEXLATEOBJ pexlo)
Definition: xlateobj.c:649
#define PALETTE_ShareLockPalette(hpal)
Definition: palette.h:57
Definition: polytest.cpp:40
GLsizeiptr size
Definition: glext.h:5919
ULONG RGBQUAD
Definition: precomp.h:50
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG x
Definition: windef.h:329
INT APIENTRY DIB_GetDIBImageBytes(INT width, INT height, INT depth)
Definition: dibobj.c:2127
int ret
HANDLE hSecure
Definition: surface.h:32
VOID FASTCALL DIB_FreeConvertedBitmapInfo(BITMAPINFO *converted, BITMAPINFO *orig, DWORD usage)
Definition: dibobj.c:2276
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: dc.h:43
ULONG NumColors
Definition: palette.h:41
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
USHORT fjBitmap
Definition: winddi.h:1217
static HDC hDC
Definition: 3dtext.c:33
FORCEINLINE VOID RECTL_vSetRect(_Out_ RECTL *prcl, _In_ LONG left, _In_ LONG top, _In_ LONG right, _In_ LONG bottom)
Definition: rect.h:5
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
FORCEINLINE VOID DC_UnlockDc(PDC pdc)
Definition: dc.h:235
unsigned short USHORT
Definition: pedump.c:61
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
DWORD * PDWORD
Definition: pedump.c:68
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
DWORD bpp
Definition: surface.c:185
static HBITMAP
Definition: button.c:44
#define DPRINT
Definition: sndvol32.h:71
#define DIB_RGB_COLORS
Definition: wingdi.h:367
LONG cy
Definition: windef.h:335
#define BI_RGB
Definition: precomp.h:47
static HBITMAP hBitmap
Definition: timezone.c:26
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28

Referenced by _Success_(), and IntSynthesizeDib().