How to convert BGRA to RGB bitmap?

166 views
Skip to first unread message

Dmitry Grebenyuk

unread,
Aug 2, 2023, 1:52:16 PM8/2/23
to Chromium-dev
Hi,

I use `ash::image_util::DecodeImageFile()` which returns `gfx::ImageSkia` with kBGRA_8888_SkColorType.

I have two ML models. For one I feed .bitmap() and it works. For another, I need to make a mapped region with RGB color type. How can I do it?

-Dmitry

Jeremy Roman

unread,
Aug 2, 2023, 2:29:59 PM8/2/23
to dgreb...@google.com, Chromium-dev
You can use SkBitmap::readPixels to copy to an SkPixmap of the structure you want, in memory you allocate; this should be able to do the color type conversion you want. If you need something more complicated, you can use an SkCanvas backed by memory and draw the image into that.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/c744c069-c456-4a37-9bce-17f923bd304dn%40chromium.org.

Dmitry Grebenyuk

unread,
Aug 2, 2023, 6:56:53 PM8/2/23
to Chromium-dev, Jeremy Roman, Chromium-dev, dgreb...@google.com
Thanks,

Is there a more optimized method without looping over each pixel?

Avi Drissman

unread,
Aug 2, 2023, 7:10:38 PM8/2/23
to dgreb...@google.com, Chromium-dev, Jeremy Roman
I'd second Jeremy's suggestion to make a new canvas with the pixel order you want, and draw the source image into it. Skia is optimized, and this would let your code take advantage of any optimization that Skia has or will have implemented.

Avi

Jeremy Roman

unread,
Aug 2, 2023, 8:54:11 PM8/2/23
to Avi Drissman, dgreb...@google.com, Chromium-dev
SkBitmap::readPixels will do the entire pixmap, not an individual pixel. I believe it does use SIMD optimizations, but haven't dug under the hood.

Making a canvas and drawing into it is more general, and should also be reasonably optimized.
Reply all
Reply to author
Forward
0 new messages