72 lines
2.0 KiB
C
72 lines
2.0 KiB
C
#include "lcd_pretty_effect.h"
|
|
|
|
#include <math.h>
|
|
#include <string.h>
|
|
|
|
#include "lcd_decode_image.h"
|
|
|
|
static uint16_t *s_pixels;
|
|
static int s_prev_frame = -1;
|
|
static int8_t s_xofs[PLATFORM_LCD_DEMO_IMAGE_W];
|
|
static int8_t s_yofs[PLATFORM_LCD_DEMO_IMAGE_H];
|
|
static int8_t s_xcomp[PLATFORM_LCD_DEMO_IMAGE_W];
|
|
static int8_t s_ycomp[PLATFORM_LCD_DEMO_IMAGE_H];
|
|
|
|
static inline uint16_t get_bgnd_pixel(int x, int y)
|
|
{
|
|
return (uint16_t)*(s_pixels + (y * PLATFORM_LCD_DEMO_IMAGE_W) + x);
|
|
}
|
|
|
|
esp_err_t platform_lcd_pretty_effect_init(void)
|
|
{
|
|
if (s_pixels != NULL) {
|
|
return ESP_OK;
|
|
}
|
|
return platform_lcd_decode_image(&s_pixels);
|
|
}
|
|
|
|
void platform_lcd_pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect)
|
|
{
|
|
if (dest == NULL || linect <= 0) {
|
|
return;
|
|
}
|
|
|
|
if (s_pixels == NULL) {
|
|
memset(dest, 0, (size_t)PLATFORM_LCD_DEMO_IMAGE_W * (size_t)linect * sizeof(uint16_t));
|
|
return;
|
|
}
|
|
|
|
if (frame != s_prev_frame) {
|
|
for (int x = 0; x < PLATFORM_LCD_DEMO_IMAGE_W; x++) {
|
|
s_xofs[x] = sin(frame * 0.15 + x * 0.06) * 4;
|
|
s_xcomp[x] = sin(frame * 0.11 + x * 0.12) * 4;
|
|
}
|
|
for (int y = 0; y < PLATFORM_LCD_DEMO_IMAGE_H; y++) {
|
|
s_yofs[y] = sin(frame * 0.1 + y * 0.05) * 4;
|
|
s_ycomp[y] = sin(frame * 0.07 + y * 0.15) * 4;
|
|
}
|
|
s_prev_frame = frame;
|
|
}
|
|
|
|
for (int y = line; y < line + linect; y++) {
|
|
for (int x = 0; x < PLATFORM_LCD_DEMO_IMAGE_W; x++) {
|
|
int sample_x = x + s_yofs[y] + s_xcomp[x];
|
|
int sample_y = y + s_xofs[x] + s_ycomp[y];
|
|
|
|
if (sample_x < 0) {
|
|
sample_x = 0;
|
|
} else if (sample_x >= PLATFORM_LCD_DEMO_IMAGE_W) {
|
|
sample_x = PLATFORM_LCD_DEMO_IMAGE_W - 1;
|
|
}
|
|
|
|
if (sample_y < 0) {
|
|
sample_y = 0;
|
|
} else if (sample_y >= PLATFORM_LCD_DEMO_IMAGE_H) {
|
|
sample_y = PLATFORM_LCD_DEMO_IMAGE_H - 1;
|
|
}
|
|
|
|
*dest++ = get_bgnd_pixel(sample_x, sample_y);
|
|
}
|
|
}
|
|
}
|