Commit 36a7f317 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

gdiplus: GdipBitmapLockBits should allow a NULL rect argument.

parent 87bb1cbc
...@@ -101,15 +101,25 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, ...@@ -101,15 +101,25 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
BITMAPINFO bmi; BITMAPINFO bmi;
BYTE *buff = NULL; BYTE *buff = NULL;
UINT abs_height; UINT abs_height;
GpRect act_rect; /* actual rect to be used */
TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata); TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
if(!lockeddata || !bitmap || !rect) if(!lockeddata || !bitmap)
return InvalidParameter; return InvalidParameter;
if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) || if(rect){
(rect->Y + rect->Height > bitmap->height) || !flags) if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
return InvalidParameter; (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) if(flags & ImageLockModeUserInputBuf)
return NotImplemented; return NotImplemented;
...@@ -151,19 +161,19 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, ...@@ -151,19 +161,19 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
if(!buff) if(!buff)
return OutOfMemory; return OutOfMemory;
lockeddata->Width = rect->Width; lockeddata->Width = act_rect.Width;
lockeddata->Height = rect->Height; lockeddata->Height = act_rect.Height;
lockeddata->PixelFormat = format; lockeddata->PixelFormat = format;
lockeddata->Reserved = flags; lockeddata->Reserved = flags;
if(bmi.bmiHeader.biHeight > 0){ if(bmi.bmiHeader.biHeight > 0){
lockeddata->Stride = -stride; lockeddata->Stride = -stride;
lockeddata->Scan0 = buff + (bitspp / 8) * rect->X + lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
stride * (abs_height - 1 - rect->Y); stride * (abs_height - 1 - act_rect.Y);
} }
else{ else{
lockeddata->Stride = stride; 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; bitmap->lockmode = flags;
......
...@@ -247,7 +247,7 @@ static void test_LockBits(void) ...@@ -247,7 +247,7 @@ static void test_LockBits(void)
GpBitmap *bm; GpBitmap *bm;
GpRect rect; GpRect rect;
BitmapData bd; BitmapData bd;
const REAL WIDTH = 10.0, HEIGHT = 20.0; const INT WIDTH = 10, HEIGHT = 20;
bm = NULL; bm = NULL;
stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm); stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
...@@ -267,6 +267,17 @@ static void test_LockBits(void) ...@@ -267,6 +267,17 @@ static void test_LockBits(void)
expect(Ok, stat); 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 */ /* read-only, consecutive */
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd); stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
expect(Ok, stat); expect(Ok, stat);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment