JPEGDEC: Experimental 3bit/4bit palette no-dither.

pull/682/head
Phil Howard 2023-02-22 15:17:38 +00:00
rodzic d3a1a571d3
commit bea90dfd60
6 zmienionych plików z 87 dodań i 12 usunięć

Wyświetl plik

@ -1,14 +1,30 @@
set(OUTPUT_NAME inky_frame_day_planner)
# Inky Frame 5.7"
add_executable(
${OUTPUT_NAME}
inky_frame_day_planner
inky_frame_day_planner.cpp
)
# Pull in pico libraries that we need
target_link_libraries(${OUTPUT_NAME} pico_stdlib inky_frame hardware_pwm hardware_spi hardware_i2c hardware_rtc fatfs sdcard pico_graphics)
target_link_libraries(inky_frame_day_planner pico_stdlib inky_frame hardware_pwm hardware_spi hardware_i2c hardware_rtc fatfs sdcard pico_graphics)
pico_enable_stdio_usb(${OUTPUT_NAME} 1)
pico_enable_stdio_usb(inky_frame_day_planner 1)
# create map/bin/hex file etc.
pico_add_extra_outputs(${OUTPUT_NAME})
pico_add_extra_outputs(inky_frame_day_planner)
# Inky Frame 7.3"
add_executable(
inky_frame_7_day_planner
inky_frame_day_planner.cpp
)
# Pull in pico libraries that we need
target_link_libraries(inky_frame_7_day_planner pico_stdlib inky_frame_7 hardware_pwm hardware_spi hardware_i2c hardware_rtc fatfs sdcard pico_graphics)
pico_enable_stdio_usb(inky_frame_7_day_planner 1)
# create map/bin/hex file etc.
pico_add_extra_outputs(inky_frame_7_day_planner)
target_compile_definitions(inky_frame_7_day_planner PUBLIC INKY_FRAME_7)

Wyświetl plik

@ -4,7 +4,11 @@
#include <stdio.h>
#include "pico/stdlib.h"
#ifdef INKY_FRAME_7
#include "libraries/inky_frame_7/inky_frame_7.hpp"
#else
#include "libraries/inky_frame/inky_frame.hpp"
#endif
using namespace pimoroni;

Wyświetl plik

@ -69,6 +69,36 @@ int jpegdec_draw_callback(JPEGDRAW *draw) {
return 1; // continue drawing
}
// Draw to the nearest colour instead of dithering
int jpegdec_draw_posterize_callback(JPEGDRAW *draw) {
uint16_t *p = draw->pPixels;
int xo = jpeg_decode_options.x;
int yo = jpeg_decode_options.y;
for(int y = 0; y < draw->iHeight; y++) {
for(int x = 0; x < draw->iWidth; x++) {
int sx = ((draw->x + x + xo) * jpeg_decode_options.w) / jpeg.getWidth();
int sy = ((draw->y + y + yo) * jpeg_decode_options.h) / jpeg.getHeight();
if(xo + sx > 0 && xo + sx < inky.bounds.w && yo + sy > 0 && yo + sy < inky.bounds.h) {
int closest = RGB(RGB565(*p)).closest(inky.palette, inky.palette_size);
if (closest != -1) {
inky.set_pen(closest);
inky.set_pixel({xo + sx, yo + sy});
} else {
inky.set_pen(0);
inky.set_pixel({xo + sx, yo + sy});
}
}
p++;
}
}
return 1; // continue drawing
}
void draw_jpeg(std::string filename, int x, int y, int w, int h) {
// TODO: this is a horrible way to do it but we need to pass some parameters
@ -85,7 +115,8 @@ void draw_jpeg(std::string filename, int x, int y, int w, int h) {
jpegdec_close_callback,
jpegdec_read_callback,
jpegdec_seek_callback,
jpegdec_draw_callback);
jpegdec_draw_callback // Try jpegdec_draw_posterize_callback
);
jpeg.setPixelType(RGB565_BIG_ENDIAN);
@ -134,7 +165,7 @@ int main() {
}; // Wait for debugger
}
filename = "butterfly-600x448.jpg";
filename = "shutterstock_172537049.jpg";
//inky.led(InkyFrame::LED_E, 255);
//sleep_ms(1000);

Wyświetl plik

@ -32,6 +32,9 @@ namespace pimoroni {
void PicoGraphics::frame_convert(PenType type, conversion_callback_func callback) {};
void PicoGraphics::sprite(void* data, const Point &sprite, const Point &dest, const int scale, const int transparent) {};
int PicoGraphics::get_palette_size() {return 0;}
RGB* PicoGraphics::get_palette() {return nullptr;}
void PicoGraphics::set_dimensions(int width, int height) {
bounds = clip = {0, 0, width, height};
}

Wyświetl plik

@ -178,9 +178,6 @@ namespace pimoroni {
Rect clip;
uint thickness = 1;
typedef std::function<void(void *data, size_t length)> conversion_callback_func;
typedef std::function<RGB565()> next_pixel_func;
typedef std::function<RGB888()> next_pixel_func_rgb888;
@ -233,6 +230,9 @@ namespace pimoroni {
virtual void set_pixel_span(const Point &p, uint l) = 0;
virtual void set_thickness(uint t) = 0;
virtual int get_palette_size();
virtual RGB* get_palette();
virtual int create_pen(uint8_t r, uint8_t g, uint8_t b);
virtual int create_pen_hsv(float h, float s, float v);
virtual int update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b);
@ -344,6 +344,9 @@ namespace pimoroni {
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override {};
int get_palette_size() override {return palette_size;};
RGB* get_palette() override {return palette;};
void set_pixel(const Point &p) override;
void set_pixel_span(const Point &p, uint l) override;
void get_dither_candidates(const RGB &col, const RGB *palette, size_t len, std::array<uint8_t, 16> &candidates);
@ -375,6 +378,9 @@ namespace pimoroni {
int create_pen_hsv(float h, float s, float v) override;
int reset_pen(uint8_t i) override;
int get_palette_size() override {return palette_size;};
RGB* get_palette() override {return palette;};
void set_pixel(const Point &p) override;
void set_pixel_span(const Point &p, uint l) override;
void get_dither_candidates(const RGB &col, const RGB *palette, size_t len, std::array<uint8_t, 16> &candidates);
@ -406,6 +412,9 @@ namespace pimoroni {
int create_pen_hsv(float h, float s, float v) override;
int reset_pen(uint8_t i) override;
int get_palette_size() override {return palette_size;};
RGB* get_palette() override {return palette;};
void set_pixel(const Point &p) override;
void set_pixel_span(const Point &p, uint l) override;
void get_dither_candidates(const RGB &col, const RGB *palette, size_t len, std::array<uint8_t, 16> &candidates);
@ -542,6 +551,9 @@ namespace pimoroni {
void set_pixel(const Point &p) override;
void set_pixel_span(const Point &p, uint l) override;
int get_palette_size() override {return palette_size;};
RGB* get_palette() override {return palette;};
void get_dither_candidates(const RGB &col, const RGB *palette, size_t len, std::array<uint8_t, 16> &candidates);
void set_pixel_dither(const Point &p, const RGB &c) override;

Wyświetl plik

@ -149,7 +149,16 @@ MICROPY_EVENT_POLL_HOOK
|| current_graphics->pen_type == PicoGraphics::PEN_P4
|| current_graphics->pen_type == PicoGraphics::PEN_3BIT
|| current_graphics->pen_type == PicoGraphics::PEN_INKY7) {
current_graphics->set_pixel_dither({pDraw->x + x, pDraw->y + y}, RGB((RGB565)pDraw->pPixels[i]));
if (current_flags & FLAG_NO_DITHER) {
int closest = RGB((RGB565)pDraw->pPixels[i]).closest(current_graphics->get_palette(), current_graphics->get_palette_size());
if (closest == -1) {
closest = 0;
}
current_graphics->set_pen(closest);
current_graphics->pixel({pDraw->x + x, pDraw->y + y});
} else {
current_graphics->set_pixel_dither({pDraw->x + x, pDraw->y + y}, RGB((RGB565)pDraw->pPixels[i]));
}
} else {
current_graphics->set_pen(pDraw->pPixels[i]);
current_graphics->pixel({pDraw->x + x, pDraw->y + y});