2018-09-11 01:00:21 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the Micro Python project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_COLORCONVERTER_H
|
|
|
|
#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_COLORCONVERTER_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "py/obj.h"
|
2019-07-05 22:01:54 -04:00
|
|
|
#include "shared-module/displayio/Palette.h"
|
2018-09-11 01:00:21 -04:00
|
|
|
|
OnDiskBitmap: INCOMPATIBLE CHANGE: Allow them to use palettes
Before, when an OnDiskBitmap was a paletted bitmap type, the palette
was internal to the OnDiskBitmap, and it internally performed the palette
conversion itself. When using with a tilegrid, a ColorConverter() object
always had to be passed.
Now, an OnDiskBitmap has a "pixel_shader" property. If the bitmap is
a paletted bitmap type, it is a (modifiable) Palette object. Otherwise,
it is a ColorConverter() object as before. This allows palette effects
to be applied to paletted OnDiskBitmaps.
Code that used to say:
```python
face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter())
```
must be updated to say:
```python
face = displayio.TileGrid(odb, pixel_shader=odb.pixel_shader)
```
Compatible code for 6.x and 7.x can say
```python
face = displayio.TileGrid(odb, pixel_shader=getattr(odb, 'pixel_shader', ColorConverter())
```
2021-05-28 11:53:21 -04:00
|
|
|
typedef struct displayio_colorconverter {
|
2018-09-11 01:00:21 -04:00
|
|
|
mp_obj_base_t base;
|
2019-09-05 21:55:45 -04:00
|
|
|
bool dither;
|
2021-04-19 11:23:47 -04:00
|
|
|
uint8_t input_colorspace;
|
2023-02-18 16:35:56 -05:00
|
|
|
_displayio_colorspace_t output_colorspace;
|
2020-10-08 22:40:55 -04:00
|
|
|
uint32_t transparent_color;
|
2022-07-30 01:09:49 -04:00
|
|
|
|
|
|
|
// Cache the last computed color in case the are the same.
|
|
|
|
const _displayio_colorspace_t *cached_colorspace;
|
|
|
|
uint32_t cached_input_pixel;
|
|
|
|
uint32_t cached_output_color;
|
2018-09-11 01:00:21 -04:00
|
|
|
} displayio_colorconverter_t;
|
|
|
|
|
2019-03-27 10:55:50 -04:00
|
|
|
bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self);
|
|
|
|
void displayio_colorconverter_finish_refresh(displayio_colorconverter_t *self);
|
2021-03-15 09:57:36 -04:00
|
|
|
void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t *colorspace, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color);
|
2019-08-31 22:07:09 -04:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
uint32_t displayio_colorconverter_dither_noise_1(uint32_t n);
|
2019-08-31 22:07:09 -04:00
|
|
|
uint32_t displayio_colorconverter_dither_noise_2(uint32_t x, uint32_t y);
|
|
|
|
|
2022-07-30 01:09:49 -04:00
|
|
|
// Convert version that doesn't require a colorconverter object.
|
|
|
|
void displayio_convert_color(const _displayio_colorspace_t *colorspace, bool dither, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color);
|
|
|
|
|
2019-07-05 22:01:54 -04:00
|
|
|
uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888);
|
2023-04-07 14:59:55 -04:00
|
|
|
uint8_t displayio_colorconverter_compute_rgb332(uint32_t color_rgb888);
|
2022-07-30 01:09:49 -04:00
|
|
|
uint8_t displayio_colorconverter_compute_rgbd(uint32_t color_rgb888);
|
2019-07-05 22:01:54 -04:00
|
|
|
uint8_t displayio_colorconverter_compute_luma(uint32_t color_rgb888);
|
2019-08-02 19:17:38 -04:00
|
|
|
uint8_t displayio_colorconverter_compute_chroma(uint32_t color_rgb888);
|
|
|
|
uint8_t displayio_colorconverter_compute_hue(uint32_t color_rgb888);
|
2022-07-30 01:09:49 -04:00
|
|
|
uint8_t displayio_colorconverter_compute_sevencolor(uint32_t color_rgb888);
|
2021-08-21 11:32:36 -04:00
|
|
|
void displayio_colorconverter_compute_tricolor(const _displayio_colorspace_t *colorspace, uint8_t pixel_hue, uint32_t *color);
|
2019-03-27 10:55:50 -04:00
|
|
|
|
2018-09-11 01:00:21 -04:00
|
|
|
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_COLORCONVERTER_H
|