[4/6] gdiplus: native GdipBitmapLockBits allows NULL rect pointer (bug 11893)
Nikolay Sivov
bunglehead at gmail.com
Mon May 19 11:34:39 CDT 2008
Changelog:
- GdipBitmapLockBits allows NULL rect argument
---
dlls/gdiplus/image.c | 28 +++++++++++++++++++---------
dlls/gdiplus/tests/image.c | 13 ++++++++++++-
2 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index 72bf7f5..f6dffcf 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -101,15 +101,25 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
BITMAPINFO bmi;
BYTE *buff = NULL;
UINT abs_height;
+ GpRect act_rect; /* actual rect to be used */
TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
- if(!lockeddata || !bitmap || !rect)
+ if(!lockeddata || !bitmap)
return InvalidParameter;
- if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
- (rect->Y + rect->Height > bitmap->height) || !flags)
- return InvalidParameter;
+ if(rect){
+ if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
+ (rect->Y + rect->Height > bitmap->height) || !flags)
+ return InvalidParameter;
+
+ act_rect = *rect;
+ }
+ else{
+ act_rect.X = act_rect.Y = 0;
+ act_rect.Width = bitmap->width;
+ act_rect.Height = bitmap->height;
+ }
if(flags & ImageLockModeUserInputBuf)
return NotImplemented;
@@ -151,19 +161,19 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
if(!buff)
return OutOfMemory;
- lockeddata->Width = rect->Width;
- lockeddata->Height = rect->Height;
+ lockeddata->Width = act_rect.Width;
+ lockeddata->Height = act_rect.Height;
lockeddata->PixelFormat = format;
lockeddata->Reserved = flags;
if(bmi.bmiHeader.biHeight > 0){
lockeddata->Stride = -stride;
- lockeddata->Scan0 = buff + (bitspp / 8) * rect->X +
- stride * (abs_height - 1 - rect->Y);
+ lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
+ stride * (abs_height - 1 - act_rect.Y);
}
else{
lockeddata->Stride = stride;
- lockeddata->Scan0 = buff + (bitspp / 8) * rect->X + stride * rect->Y;
+ lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
}
bitmap->lockmode = flags;
diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c
index 5142f7c..a3e7676 100644
--- a/dlls/gdiplus/tests/image.c
+++ b/dlls/gdiplus/tests/image.c
@@ -247,7 +247,7 @@ static void test_LockBits(void)
GpBitmap *bm;
GpRect rect;
BitmapData bd;
- const REAL WIDTH = 10.0, HEIGHT = 20.0;
+ const INT WIDTH = 10, HEIGHT = 20;
bm = NULL;
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
@@ -267,6 +267,17 @@ static void test_LockBits(void)
expect(Ok, stat);
}
+ /* read-only, with NULL rect -> whole bitmap lock */
+ stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
+ expect(Ok, stat);
+ expect(bd.Width, WIDTH);
+ expect(bd.Height, HEIGHT);
+
+ if (stat == Ok) {
+ stat = GdipBitmapUnlockBits(bm, &bd);
+ expect(Ok, stat);
+ }
+
/* read-only, consecutive */
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
expect(Ok, stat);
--
1.4.4.4
More information about the wine-patches
mailing list