Commit 21d6fc96 authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

gdiplus: Implement ImageLockModeUserInputBuf.

parent 546b1a5c
......@@ -913,9 +913,7 @@ GpStatus convert_pixels(UINT width, UINT height,
GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
UINT flags, PixelFormat format, BitmapData* lockeddata)
{
INT stride, bitspp = PIXELFORMATBPP(format);
BYTE *buff = NULL;
UINT abs_height;
INT bitspp = PIXELFORMATBPP(format);
GpRect act_rect; /* actual rect to be used */
GpStatus stat;
......@@ -937,20 +935,13 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
act_rect.Height = bitmap->height;
}
if(flags & ImageLockModeUserInputBuf)
{
static int fixme=0;
if (!fixme++) FIXME("ImageLockModeUserInputBuf not implemented\n");
return NotImplemented;
}
if(bitmap->lockmode)
{
WARN("bitmap is already locked and cannot be locked again\n");
return WrongState;
}
if (bitmap->bits && bitmap->format == format)
if (bitmap->bits && bitmap->format == format && !(flags & ImageLockModeUserInputBuf))
{
/* no conversion is necessary; just use the bits directly */
lockeddata->Width = act_rect.Width;
......@@ -990,13 +981,21 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
}
}
abs_height = act_rect.Height;
stride = (act_rect.Width * bitspp + 7) / 8;
stride = (stride + 3) & ~3;
lockeddata->Width = act_rect.Width;
lockeddata->Height = act_rect.Height;
lockeddata->PixelFormat = format;
lockeddata->Reserved = flags;
if(!(flags & ImageLockModeUserInputBuf))
{
lockeddata->Stride = (((act_rect.Width * bitspp + 7) / 8) + 3) & ~3;
bitmap->bitmapbits = GdipAlloc(lockeddata->Stride * act_rect.Height);
buff = GdipAlloc(stride * abs_height);
if (!bitmap->bitmapbits) return OutOfMemory;
if (!buff) return OutOfMemory;
lockeddata->Scan0 = bitmap->bitmapbits;
}
if (flags & ImageLockModeRead)
{
......@@ -1009,28 +1008,21 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
}
stat = convert_pixels(act_rect.Width, act_rect.Height,
stride, buff, format,
lockeddata->Stride, lockeddata->Scan0, format,
bitmap->stride,
bitmap->bits + bitmap->stride * act_rect.Y + PIXELFORMATBPP(bitmap->format) * act_rect.X / 8,
bitmap->format, bitmap->image.palette_entries);
if (stat != Ok)
{
GdipFree(buff);
GdipFree(bitmap->bitmapbits);
bitmap->bitmapbits = NULL;
return stat;
}
}
lockeddata->Width = act_rect.Width;
lockeddata->Height = act_rect.Height;
lockeddata->PixelFormat = format;
lockeddata->Reserved = flags;
lockeddata->Stride = stride;
lockeddata->Scan0 = buff;
bitmap->lockmode = flags;
bitmap->numlocks++;
bitmap->bitmapbits = buff;
bitmap->lockx = act_rect.X;
bitmap->locky = act_rect.Y;
......@@ -1064,9 +1056,6 @@ GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
if(!bitmap->lockmode)
return WrongState;
if(lockeddata->Reserved & ImageLockModeUserInputBuf)
return NotImplemented;
if(!(lockeddata->Reserved & ImageLockModeWrite)){
if(!(--bitmap->numlocks))
bitmap->lockmode = 0;
......@@ -1076,7 +1065,7 @@ GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
return Ok;
}
if (!bitmap->bitmapbits)
if (!bitmap->bitmapbits && !(lockeddata->Reserved & ImageLockModeUserInputBuf))
{
/* we passed a direct reference; no need to do anything */
bitmap->lockmode = 0;
......
......@@ -777,10 +777,10 @@ static void test_LockBits_UserBuf(void)
/* read-only */
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
todo_wine expect(Ok, stat);
expect(Ok, stat);
expect(0xaaaaaaaa, bits[0]);
todo_wine expect(0, bits[2+3*WIDTH]);
expect(0, bits[2+3*WIDTH]);
bits[2+3*WIDTH] = 0xdeadbeef;
......@@ -795,7 +795,7 @@ static void test_LockBits_UserBuf(void)
/* write-only */
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
todo_wine expect(Ok, stat);
expect(Ok, stat);
expect(0xdeadbeef, bits[2+3*WIDTH]);
bits[2+3*WIDTH] = 0x12345678;
......@@ -807,15 +807,15 @@ static void test_LockBits_UserBuf(void)
stat = GdipBitmapGetPixel(bm, 2, 3, &color);
expect(Ok, stat);
todo_wine expect(0x12345678, color);
expect(0x12345678, color);
bits[2+3*WIDTH] = 0;
/* read/write */
stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
todo_wine expect(Ok, stat);
expect(Ok, stat);
todo_wine expect(0x12345678, bits[2+3*WIDTH]);
expect(0x12345678, bits[2+3*WIDTH]);
bits[2+3*WIDTH] = 0xdeadbeef;
if (stat == Ok) {
......@@ -825,7 +825,7 @@ static void test_LockBits_UserBuf(void)
stat = GdipBitmapGetPixel(bm, 2, 3, &color);
expect(Ok, stat);
todo_wine expect(0xdeadbeef, color);
expect(0xdeadbeef, color);
stat = GdipDisposeImage((GpImage*)bm);
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