1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00

modtrezorui: Display.save skips identical screens (#530)

This commit is contained in:
Jan Pochyla 2019-04-02 15:26:34 +02:00 committed by Pavol Rusnak
parent 64925350a2
commit e89699817f
5 changed files with 27 additions and 12 deletions

View File

@ -241,4 +241,6 @@ void display_refresh(void) {
HAL_GPIO_WritePin(OLED_DC_PORT, OLED_DC_PIN, GPIO_PIN_RESET); // set to CMD HAL_GPIO_WritePin(OLED_DC_PORT, OLED_DC_PIN, GPIO_PIN_RESET); // set to CMD
} }
void display_save(const char *prefix) {} const char *display_save(const char *prefix) {
return NULL;
}

View File

@ -498,4 +498,6 @@ void display_refresh(void) {
} }
} }
void display_save(const char *prefix) {} const char *display_save(const char *prefix) {
return NULL;
}

View File

@ -206,23 +206,34 @@ static void display_set_orientation(int degrees) { display_refresh(); }
static void display_set_backlight(int val) { display_refresh(); } static void display_set_backlight(int val) { display_refresh(); }
void display_save(const char *prefix) { const char *display_save(const char *prefix) {
#ifndef TREZOR_EMULATOR_NOUI #ifndef TREZOR_EMULATOR_NOUI
if (!RENDERER) { if (!RENDERER) {
display_init(); display_init();
} }
static uint32_t cnt = 0; static int count;
char fname[256]; static char filename[256];
snprintf(fname, sizeof(fname), "%s%08d.png", prefix, cnt); static SDL_Surface *prev;
// take a cropped view of the screen contents
const SDL_Rect rect = {0, 0, DISPLAY_RESX, DISPLAY_RESY}; const SDL_Rect rect = {0, 0, DISPLAY_RESX, DISPLAY_RESY};
SDL_Surface *crop = SDL_CreateRGBSurface( SDL_Surface *crop = SDL_CreateRGBSurface(
BUFFER->flags, rect.w, rect.h, BUFFER->format->BitsPerPixel, BUFFER->flags, rect.w, rect.h, BUFFER->format->BitsPerPixel,
BUFFER->format->Rmask, BUFFER->format->Gmask, BUFFER->format->Bmask, BUFFER->format->Rmask, BUFFER->format->Gmask, BUFFER->format->Bmask,
BUFFER->format->Amask); BUFFER->format->Amask);
SDL_BlitSurface(BUFFER, &rect, crop, NULL); SDL_BlitSurface(BUFFER, &rect, crop, NULL);
IMG_SavePNG(crop, fname); // compare with previous screen, skip if equal
if (prev != NULL) {
if (memcmp(prev->pixels, crop->pixels, crop->pitch * crop->h) == 0) {
SDL_FreeSurface(crop); SDL_FreeSurface(crop);
fprintf(stderr, "Saved screenshot to %s\n", fname); return filename;
cnt++; }
#endif SDL_FreeSurface(prev);
}
// save to png
snprintf(filename, sizeof(filename), "%s%08d.png", prefix, count++);
IMG_SavePNG(crop, filename);
prev = crop;
return filename;
#endif
return NULL;
} }

View File

@ -67,7 +67,7 @@
void display_init(void); void display_init(void);
void display_refresh(void); void display_refresh(void);
void display_save(const char *prefix); const char *display_save(const char *prefix);
// provided by common // provided by common

View File

@ -28,7 +28,7 @@ extern int sdl_display_res_x, sdl_display_res_y;
extern int sdl_touch_offset_x, sdl_touch_offset_y; extern int sdl_touch_offset_x, sdl_touch_offset_y;
extern void __shutdown(void); extern void __shutdown(void);
extern void display_save(const char *prefix); extern const char *display_save(const char *prefix);
uint32_t touch_read(void) { uint32_t touch_read(void) {
#ifndef TREZOR_EMULATOR_NOUI #ifndef TREZOR_EMULATOR_NOUI