Vincent Povirk madewokherd@gmail.com writes:
@@ -2264,6 +2266,41 @@ GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **gra if(graphics == NULL) return InvalidParameter;
- hbm = GetCurrentObject(hdc, OBJ_BITMAP);
- if (hbm && GetObjectW(hbm, sizeof(dib), &dib) && dib.dsBm.bmBitsPixel == 32)
- {
/* Make a bitmap object so we can use the alpha channel */
GpBitmap *bitmap;
DWORD height, stride;
BYTE *bits;
height = abs(dib.dsBmih.biHeight);
stride = dib.dsBmih.biWidth * 4;
if(dib.dsBmih.biHeight > 0) /* bottom-up */
{
bits = (BYTE*)dib.dsBm.bmBits + (height - 1) * stride;
stride = -dib.dsBmih.biWidth * 4;
}
else
bits = dib.dsBm.bmBits;
retval = GdipCreateBitmapFromScan0(dib.dsBmih.biWidth, height, stride,
PixelFormat32bppPARGB, bits, &bitmap);
This won't work, you won't get a negative height with GetObject, and you won't get DIB info at all for DDBs. Also not all DIBs are in PARGB format.
you won't get a negative height with GetObject,
Hmm, is GdipCreateBitmapFromHBITMAP doing it right, then? It assumes all DIB objects have positive stride.
you won't get DIB info at all for DDBs.
I don't think it makes sense to do this for DDBs, as I can't draw them directly and don't expect them to have alpha information.
Also not all DIBs are in PARGB format.
I'll test whether native cares.
It assumes all DIB objects have positive stride.
Sorry, I misread, that's assuming a negative stride.
Vincent Povirk madewokherd@gmail.com writes:
you won't get a negative height with GetObject,
Hmm, is GdipCreateBitmapFromHBITMAP doing it right, then? It assumes all DIB objects have positive stride.
No, that's wrong. It should most likely just do a GetDIBits (in one go, not line by line like it currently does).
you won't get DIB info at all for DDBs.
I don't think it makes sense to do this for DDBs, as I can't draw them directly and don't expect them to have alpha information.
Sure, but it shouldn't crash and burn.
you won't get a negative height with GetObject,
Hmm, is GdipCreateBitmapFromHBITMAP doing it right, then? It assumes all DIB objects have positive stride.
No, that's wrong. It should most likely just do a GetDIBits (in one go, not line by line like it currently does).
Does that mean there's no way to access the bits directly given a DIB object?
I think we do it line by line so that we don't rely on GdipCreateBitmapFromScan0 to create the bitmap with a particular stride. I guess we could specify a stride when calling that.
you won't get DIB info at all for DDBs.
I don't think it makes sense to do this for DDBs, as I can't draw them directly and don't expect them to have alpha information.
Sure, but it shouldn't crash and burn.
I don't understand why it would. I'd expect the GetObject to fail given sizeof(DIBSECTION) if the object is a DDB.
Vincent Povirk madewokherd@gmail.com writes:
Does that mean there's no way to access the bits directly given a DIB object?
If you don't know how it was created, then no.
I think we do it line by line so that we don't rely on GdipCreateBitmapFromScan0 to create the bitmap with a particular stride. I guess we could specify a stride when calling that.
It seems to me the default is already a DIB stride.
Sure, but it shouldn't crash and burn.
I don't understand why it would. I'd expect the GetObject to fail given sizeof(DIBSECTION) if the object is a DDB.
No, that's not how it works, size is an upper bound.