Add support for RGB565 images in qrio
Most cameras produce RGB565_SWAPPED data
This commit is contained in:
parent
86f9d98a5d
commit
5168f6ec1f
|
@ -39,13 +39,23 @@
|
||||||
//| ODD_BYTES: PixelPolicy
|
//| ODD_BYTES: PixelPolicy
|
||||||
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 1, 3, …, and ignored bytes in positions 0, 2, …. This can decode directly from YUV images where the odd bytes hold the Y (luminance) data"""
|
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 1, 3, …, and ignored bytes in positions 0, 2, …. This can decode directly from YUV images where the odd bytes hold the Y (luminance) data"""
|
||||||
//|
|
//|
|
||||||
|
//| RGB565_SWAPPED: PixelPolicy
|
||||||
|
//| """The input buffer to `QRDecoder.decode` consists of RGB565 values in byte-swapped order. The green component is used."""
|
||||||
|
//|
|
||||||
|
//| RGB565: PixelPolicy
|
||||||
|
//| """The input buffer to `QRDecoder.decode` consists of RGB565 values. The green component is used."""
|
||||||
|
//|
|
||||||
|
|
||||||
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVERY_BYTE, QRIO_EVERY_BYTE);
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVERY_BYTE, QRIO_EVERY_BYTE);
|
||||||
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, RGB565, QRIO_RGB565);
|
||||||
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, RGB565_SWAPPED, QRIO_RGB565_SWAPPED);
|
||||||
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVEN_BYTES, QRIO_EVEN_BYTES);
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVEN_BYTES, QRIO_EVEN_BYTES);
|
||||||
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, ODD_BYTES, QRIO_EVEN_BYTES);
|
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, ODD_BYTES, QRIO_EVEN_BYTES);
|
||||||
|
|
||||||
MAKE_ENUM_MAP(qrio_pixel_policy) {
|
MAKE_ENUM_MAP(qrio_pixel_policy) {
|
||||||
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVERY_BYTE),
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVERY_BYTE),
|
||||||
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, RGB565),
|
||||||
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, RGB565_SWAPPED),
|
||||||
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVEN_BYTES),
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVEN_BYTES),
|
||||||
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, ODD_BYTES),
|
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, ODD_BYTES),
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
extern const mp_obj_type_t qrio_pixel_policy_type;
|
extern const mp_obj_type_t qrio_pixel_policy_type;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES
|
QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES, QRIO_RGB565, QRIO_RGB565_SWAPPED
|
||||||
} qrio_pixel_policy_t;
|
} qrio_pixel_policy_t;
|
||||||
|
|
||||||
extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj;
|
extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj;
|
||||||
|
|
|
@ -104,6 +104,20 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co
|
||||||
uint8_t *src = bufinfo->buf;
|
uint8_t *src = bufinfo->buf;
|
||||||
|
|
||||||
switch (policy) {
|
switch (policy) {
|
||||||
|
case QRIO_RGB565: {
|
||||||
|
uint16_t *src16 = bufinfo->buf;
|
||||||
|
for (int i = 0; i < width * height; i++) {
|
||||||
|
framebuffer[i] = (src16[i] >> 3) & 0xfc;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QRIO_RGB565_SWAPPED: {
|
||||||
|
uint16_t *src16 = bufinfo->buf;
|
||||||
|
for (int i = 0; i < width * height; i++) {
|
||||||
|
framebuffer[i] = (__builtin_bswap16(src16[i]) >> 3) & 0xfc;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case QRIO_EVERY_BYTE:
|
case QRIO_EVERY_BYTE:
|
||||||
memcpy(framebuffer, src, width * height);
|
memcpy(framebuffer, src, width * height);
|
||||||
break;
|
break;
|
||||||
|
@ -116,6 +130,7 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co
|
||||||
for (int i = 0; i < width * height; i++) {
|
for (int i = 0; i < width * height; i++) {
|
||||||
framebuffer[i] = src[2 * i];
|
framebuffer[i] = src[2 * i];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
quirc_end(self->quirc);
|
quirc_end(self->quirc);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue