Merge pull request #6739 from jepler/qrio-esp32camera

Enable qrio to work with rgb565 data, including byte-swapped data
This commit is contained in:
Jeff Epler 2022-08-10 13:54:40 -05:00 committed by GitHub
commit c2a45c1f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View File

@ -57,7 +57,7 @@
//| pixel_format: PixelFormat=PixelFormat.RGB565,
//| frame_size: FrameSize=FrameSize.QQVGA,
//| jpeg_quality: int=15,
//| double_buffered: bool = True,
//| framebuffer_count: int = 1,
//| grab_mode: GrabMode = GrabMode.WHEN_EMPTY,
//| ) -> None:
//| """

View File

@ -34,18 +34,28 @@
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in every byte"""
//|
//| EVEN_BYTES: PixelPolicy
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 0, 2, …, and ignored bytes in positions 1, 3, …. This can decode directly from YUV images where the even bytes hold the Y (luminance) data."""
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 0, 2, …, and ignored bytes in positions 1, 3, …. This can decode directly from YUV images where the even bytes hold the Y (luminance) data."""
//|
//| 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. Most cameras produce data in byte-swapped order. The green component is used."""
//|
//| RGB565: PixelPolicy
//| """The input buffer to `QRDecoder.decode` consists of RGB565 values in native order. 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, 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, ODD_BYTES, QRIO_EVEN_BYTES);
MAKE_ENUM_MAP(qrio_pixel_policy) {
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, ODD_BYTES),
};

View File

@ -33,7 +33,7 @@
extern const mp_obj_type_t qrio_pixel_policy_type;
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;
extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj;

View File

@ -104,6 +104,20 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co
uint8_t *src = bufinfo->buf;
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:
memcpy(framebuffer, src, width * height);
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++) {
framebuffer[i] = src[2 * i];
}
break;
}
quirc_end(self->quirc);