E
E
Eugene2021-06-24 01:05:34
JavaScript
Eugene, 2021-06-24 01:05:34

How to decode png with bit depth not equal to 8?

I'm learning png decoding algorithms and I'm having trouble processing images with a bit depth other than 8.
The image is loaded as a buffer (aka Uint8Array). IHDR and PLTE are decoded correctly.
The picture I'm trying to decipher is a 2x2 square cian color (RGBA: 0, 255, 255, 255)

Bit depth 1
Color type 3 (Indexed Color)
Palette
Number of channels 1

After decompression, the array [0,0,0,0] was obtained, where the 1st and 3rd elements indicate the filter type. In this case, it is equal to 0, and after defiltering, the array [0, 0] is obtained. If we correlate it with the palette, it turns out
[0, 255, 255, 255, 0, 255, 255, 255]
Although, in fact, this bitmap should turn out
[0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-06-24
@you_are_enot

You have a color depth of 1 bit, so byte 0 is actually 8 bits with a value of 0. Since you have a picture width of 2, the first two bits (also 0) matter, and the rest are simply ignored.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question