Skip to content

Commit c2a45c1

Browse files
authored
Merge pull request #6739 from jepler/qrio-esp32camera
Enable qrio to work with rgb565 data, including byte-swapped data
2 parents b423520 + 3c3b7cb commit c2a45c1

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

ports/espressif/bindings/esp32_camera/Camera.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
//| pixel_format: PixelFormat=PixelFormat.RGB565,
5858
//| frame_size: FrameSize=FrameSize.QQVGA,
5959
//| jpeg_quality: int=15,
60-
//| double_buffered: bool = True,
60+
//| framebuffer_count: int = 1,
6161
//| grab_mode: GrabMode = GrabMode.WHEN_EMPTY,
6262
//| ) -> None:
6363
//| """

shared-bindings/qrio/PixelPolicy.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,28 @@
3434
//| """The input buffer to `QRDecoder.decode` consists of greyscale values in every byte"""
3535
//|
3636
//| EVEN_BYTES: PixelPolicy
37-
//| """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."""
37+
//| """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."""
3838
//|
3939
//| ODD_BYTES: PixelPolicy
40-
//| """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"""
40+
//| """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"""
41+
//|
42+
//| RGB565_SWAPPED: PixelPolicy
43+
//| """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."""
44+
//|
45+
//| RGB565: PixelPolicy
46+
//| """The input buffer to `QRDecoder.decode` consists of RGB565 values in native order. The green component is used."""
4147
//|
4248

4349
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVERY_BYTE, QRIO_EVERY_BYTE);
50+
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, RGB565, QRIO_RGB565);
51+
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, RGB565_SWAPPED, QRIO_RGB565_SWAPPED);
4452
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVEN_BYTES, QRIO_EVEN_BYTES);
4553
MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, ODD_BYTES, QRIO_EVEN_BYTES);
4654

4755
MAKE_ENUM_MAP(qrio_pixel_policy) {
4856
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVERY_BYTE),
57+
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, RGB565),
58+
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, RGB565_SWAPPED),
4959
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVEN_BYTES),
5060
MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, ODD_BYTES),
5161
};

shared-bindings/qrio/PixelPolicy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
extern const mp_obj_type_t qrio_pixel_policy_type;
3434

3535
typedef enum {
36-
QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES
36+
QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES, QRIO_RGB565, QRIO_RGB565_SWAPPED
3737
} qrio_pixel_policy_t;
3838

3939
extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj;

shared-module/qrio/QRDecoder.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co
104104
uint8_t *src = bufinfo->buf;
105105

106106
switch (policy) {
107+
case QRIO_RGB565: {
108+
uint16_t *src16 = bufinfo->buf;
109+
for (int i = 0; i < width * height; i++) {
110+
framebuffer[i] = (src16[i] >> 3) & 0xfc;
111+
}
112+
break;
113+
}
114+
case QRIO_RGB565_SWAPPED: {
115+
uint16_t *src16 = bufinfo->buf;
116+
for (int i = 0; i < width * height; i++) {
117+
framebuffer[i] = (__builtin_bswap16(src16[i]) >> 3) & 0xfc;
118+
}
119+
break;
120+
}
107121
case QRIO_EVERY_BYTE:
108122
memcpy(framebuffer, src, width * height);
109123
break;
@@ -116,6 +130,7 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co
116130
for (int i = 0; i < width * height; i++) {
117131
framebuffer[i] = src[2 * i];
118132
}
133+
break;
119134
}
120135
quirc_end(self->quirc);
121136

0 commit comments

Comments
 (0)