Skip to content

Commit

Permalink
Added an option for testing different tonemap operators
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Feb 21, 2024
1 parent c6d4faa commit 589875b
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions examples/showimage.c
Expand Up @@ -60,14 +60,15 @@ int main(int argc, char *argv[])
int done = 0;
int quit = 0;
SDL_Event event;
const char *tonemap = NULL;
const char *saveFile = NULL;
int result = 0;

(void)argc;

/* Check command line usage */
if ( ! argv[1] ) {
SDL_Log("Usage: %s [-fullscreen] [-save file.png] <image_file> ...\n", argv[0]);
SDL_Log("Usage: %s [-fullscreen] [-tonemap X] [-save file.png] <image_file> ...\n", argv[0]);
result = 1;
goto done;
}
Expand Down Expand Up @@ -120,17 +121,49 @@ int main(int argc, char *argv[])
continue;
}

if (SDL_strcmp(argv[i], "-tonemap") == 0 && argv[i+1]) {
++i;
tonemap = argv[i];
continue;
}

if (SDL_strcmp(argv[i], "-save") == 0 && argv[i+1]) {
++i;
saveFile = argv[i];
continue;
}

/* Open the image file */
texture = IMG_LoadTexture(renderer, argv[i]);
if (!texture) {
SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError());
continue;
if (tonemap) {
SDL_Surface *surface, *temp;

surface = IMG_Load(argv[i]);
if (!surface) {
SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError());
continue;
}

/* Use the tonemap operator to convert to SDR output */
SDL_SetStringProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING, tonemap);
temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32);
SDL_DestroySurface(surface);
if (!temp) {
SDL_Log("Couldn't convert surface: %s\n", SDL_GetError());
continue;
}

texture = SDL_CreateTextureFromSurface(renderer, temp);
SDL_DestroySurface(temp);
if (!texture) {
SDL_Log("Couldn't create texture: %s\n", SDL_GetError());
continue;
}
} else {
texture = IMG_LoadTexture(renderer, argv[i]);
if (!texture) {
SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError());
continue;
}
}
SDL_QueryTexture(texture, NULL, NULL, &w, &h);

Expand Down

0 comments on commit 589875b

Please sign in to comment.