使用 RGBA_F16 读取 Android 中的 HDR 照片并从缓冲区访问单个像素

Reading HDR photo in Android with RGBA_F16 and accessing single pixel from buffer

PNG 中的 AFAIK HDR 图像保存为 16 位深度的整数值。但是在 Android SDK 中我可以通过配置 Config.RGBA_F16 读取 HDR 图像,其中有一个非常有趣的描述:

Each pixels is stored on 8 bytes. Each channel (RGB and alpha for translucency) is stored as a half-precision floating point value. This configuration is particularly suited for wide-gamut and HDR content.

像素的单通道(例如红色)是如描述中那样以 8 位存储,还是如名称 RGBA_F16 所暗示的那样以 16 位存储?

第二个问题是如何获取单个像素的所有4个通道?例如。左上角像素的存储位置:索引 0, 1, 2, 3 或索引 0, 1*h*w, 2*h*w, 3*w*h?

关于位数,您混淆了位和字节。每个像素使用 16 位格式存储在 8 个字节中。这里并不矛盾,因为每个像素有 4 个通道,每个通道以 16 位存储。所以每个像素点占用4*16 = 64位内存,相当于8个字节。

对于第二个问题,像素存储为连续的内存块,如 Config.RGBA_F16 的描述建议:

long color = (A & 0xffff) << 48 | (B & 0xffff) << 32 | (G & 0xffff) << 16 | (R & 0xffff);

这在Bitmap.getColorsource code中也可以得到验证。这意味着左上角的像素存储在索引为 0-7 的字节中。

我注意到的一件事是您无法使用 Bitmap.getColor, because it will convert colors to 8 bits. Bitmap.getPixels converts 16 bits to 8 bits too. Using Bitmap.getPixel 获得 16 位像素通道值也无济于事,因为它 returns int.

因此访问 16 位像素的唯一方法是使用 Bitmap.copyPixelsToBuffer