mirror of
https://github.com/whowechina/aic_pico.git
synced 2024-11-12 00:40:47 +01:00
anima + image = gfx
This commit is contained in:
parent
29f6dc3e5b
commit
b5f0770eda
@ -13,7 +13,7 @@ function(make_firmware board board_def)
|
||||
|
||||
add_executable(${board}
|
||||
main.c save.c config.c commands.c light.c keypad.c
|
||||
cst816t.c st7789.c gui.c anima.c
|
||||
cst816t.c st7789.c gui.c gfx.c rle.c
|
||||
cli.c usb_descriptors.c)
|
||||
target_compile_definitions(${board} PUBLIC ${board_def})
|
||||
pico_enable_stdio_usb(${board} 1)
|
||||
|
@ -1,20 +0,0 @@
|
||||
#ifndef ANIMA_H
|
||||
#define ANIMA_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint32_t frames;
|
||||
uint32_t size;
|
||||
const uint32_t *index;
|
||||
const uint8_t *data;
|
||||
} anima_t;
|
||||
|
||||
extern const uint16_t white_pallete[16];
|
||||
|
||||
void anima_draw(const anima_t *ani, int x, int y, int frame, const uint16_t pallete[16]);
|
||||
void anima_mix(const anima_t *ani, int x, int y, int frame, uint16_t color);
|
||||
|
||||
#endif
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "st7789.h"
|
||||
#include "rle.h"
|
||||
#include "anima.h"
|
||||
#include "gfx.h"
|
||||
|
||||
const uint16_t white_pallete[16] = {
|
||||
st7789_gray(0x00),
|
||||
@ -23,34 +23,7 @@ const uint16_t white_pallete[16] = {
|
||||
st7789_gray(0xf0),
|
||||
};
|
||||
|
||||
static const uint8_t *compressed_data;
|
||||
static int zero_count = 0;
|
||||
static inline void decode_start(const uint8_t *data)
|
||||
{
|
||||
compressed_data = data;
|
||||
zero_count = 0;
|
||||
}
|
||||
|
||||
static inline uint8_t decode_byte()
|
||||
{
|
||||
if (zero_count) {
|
||||
zero_count--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t value = *compressed_data;
|
||||
compressed_data++;
|
||||
|
||||
if (value == 0) {
|
||||
zero_count = *compressed_data - 1;
|
||||
compressed_data++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void anima_draw(const anima_t *ani, int x, int y, int frame, const uint16_t pallete[16])
|
||||
void gfx_anima_draw(const anima_t *ani, int x, int y, int frame, const uint16_t pallete[16])
|
||||
{
|
||||
uint16_t width = ani->width;
|
||||
uint16_t height = ani->height;
|
||||
@ -68,7 +41,7 @@ void anima_draw(const anima_t *ani, int x, int y, int frame, const uint16_t pall
|
||||
}
|
||||
}
|
||||
|
||||
void anima_mix(const anima_t *ani, int x, int y, int frame, uint16_t color)
|
||||
void gfx_anima_mix(const anima_t *ani, int x, int y, int frame, uint16_t color)
|
||||
{
|
||||
uint16_t width = ani->width;
|
||||
uint16_t height = ani->height;
|
||||
@ -83,4 +56,39 @@ void anima_mix(const anima_t *ani, int x, int y, int frame, uint16_t color)
|
||||
st7789_pixel(x + i * 2 + 1, y + j, color, (value & 0x0f) << 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static rle_t pixels_rle;
|
||||
static rle_t alpha_rle;
|
||||
static int pixels_pos;
|
||||
static int alpha_pos;
|
||||
|
||||
#define INIT_RLE(which) \
|
||||
if (img->which##_rle_x) { \
|
||||
rle_x_init(&which##_rle, img->which, img->width * img->height, img->which##_x); \
|
||||
} else if (img->which##_rle) { \
|
||||
rle_init(&which##_rle, img->which, img->width * img->height); \
|
||||
} else { \
|
||||
which##_pos = 0; \
|
||||
}
|
||||
|
||||
#define GET_DATA(which, type) \
|
||||
(img->which##_rle_x ? \
|
||||
rle_x_get_##type(&which##_rle) : \
|
||||
img->which##_rle ? \
|
||||
rle_get_##type(&which##_rle) :\
|
||||
img->which[which##_pos++])
|
||||
|
||||
void gfx_img_draw(int x, int y, const image_t *img)
|
||||
{
|
||||
INIT_RLE(pixels);
|
||||
INIT_RLE(alpha);
|
||||
|
||||
for (int i = 0; i < img->height; i++) {
|
||||
for (int j = 0; j < img->width; j++) {
|
||||
uint16_t pixel = GET_DATA(pixels, uint16);
|
||||
uint8_t mix = img->alpha ? GET_DATA(alpha, uint8) : 0xff;
|
||||
st7789_pixel(x + j, y + i, pixel, mix);
|
||||
}
|
||||
}
|
||||
}
|
37
firmware/src/gfx.h
Normal file
37
firmware/src/gfx.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef GFX_H
|
||||
#define GFX_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint32_t frames;
|
||||
uint32_t size;
|
||||
const uint32_t *index;
|
||||
const uint8_t *data;
|
||||
} anima_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
|
||||
const uint16_t *pixels;
|
||||
bool pixels_rle;
|
||||
bool pixels_rle_x;
|
||||
uint16_t pixels_x;
|
||||
|
||||
const uint8_t *alpha;
|
||||
bool alpha_rle;
|
||||
bool alpha_rle_x;
|
||||
uint8_t alpha_x;
|
||||
} image_t;
|
||||
|
||||
extern const uint16_t white_pallete[16];
|
||||
|
||||
void gfx_anima_draw(const anima_t *ani, int x, int y, int frame, const uint16_t pallete[16]);
|
||||
void gfx_anima_mix(const anima_t *ani, int x, int y, int frame, uint16_t color);
|
||||
|
||||
void gfx_img_draw(int x, int y, const image_t *img);
|
||||
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
/* Generated by anima_conv.c, 4 bit per pixel, zero run-length compressed. */
|
||||
|
||||
#include "anima.h"
|
||||
#include "gfx.h"
|
||||
|
||||
const uint8_t glow_data[] = {
|
||||
// Frame 1 (size: 831)
|
||||
|
@ -66,7 +66,7 @@ static void draw_keypad()
|
||||
if (tail < 6) {
|
||||
glow_color = st7789_gray(tail * 0x30);
|
||||
}
|
||||
anima_mix(&glow_ani, x - 18, y - 20, glow_frame[key], glow_color);
|
||||
gfx_anima_mix(&glow_ani, x - 18, y - 20, glow_frame[key], glow_color);
|
||||
glow_frame[key]++;
|
||||
}
|
||||
char c = signs_text[row * 3 + col];
|
||||
@ -196,7 +196,7 @@ static void run_background()
|
||||
static int phase = 0;
|
||||
phase++;
|
||||
rotate_colors();
|
||||
anima_draw(&star_ani, 0, 0, phase, ani_colors);
|
||||
gfx_anima_draw(&star_ani, 0, 0, phase, ani_colors);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user