Added DIB_CreateDIBSection with extra parameter ovr_pitch, added
ovr_pitch to pCreateDIBSection in DC_FUNCS. If ovr_pitch is nonzero,
it is a pitch override (specifies bytes per line), and tells to treat
the offset parameter as an already-mapped virtual memory address (if
the section parameter is zero). Fixed a DIB status init bug in
creating DIB sections from file mappings (if created from mapping, the
DIB is *not* really InSync).
diff --git a/graphics/x11drv/dib.c b/graphics/x11drv/dib.c
index 8017267..0761d81 100644
--- a/graphics/x11drv/dib.c
+++ b/graphics/x11drv/dib.c
@@ -3167,10 +3167,10 @@
HBITMAP16 X11DRV_DIB_CreateDIBSection16(
DC *dc, BITMAPINFO *bmi, UINT16 usage,
SEGPTR *bits, HANDLE section,
- DWORD offset)
+ DWORD offset, DWORD ovr_pitch)
{
HBITMAP res = X11DRV_DIB_CreateDIBSection(dc, bmi, usage, NULL,
- section, offset);
+ section, offset, ovr_pitch);
if ( res )
{
BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr(res, BITMAP_MAGIC);
@@ -3272,7 +3272,7 @@
HBITMAP X11DRV_DIB_CreateDIBSection(
DC *dc, BITMAPINFO *bmi, UINT usage,
LPVOID *bits, HANDLE section,
- DWORD offset)
+ DWORD offset, DWORD ovr_pitch)
{
HBITMAP res = 0;
BITMAPOBJ *bmp = NULL;
@@ -3293,7 +3293,8 @@
bm.bmType = 0;
bm.bmWidth = bi->biWidth;
bm.bmHeight = effHeight;
- bm.bmWidthBytes = DIB_GetDIBWidthBytes(bm.bmWidth, bi->biBitCount);
+ bm.bmWidthBytes = ovr_pitch ? ovr_pitch
+ : DIB_GetDIBWidthBytes(bm.bmWidth, bi->biBitCount);
bm.bmPlanes = bi->biPlanes;
bm.bmBitsPixel = bi->biBitCount;
bm.bmBits = NULL;
@@ -3304,9 +3305,13 @@
if (section)
bm.bmBits = MapViewOfFile(section, FILE_MAP_ALL_ACCESS,
0L, offset, totalSize);
- else
+ else if (ovr_pitch && offset)
+ bm.bmBits = offset;
+ else {
+ offset = 0;
bm.bmBits = VirtualAlloc(NULL, totalSize,
MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
+ }
/* Create Color Map */
if (bm.bmBits && bm.bmBitsPixel <= 8)
@@ -3396,7 +3401,7 @@
{
if (section)
UnmapViewOfFile(bm.bmBits), bm.bmBits = NULL;
- else
+ else if (!offset)
VirtualFree(bm.bmBits, 0L, MEM_RELEASE), bm.bmBits = NULL;
}
@@ -3411,8 +3416,16 @@
{
if (VIRTUAL_SetFaultHandler(bm.bmBits, X11DRV_DIB_FaultHandler, (LPVOID)res))
{
- X11DRV_DIB_DoProtectDIBSection( bmp, PAGE_READONLY );
- if (dib) dib->status = X11DRV_DIB_InSync;
+ if (section || offset)
+ {
+ X11DRV_DIB_DoProtectDIBSection( bmp, PAGE_READWRITE );
+ if (dib) dib->status = X11DRV_DIB_AppMod;
+ }
+ else
+ {
+ X11DRV_DIB_DoProtectDIBSection( bmp, PAGE_READONLY );
+ if (dib) dib->status = X11DRV_DIB_InSync;
+ }
}
}
diff --git a/include/bitmap.h b/include/bitmap.h
index 4d171fb..d8ed08b 100644
--- a/include/bitmap.h
+++ b/include/bitmap.h
@@ -52,6 +52,8 @@
extern int DIB_BitmapInfoSize( const BITMAPINFO * info, WORD coloruse );
extern int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, DWORD *width,
int *height, WORD *bpp, WORD *compr );
+extern HBITMAP DIB_CreateDIBSection( HDC hdc, BITMAPINFO *bmi, UINT usage, LPVOID *bits,
+ HANDLE section, DWORD offset, DWORD ovr_pitch );
extern void DIB_UpdateDIBSection( DC *dc, BOOL toDIB );
extern void DIB_DeleteDIBSection( BITMAPOBJ *bmp );
extern void DIB_SelectDIBSection( DC *dc, BITMAPOBJ *bmp );
diff --git a/include/gdi.h b/include/gdi.h
index 6a9ce2b..f21213f 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -181,9 +181,9 @@
BOOL (*pCreateBitmap)(HBITMAP);
BOOL (*pCreateDC)(DC*,LPCSTR,LPCSTR,LPCSTR,const DEVMODEA*);
HBITMAP (*pCreateDIBSection)(DC *,BITMAPINFO *,UINT,LPVOID *,HANDLE,
- DWORD);
+ DWORD,DWORD);
HBITMAP16 (*pCreateDIBSection16)(DC *,BITMAPINFO *,UINT16,SEGPTR *,HANDLE,
- DWORD);
+ DWORD,DWORD);
BOOL (*pDeleteDC)(DC*);
BOOL (*pDeleteObject)(HGDIOBJ);
DWORD (*pDeviceCapabilities)(LPSTR,LPCSTR,LPCSTR,WORD,LPSTR,LPDEVMODEA);
diff --git a/include/x11drv.h b/include/x11drv.h
index 26e48a6..3a2bd49 100644
--- a/include/x11drv.h
+++ b/include/x11drv.h
@@ -254,9 +254,9 @@
extern void X11DRV_DIB_UpdateDIBSection(struct tagDC *dc, BOOL toDIB);
extern HBITMAP X11DRV_DIB_CreateDIBSection(struct tagDC *dc, BITMAPINFO *bmi, UINT usage,
- LPVOID *bits, HANDLE section, DWORD offset);
+ LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
extern HBITMAP16 X11DRV_DIB_CreateDIBSection16(struct tagDC *dc, BITMAPINFO *bmi, UINT16 usage,
- SEGPTR *bits, HANDLE section, DWORD offset);
+ SEGPTR *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
extern struct tagBITMAP_DRIVER X11DRV_BITMAP_Driver;
diff --git a/objects/dib.c b/objects/dib.c
index b346629..0640bb9 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -870,7 +870,26 @@
if(!dc) dc = (DC *) GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
if(!dc) return (HBITMAP16) NULL;
- hbitmap = dc->funcs->pCreateDIBSection16(dc, bmi, usage, bits, section, offset);
+ hbitmap = dc->funcs->pCreateDIBSection16(dc, bmi, usage, bits, section, offset, 0);
+
+ GDI_HEAP_UNLOCK(hdc);
+
+ return hbitmap;
+}
+
+/***********************************************************************
+ * DIB_CreateDIBSection
+ */
+HBITMAP DIB_CreateDIBSection(HDC hdc, BITMAPINFO *bmi, UINT usage,
+ LPVOID *bits, HANDLE section,
+ DWORD offset, DWORD ovr_pitch)
+{
+ HBITMAP hbitmap;
+ DC *dc = (DC *) GDI_GetObjPtr(hdc, DC_MAGIC);
+ if(!dc) dc = (DC *) GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
+ if(!dc) return (HBITMAP) NULL;
+
+ hbitmap = dc->funcs->pCreateDIBSection(dc, bmi, usage, bits, section, offset, ovr_pitch);
GDI_HEAP_UNLOCK(hdc);
@@ -884,16 +903,7 @@
LPVOID *bits, HANDLE section,
DWORD offset)
{
- HBITMAP hbitmap;
- DC *dc = (DC *) GDI_GetObjPtr(hdc, DC_MAGIC);
- if(!dc) dc = (DC *) GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
- if(!dc) return (HBITMAP) NULL;
-
- hbitmap = dc->funcs->pCreateDIBSection(dc, bmi, usage, bits, section, offset);
-
- GDI_HEAP_UNLOCK(hdc);
-
- return hbitmap;
+ return DIB_CreateDIBSection(hdc, bmi, usage, bits, section, offset, 0);
}
/***********************************************************************
@@ -909,7 +919,7 @@
{
if (dib->dshSection)
UnmapViewOfFile(dib->dsBm.bmBits);
- else
+ else if (!dib->dsOffset)
VirtualFree(dib->dsBm.bmBits, 0L, MEM_RELEASE );
}