Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iOS images: back to rendering to a cg context with unmultiplying.
The method I was using to extract the pixel data doesn't always return RGBA and you cannot force Core Graphics to return RGBA (I tried CGImageCreateCopyWithColorSpace but it only works when the components per pixel match). This is particularly problematic with PNG8 where the image data is a palette, Core Graphics will return 8 bits per pixel in this case. We let Core Graphics do the conversion by letting it render to a context and then grab the buffer as we did before. This only works with pre-multiplied alpha (the context cannot store un-multiplied, tried that too, fails on creation). So I've also re-introduced the un-multiply logic but I hand rolled it as the SIMD was failing. Current: ``` // CG only supports premultiplied alpha. Unmultiply now. size_t imageSizeInBytes = image.height * image.width * 4; for (size_t i = 0; i < imageSizeInBytes; i += 4) { auto alpha = image.pixels[i + 3]; if (alpha != 0.0f) { auto alphaFactor = 255.0f / alpha; for (size_t j = 0; j < 3; j++) { image.pixels[i + j] *= alphaFactor; } } } ``` Not working SIMD attempt (should 255/rgba.a actually do floating point here or is this the problem?) @csmartdalton: ``` // CG only supports premultiplied alpha. Unmultiply now. size_t imageSizeInBytes = image.height * image.width * 4; for (size_t i = 0; i < imageSizeInBytes; i += 4) { auto rgba = rive::simd::load<uint8_t, 4>(&image.pixels[i]); if (rgba.a != 0) { rive::simd::store(&image.pixels[i], rgba.rgb * 255 / rgba.a); } } ``` This now works with both the dwarf and the problematic png from here: https://2dimensions.slack.com/archives/CLLCU09T6/p1723735670398969?thread_ts=1723673292.651149&cid=CLLCU09T6 Diffs= ccfcbffdf iOS images: back to rendering to a cg context with unmultiplying. (#7868) Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
- Loading branch information