Output: default to PNG with PPM fallback
This commit is contained in:
1 parent
83dc05fd52
commit
b0fdf1faca
7 files changed
+47
-26
No files matched your search
+13
-3
@@ -96,6 +96,11 @@ static int parse_moffat_beta(const char *text, double *value) {
|
||||
|
||||
static int parse_args(int argc, char **argv, Settings *s,
|
||||
const char **write_path) {
|
||||
#ifdef ENABLE_PNG
|
||||
const char *default_output_path = "output/imgs/minkowski_sky.png";
|
||||
#else
|
||||
const char *default_output_path = "output/imgs/minkowski_sky.ppm";
|
||||
#endif
|
||||
*s = (Settings){.width = 1280,
|
||||
.height = 720,
|
||||
.coarse_cell_pixels = 16,
|
||||
@@ -106,7 +111,7 @@ static int parse_args(int argc, char **argv, Settings *s,
|
||||
.observer_radius = 30.0,
|
||||
.psf = {2.7, 4.5},
|
||||
.catalog_path = "assets/sky_grid_5deg.csv",
|
||||
.output_path = "output/imgs/minkowski_sky.ppm",
|
||||
.output_path = default_output_path,
|
||||
.frames_prefix = "frame",
|
||||
.movie_duration = 2.0,
|
||||
.movie_fps = 30.0,
|
||||
@@ -246,13 +251,18 @@ static int render_frame(const Settings *s, StarCatalog *catalog,
|
||||
|
||||
static int frame_output_path(char path[PATH_MAX], const Settings *s,
|
||||
size_t frame_id) {
|
||||
#ifdef ENABLE_PNG
|
||||
const char *extension = "png";
|
||||
#else
|
||||
const char *extension = "ppm";
|
||||
#endif
|
||||
struct stat st;
|
||||
if (s->frames_dir == NULL || s->frames_prefix == NULL ||
|
||||
strchr(s->frames_prefix, '/') != NULL || stat(s->frames_dir, &st) ||
|
||||
!S_ISDIR(st.st_mode))
|
||||
return -1;
|
||||
const int written = snprintf(path, PATH_MAX, "%s/%s_%06zu.png", s->frames_dir,
|
||||
s->frames_prefix, frame_id);
|
||||
const int written = snprintf(path, PATH_MAX, "%s/%s_%06zu.%s", s->frames_dir,
|
||||
s->frames_prefix, frame_id, extension);
|
||||
return written < 0 || written >= PATH_MAX ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -120,6 +120,7 @@ static unsigned char tonemap_channel(double hdr_value)
|
||||
return (unsigned char)lround(255.0 * clamp(display, 0.0, 1.0));
|
||||
}
|
||||
|
||||
#ifndef ENABLE_PNG
|
||||
static int write_tonemapped_ppm(const char *path, const double *hdr, int width,
|
||||
int height)
|
||||
{
|
||||
@@ -132,6 +133,7 @@ static int write_tonemapped_ppm(const char *path, const double *hdr, int width,
|
||||
}
|
||||
return fclose(file) == 0 ? 0 : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_PNG
|
||||
static int write_tonemapped_png(const char *path, const double *hdr, int width,
|
||||
@@ -171,13 +173,16 @@ done:
|
||||
int write_tonemapped_image(const char *path, const double *hdr, int width, int height)
|
||||
{
|
||||
const size_t path_length = strlen(path);
|
||||
if (path_length >= 4 && strcmp(path + path_length - 4, ".png") == 0) {
|
||||
#ifdef ENABLE_PNG
|
||||
if (path_length >= 4 && strcmp(path + path_length - 4, ".png") == 0)
|
||||
return write_tonemapped_png(path, hdr, width, height);
|
||||
fputs("PNG output is enabled; use a .png output path.\n", stderr);
|
||||
return -1;
|
||||
#else
|
||||
fputs("PNG output is disabled; rebuild with make ENABLE_PNG=1.\n", stderr);
|
||||
return -1;
|
||||
if (path_length >= 4 && strcmp(path + path_length - 4, ".ppm") == 0)
|
||||
return write_tonemapped_ppm(path, hdr, width, height);
|
||||
fputs("PNG output is unavailable; use a .ppm output path or rebuild with libpng.\n",
|
||||
stderr);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
return write_tonemapped_ppm(path, hdr, width, height);
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ LinearRgb blackbody_to_linear_rgb(double temperature_K);
|
||||
void splat_moffat(double *hdr, int width, int height, double x, double y,
|
||||
LinearRgb color, double flux,
|
||||
const PointSpreadFunction *psf);
|
||||
/* Writes PPM by default; a .png path requires a build with ENABLE_PNG=1. */
|
||||
/* Writes PNG when built with libpng; non-libpng builds use PPM fallback. */
|
||||
int write_tonemapped_image(const char *path, const double *hdr, int width,
|
||||
int height);
|
||||
|
||||
|
||||
Reference in new issue
Block a user