According to my question for RGB888 to RGB565, I would like to do RGB565 to RGB888, here is my testing code, however I got stuck on convert to RGB888 byte array.
import numpy as np
np.random.seed(42)
im = np.random.randint(0,256,(1,4,2), dtype=np.uint8)
# >>> im.nbytes
# 8
# >>> im
# array([[[102, 220],
# [225, 95],
# [179, 61],
# [234, 203]]], dtype=uint8)
# Make components of RGB888
R8 = (im[...,0] & 0xF8).astype(np.uint32) << 8
G8 = (im[...,0] & 0x07).astype(np.uint32) << 5 | (im[...,1] & 0xE0).astype(np.uint32)
B8 = (im[...,1] & 0x1F).astype(np.uint32)
RGB888 = R8 | G8 | B8
# >>> RGB888.nbytes
# 16 <= here I think it should be 12 (4x3 bytes)
# >>> RGB888.reshape(1, 4, 3)
# Traceback (most recent call last):
# File "<input>", line 1, in <module>
# ValueError: cannot reshape array of size 4 into shape (1,4,3)
When I use astype(np.uint16), some values become 0 because it need larger data type to store, that's why I use unit32 on above code.
I know unit32 will make above code's RGB888 size to be 16, so I would like to ask if any other correct way to transfer RGB565 to RGB888?
np.uint16array where each element corresponds to a single packed pixel.uint16type, so it would make more sense to start with that.