8000 ColorConverter: Add "BGR" color modes. by jepler · Pull Request #4952 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

ColorConverter: Add "BGR" color modes. #4952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

8000

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ msgstr ""
msgid "%q must of type %q"
msgstr ""

#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c
#: shared-bindings/keypad/ShiftRegisterKeys.c
msgid "%q must store bytes"
msgstr ""

#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#: shared-bindings/canio/Match.c
msgid "%q out of range"
Expand Down
8 changes: 8 additions & 0 deletions shared-bindings/displayio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB565, DISPLAY
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB565_SWAPPED, DISPLAYIO_COLORSPACE_RGB565_SWAPPED);
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB555, DISPLAYIO_COLORSPACE_RGB555);
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB555_SWAPPED, DISPLAYIO_COLORSPACE_RGB555_SWAPPED);
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, BGR565, DISPLAYIO_COLORSPACE_BGR565);
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, BGR565_SWAPPED, DISPLAYIO_COLORSPACE_BGR565_SWAPPED);
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, BGR555, DISPLAYIO_COLORSPACE_BGR555);
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, BGR555_SWAPPED, DISPLAYIO_COLORSPACE_BGR555_SWAPPED);

//| class Colorspace:
//| """The colorspace for a `ColorConverter` to operate in"""
Expand All @@ -95,6 +99,10 @@ MAKE_ENUM_MAP(displayio_colorspace) {
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, RGB565_SWAPPED),
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, RGB555),
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, RGB555_SWAPPED),
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, BGR565),
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, BGR565_SWAPPED),
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, BGR555),
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, BGR555_SWAPPED),
};
STATIC MP_DEFINE_CONST_DICT(displayio_colorspace_locals_dict, displayio_colorspace_locals_table);

Expand Down
4 changes: 4 additions & 0 deletions shared-bindings/displayio/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ typedef enum {
DISPLAYIO_COLORSPACE_RGB555,
DISPLAYIO_COLORSPACE_RGB565_SWAPPED,
DISPLAYIO_COLORSPACE_RGB555_SWAPPED,
DISPLAYIO_COLORSPACE_BGR565,
DISPLAYIO_COLORSPACE_BGR555,
DISPLAYIO_COLORSPACE_BGR565_SWAPPED,
DISPLAYIO_COLORSPACE_BGR555_SWAPPED,
} displayio_colorspace_t;

typedef bool (*display_bus_bus_reset)(mp_obj_t bus);
Expand Down
22 changes: 22 additions & 0 deletions shared-module/displayio/ColorConverter.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d
}
break;

case DISPLAYIO_COLORSP 7617 ACE_BGR565_SWAPPED:
pixel = __builtin_bswap16(pixel);
MP_FALLTHROUGH;
case DISPLAYIO_COLORSPACE_BGR565: {
uint32_t b8 = (pixel >> 11) << 3;
uint32_t g8 = ((pixel >> 5) << 2) & 0xff;
uint32_t r8 = (pixel << 3) & 0xff;
pixel = (r8 << 16) | (g8 << 8) | b8;
}
break;

case DISPLAYIO_COLORSPACE_BGR555_SWAPPED:
pixel = __builtin_bswap16(pixel);
MP_FALLTHROUGH;
case DISPLAYIO_COLORSPACE_BGR555: {
uint32_t b8 = (pixel >> 10) << 3;
uint32_t g8 = ((pixel >> 5) << 3) & 0xff;
uint32_t r8 = (pixel << 3) & 0xff;
pixel = (r8 << 16) | (g8 << 8) | b8;
}
break;

case DISPLAYIO_COLORSPACE_RGB888:
break;
}
Expand Down
0