1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-19 14:08:11 +00:00

fix(core): removed no longer needed emulator gamma correction

[no changelog]
This commit is contained in:
tychovrahe 2023-06-19 22:24:30 +02:00 committed by TychoVrahe
parent c85102494d
commit ef5469ad90
2 changed files with 1 additions and 95 deletions

View File

@ -32,7 +32,6 @@
#include "memzero.h"
extern void main_clean_exit(int);
extern float display_gamma(float);
void __attribute__((noreturn)) trezor_shutdown(void) {
printf("SHUTDOWN\n");
@ -165,9 +164,6 @@ uint32_t hal_ticks_ms() {
}
static int SDLCALL emulator_event_filter(void *userdata, SDL_Event *event) {
#if defined TREZOR_MODEL_T
float gamma = display_gamma(0);
#endif
switch (event->type) {
case SDL_QUIT:
trezor_shutdown();
@ -183,22 +179,6 @@ static int SDLCALL emulator_event_filter(void *userdata, SDL_Event *event) {
case SDLK_p:
display_save("emu");
return 0;
#if defined TREZOR_MODEL_T
// Left and right arrows controlling display gamma
// Only for TT (in button models, arrows do different things)
case SDLK_LEFT:
gamma = fmaxf(0.0001f, gamma - 0.05f);
printf("DISPLAY_GAMMA: %0.2f\n", gamma);
display_gamma(gamma);
display_refresh();
return 0;
case SDLK_RIGHT:
gamma = fminf(8.0f, gamma + 0.05f);
printf("DISPLAY_GAMMA: %0.2f\n", gamma);
display_gamma(gamma);
display_refresh();
return 0;
#endif
}
break;
}

View File

@ -63,18 +63,13 @@
static SDL_Window *WINDOW;
static SDL_Renderer *RENDERER;
// BUFFER_TO_DISPLAY will contain the actual pixels to be displayed,
// it will be filled from BUFFER by gamma-correcting the pixel colors.
// Screenshots will be taken with data from BUFFER.
static SDL_Surface *BUFFER;
static SDL_Surface *BUFFER_TO_DISPLAY;
static SDL_Texture *TEXTURE, *BACKGROUND;
static SDL_Surface *PREV_SAVED;
static int DISPLAY_BACKLIGHT = -1;
static int DISPLAY_ORIENTATION = -1;
float DISPLAY_GAMMA = 0.55f;
int sdl_display_res_x = DISPLAY_RESX, sdl_display_res_y = DISPLAY_RESY;
int sdl_touch_offset_x, sdl_touch_offset_y;
@ -82,10 +77,6 @@ int sdl_touch_offset_x, sdl_touch_offset_y;
// Using RGB565 (16-bit) color format.
typedef uint16_t pixel_color;
// Will depend on SDL_VIDEODRIVER env variable
static bool DO_GAMMA_CORRECTION = true;
static pixel_color GAMMA_LUT[0x10000];
// this is just for compatibility with DMA2D using algorithms
uint8_t *const DISPLAY_DATA_ADDRESS = 0;
@ -101,48 +92,6 @@ static struct {
} pos;
} PIXELWINDOW;
static pixel_color gamma_correct(pixel_color c, float gamma) {
// NOTE: 0x1f/31 and 0x3f/63 are maximum values of RGB components
// given the color is 16-bit (5 bits for R, 6 bits for G, 5 bits for B).
int r = (c >> 11) & 0x1f;
int g = (c >> 5) & 0x3f;
int b = c & 0x1f;
r = (int)round(pow(r / 31.0, gamma) * 31.0);
g = (int)round(pow(g / 63.0, gamma) * 63.0);
b = (int)round(pow(b / 31.0, gamma) * 31.0);
return (r << 11) | (g << 5) | b;
}
static void prepare_gamma_lut(float gamma) {
for (int i = 0; i < 0x10000; i++) {
GAMMA_LUT[i] = gamma_correct(i, gamma);
}
}
#if defined TREZOR_MODEL_T
static void gamma_correct_buffer_to_display(void) {
// Gamma correct all the pixels in BUFFER_TO_DISPLAY.
pixel_color *pixels = (pixel_color *)BUFFER_TO_DISPLAY->pixels;
for (int y = 0; y < BUFFER_TO_DISPLAY->h; y++) {
for (int x = 0; x < BUFFER_TO_DISPLAY->w; x++) {
int index = y * BUFFER_TO_DISPLAY->pitch / 2 + x;
pixels[index] = GAMMA_LUT[pixels[index]];
}
}
}
#endif
float display_gamma(float gamma) {
float prev_gamma = DISPLAY_GAMMA;
if (gamma != 0) {
DISPLAY_GAMMA = gamma;
prepare_gamma_lut(gamma);
}
return prev_gamma;
}
void display_pixeldata(pixel_color c) {
#if defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R
// set to white if highest bits of all R, G, B values are set to 1
@ -175,7 +124,6 @@ void display_init_seq(void) {}
void display_deinit(void) {
SDL_FreeSurface(PREV_SAVED);
SDL_FreeSurface(BUFFER);
SDL_FreeSurface(BUFFER_TO_DISPLAY);
if (BACKGROUND != NULL) {
SDL_DestroyTexture(BACKGROUND);
}
@ -198,16 +146,6 @@ void display_init(void) {
}
atexit(display_deinit);
// Not doing gamma correction for "dummy" SDL driver
// (not to slow down device/UI tests)
char *sdl_env = getenv("SDL_VIDEODRIVER");
if (sdl_env && strcmp(sdl_env, "dummy") == 0) {
DO_GAMMA_CORRECTION = false;
} else {
DO_GAMMA_CORRECTION = true;
prepare_gamma_lut(DISPLAY_GAMMA);
}
char *window_title = NULL;
char *window_title_alloc = NULL;
if (asprintf(&window_title_alloc, "Trezor^emu: %s", profile_name()) > 0) {
@ -241,9 +179,6 @@ void display_init(void) {
SDL_RenderClear(RENDERER);
BUFFER = SDL_CreateRGBSurface(0, MAX_DISPLAY_RESX, MAX_DISPLAY_RESY, 16,
0xF800, 0x07E0, 0x001F, 0x0000);
BUFFER_TO_DISPLAY =
SDL_CreateRGBSurface(0, MAX_DISPLAY_RESX, MAX_DISPLAY_RESY, 16, 0xF800,
0x07E0, 0x001F, 0x0000);
TEXTURE = SDL_CreateTexture(RENDERER, SDL_PIXELFORMAT_RGB565,
SDL_TEXTUREACCESS_STREAMING, DISPLAY_RESX,
DISPLAY_RESY);
@ -319,17 +254,8 @@ void display_refresh(void) {
} else {
SDL_RenderClear(RENDERER);
}
// Fill BUFFER_TO_DISPLAY with BUFFER data
SDL_BlitSurface(BUFFER, NULL, BUFFER_TO_DISPLAY, NULL);
#if defined TREZOR_MODEL_T
// Gamma-correcting the display buffer for model T when wanted
if (DO_GAMMA_CORRECTION) {
gamma_correct_buffer_to_display();
}
#endif
// Show the display buffer
SDL_UpdateTexture(TEXTURE, NULL, BUFFER_TO_DISPLAY->pixels,
BUFFER_TO_DISPLAY->pitch);
SDL_UpdateTexture(TEXTURE, NULL, BUFFER->pixels, BUFFER->pitch);
#define BACKLIGHT_NORMAL 150
SDL_SetTextureAlphaMod(TEXTURE,
MIN(255, 255 * DISPLAY_BACKLIGHT / BACKLIGHT_NORMAL));