Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

[MBS] PictureMBS and Premultiplied alpha? (MBS Xojo Plugin Mailinglist archive)

Back to the thread list
Previous thread: [MBS] [ANN] 16.0pr7
Next thread: [MBS] [ANN] Free tickets for young developers for MBS Xojo Conference 2016 in Koblenz, Germany


[MBS] MBS 7.5 with RB2010r4.1   -   Garth Hjelte
  [MBS] PictureMBS and Premultiplied alpha?   -   Michael Diehr
   Re: [MBS] PictureMBS and Premultiplied alpha?   -   Michael Diehr
   Re: [MBS] PictureMBS and Premultiplied alpha?   -   Christian Schmitz

[MBS] PictureMBS and Premultiplied alpha?
Date: 19.01.16 21:48 (Tue, 19 Jan 2016 12:48:24 -0800)
From: Michael Diehr
Hi Christian,

It appears that

PictureMBS.RowInFormat(y,ImageFormatRGBA)

is returning premultiplied RGBA data, even on Win32 which doesn't use Premultiplied alpha.

Here's a little test:

#if TargetWin32
app.UseGDIPlus = true
#endif

dim p as new picture(128,128) // new-style 32 bit xojo picture

dim c as color = &cFF000080 // Red = 255, Green = 0, Blue = 0, Alpha = 128

p.Graphics.ForeColor = c
p.Graphics.FillRect 0,0,p.width,p.height

dim rgba as color = p.RGBSurface.Pixel(0,0)
MsgBox "Pixel RGBA = " + str(rgba.Red) + " " + str(rgba.Green) + " " + str(rgba.blue) + " " + str(rgba.Alpha)

// now make a pictureMBS and get the data

dim pm as new PictureMBS(p, p.HasAlphaChannel)

dim mb as MemoryBlock = pm.RowInFormat(0,PictureMBS.ImageFormatRGBA)

MsgBox "Data RGBA = " + str(mb.byte(0)) + " " + str(mb.byte(1)) + " " + str(mb.byte(2)) + " " + str(mb.byte(3))

On both Mac and Windows, I get

Pixel RGBA = 255, 0, 0, 127
Data RGBA = 127, 0, 0, 127

I would expect to get

Data RGBA = 255, 0, 0, 127

on both platforms, although I suppose you could argue that on Mac perhaps the premultiplied values are "right".

Is there any way I can work around this and get the raw RGBA data, not premultiplied?

_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
<email address removed>
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Re: [MBS] PictureMBS and Premultiplied alpha?
Date: 20.01.16 01:56 (Tue, 19 Jan 2016 16:56:22 -0800)
From: Michael Diehr
On Jan 19, 2016, at 2:06 PM, Christian Schmitz <<email address removed>> wrote:
>
>> Am 19.01.2016 um 21:48 schrieb Michael Diehr <<email address removed>>:
>>
>> Hi Christian,
>>
>> It appears that
>>
>> PictureMBS.RowInFormat(y,ImageFormatRGBA)
>>
>> is returning premultiplied RGBA data, even on Win32 which doesn't use Premultiplied alpha.
>
> The plugin returns whatever pixel values are there.
>
> So we don't premultiply for you and we don't reverse it.

Interesting : I wonder then if Xojo documentation is wrong, and that they are storing pictures premultiplied on Win32, and then RGBSurface.Pixel() must be un-premultiplying it when invoked?

_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
<email address removed>
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info

Re: [MBS] PictureMBS and Premultiplied alpha?
Date: 19.01.16 23:06 (Tue, 19 Jan 2016 23:06:08 +0100)
From: Christian Schmitz

> Am 19.01.2016 um 21:48 schrieb Michael Diehr <<email address removed>>:
>
> Hi Christian,
>
> It appears that
>
> PictureMBS.RowInFormat(y,ImageFormatRGBA)
>
> is returning premultiplied RGBA data, even on Win32 which doesn't use Premultiplied alpha.

The plugin returns whatever pixel values are there.

So we don't premultiply for you and we don't reverse it.

Sincerely
Christian