gdiplus: GdipBitmapLockBits should allow a NULL rect argument.

This commit is contained in:
Nikolay Sivov 2008-05-21 19:47:50 +04:00 committed by Alexandre Julliard
parent 87bb1cbcdc
commit 36a7f31752
2 changed files with 31 additions and 10 deletions

View File

@ -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,
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;

View File

@ -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)
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);