Immutable Bitmap: non premultiplied RGBA data

I’m updating an old project from 2014R2.1 to 2017R3, from 32 to 64 bit, and I find myself needing to access image data where alpha has not been pre-multiplied.

In my old app, I was loading the premultiplied data, then un-multiplying it to get back to the normal RGBA data - unfortunately this is a lossy computation, so the results were never perfect.

This document:
http://developer.xojo.com/hidpi-support
Says:

[quote]The most significant changes are to Picture, which now essentially can contain three different types of “pictures”: Bitmap, Immutable Bitmap, Vector and Image.[…]

  • Immutable Bitmap: A single-representation read-only bitmap. If the bitmap is RGB with 8, 16, 24, or 32 bits per pixel, there will be a read-only RGBSurface that can be used to access raw pixel data that hasn’t gone through color conversion or pre-multiplied alpha (typically).
    [/quote]
    (emphasis mine)

My specific workflow would be something like this:

  • load image file from disk (JPEG, PNG, TIFF…)
  • access raw image bytes that have not been premultiplied
  • do something with the color data
  • save it back to disk
  • display it (with proper colorspace management) onscreen.

Right now I only care about macOS 10.10 and Windows 10 and higher. Can anyone comment on what the word “typically” means above?

My PictureMBS class recently got methods to unmultiply, so maybe you want to use it?

http://www.monkeybreadsoftware.net/class-picturembs.shtml

These days Xojo pictures are only good for displaying graphics on-screen.

If you are doing any type of image processing I suggest you look at the MBS & Einhuger plugins.

The problem with un-multiplying is that it’s too late in the process - alpha multiplication, then division, is lossy.

I am already using MBS classes heavily and will probably continue to do so, but in this discussion I’m trying to focus on what changes have happened inside Xojo.

Sounds like it’s “time for a test app!” :slight_smile:

You can do it end to end where it never gets to multiplied state with GraphicsFormats -> PictureEffectsRaw, using RawBitmap object from TypeLib. (and it will maintain the color profile). Then when your ready to display something on the screen TypeLib can convert it to Xojo Picture object for Display purposes.

I think it will be far fetched to get pure Xojo solution now days for this purpose. Things got complicated with Pre-multiplication, Color profiles and increasing demand for processing also 16 bits per channel images.

I’m basically trying to understand the release notes, or more specifically:

In Xojo 2017R3, under what specific circumstances does one get a Picture object that contains a non-alpha-multiplied Immutable Bitmap.

Anyone know the answer?

Possibly console apps. My understanding is that they are very different under the hood but also come with their own set of issues.

AFAIK it really depends on what format and what mechanism is used to open a picture and then the Xojo wrappers for the OS images.

Most of the macOS API uses pre-multiplied images, as it’s my understanding that the macOS is optimized for premultiplied images. I would argue about how lossy it is if you use the OS APIs as you can use floating points for channel data.