Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Table issues (transparency & background) #425

Open
mischnic opened this issue Sep 28, 2018 · 9 comments
Open

Image Table issues (transparency & background) #425

mischnic opened this issue Sep 28, 2018 · 9 comments
Milestone

Comments

@mischnic
Copy link
Contributor

mischnic commented Sep 28, 2018

On macOS (not Windows): On the right is the (png) image as it should be displayed, but in the table there are these green bits.
bildschirmfoto 2018-09-28 um 19 21 03

The code below has this output: Firstly, the green as described above, but secondly the alternating row background doesn't seem to work correctly.
bildschirmfoto 2018-09-28 um 20 03 04

Code: https://github.com/mischnic/libui-tests/tree/master/png

@msink
Copy link
Contributor

msink commented Sep 30, 2018

Pixel format is 32bit ARGB
https://github.com/msink/png2kt

@mischnic
Copy link
Contributor Author

The decoder returns 32bit RGBA, with the libui output above (the colors do look correct, just something about the transparency).
Reordering the components using this code (which is basically what your tool does?) yields

for(unsigned int i = 0; i < width*height*4; i+=4){
	const unsigned char alpha = image[i+3];
	image[i+3] = image[i+2];
	image[i+2] = image[i+1];
	image[i+1] = image[i];
	image[i] = alpha;
}

bildschirmfoto 2018-09-30 um 12 43 47

Setting the alpha component to 255 and passing RGBA to libui:
bildschirmfoto 2018-09-30 um 12 45 08

@msink
Copy link
Contributor

msink commented Sep 30, 2018

Strange, it worked for me 3 months ago.
Will check tomorrow, now far from computer, sorry.

@mischnic
Copy link
Contributor Author

mischnic commented Sep 30, 2018

Passing RGBA to libui works fine on Windows (no green artifacts)
@msink It is RGBA:

libui/ui.h

Lines 1165 to 1166 in 30d4129

// stored in [R G B A] order (so ((uint8_t *) pixels)[0] is the R of the
// first pixel and [3] is the A of the first pixel). pixelWidth and

So the green is a macOS bug indeed.

@msink
Copy link
Contributor

msink commented Oct 1, 2018

So something was broken in macOS version between alpha4 and alpha4.1.

@msink
Copy link
Contributor

msink commented Oct 1, 2018

Does it work in https://github.com/msink/kotlin-libui/releases/download/alpha-4.1-1/libui-samples-kotlin-macos.tgz ?
I do not have mac, so cannot check.

On Windows: image

@mischnic
Copy link
Contributor Author

mischnic commented Oct 1, 2018

No, same problem:

bildschirmfoto 2018-10-01 um 21 07 38

@mischnic
Copy link
Contributor Author

mischnic commented Oct 1, 2018

Another example (not tested on Windows):

Icon: (outline is not part of the icon)
bildschirmfoto 2018-10-01 um 21 58 06

Displayed in the table on macOS (black smoke around):
bildschirmfoto 2018-10-01 um 21 58 10

There are no artifacts after replacing all transparency with white.

@mischnic
Copy link
Contributor Author

mischnic commented Oct 2, 2018

Huh, with this change:

diff --git a/darwin/image.m b/darwin/image.m
index 0b10cb09..75ed6347 100644
--- a/darwin/image.m
+++ b/darwin/image.m
@@ -37,7 +37,7 @@ void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, in
                hasAlpha:YES
                isPlanar:NO
                colorSpaceName:NSCalibratedRGBColorSpace
-               bitmapFormat:0
+               bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
                bytesPerRow:0
                bitsPerPixel:32];

The image is displayed correctly. But I thought libui used premultiplied image data now? This tells Cocoa, that the values aren't premuliplied. 🤔

@andlabs On this page, there are also some options regarding endianness, have you seen these? https://developer.apple.com/documentation/appkit/nsbitmapformat?language=objc

mischnic referenced this issue in parro-it/libui-napi Dec 10, 2018
@andlabs andlabs added this to the Alpha 5 milestone Dec 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants