Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jan 31, 2024
1 parent 809b78e commit babc74b
Show file tree
Hide file tree
Showing 20 changed files with 352 additions and 4,720 deletions.
16 changes: 8 additions & 8 deletions apps/ycolorgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ void run(const vector<string>& args) {
parse_cli(cli, args);

// load image
auto image = load_image(imagename);
auto source = load_image(imagename);
auto in_linear = is_linear_filename(imagename);

// switch between interactive and offline
if (!interactive) {
// apply color grade
image = colorgrade_image(image, in_linear, params);
auto graded = colorgrade_image(source, in_linear, params);

// save image
save_image(outname, image);
save_image(outname, graded);
} else {
#ifdef YOCTO_OPENGL

// color grading parameters
auto params = colorgrade_params{};

// display image
auto display = image;
colorgrade_image(display, image, in_linear, params);
auto display = source;
colorgrade_image(display, source, in_linear, params);

// opengl image
auto glimage = glimage_state{};
Expand All @@ -85,7 +85,7 @@ void run(const vector<string>& args) {
};
callbacks.clear = [&](const gui_input& input) { clear_image(glimage); };
callbacks.draw = [&](const gui_input& input) {
update_image_params(input, image, glparams);
update_image_params(input, source, glparams);
draw_image(glimage, glparams);
};
callbacks.widgets = [&](const gui_input& input) {
Expand All @@ -110,11 +110,11 @@ void run(const vector<string>& args) {
"highlights color", params.highlights_color);
end_gui_header();
if (edited) {
colorgrade_image(display, image, true, params);
colorgrade_image(display, source, true, params);
set_image(glimage, display);
}
}
draw_image_widgets(input, image, display, glparams);
draw_image_widgets(input, source, display, glparams);
};
callbacks.uiupdate = [&glparams](const gui_input& input) {
uiupdate_image_params(input, glparams);
Expand Down
12 changes: 6 additions & 6 deletions apps/yimalpha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@ void run(const vector<string>& args) {
parse_cli(cli, args);

// load
auto image = load_image(imagename);
auto alpha = load_image(alphaname);
auto source = load_image(imagename);
auto alpha = load_image(alphaname);

// check sizes and types
if (image.size() != alpha.size()) throw io_error("different image sizes");
if (source.size() != alpha.size()) throw io_error("different image sizes");
if (is_linear_filename(imagename) != is_linear_filename(alphaname) ||
is_linear_filename(imagename) != is_linear_filename(outname))
throw io_error("different image types");

// edit alpha
auto out = image_t<vec4f>{image.size()};
for (auto idx : range(image.size())) {
auto out = image<vec4f>{source.size()};
for (auto idx : range(source.size())) {
auto calpha = alpha[idx];
auto alpha_ = from_color ? mean(xyz(calpha))
: from_black ? (mean(xyz(calpha)) > 0.01 ? 1.0f : 0.0f)
: calpha.w;
if (to_color) {
out[idx] = {alpha_, alpha_, alpha_, alpha_};
} else {
auto color = image[idx];
auto color = source[idx];
color.w = alpha_;
out[idx] = color;
}
Expand Down
29 changes: 15 additions & 14 deletions apps/ytrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,27 @@ void run(const vector<string>& args) {
print_info("render sample {}/{}: {}", state.samples, params.samples,
elapsed_formatted(sample_timer));
if (savebatch && state.samples % params.batch == 0) {
auto image = get_image(state);
auto render = get_image(state);
auto batchname = replace_extension(outname,
"-" + std::to_string(state.samples) + path_extension(outname));
save_image(batchname, image);
save_image(batchname, render);
}
}
print_info("render image: {}", elapsed_formatted(timer));

// save image
timer = simple_timer{};
auto image = get_image(state);
save_image(outname, is_srgb_filename(outname) ? rgb_to_srgb(image) : image);
timer = simple_timer{};
auto render = get_image(state);
save_image(
outname, is_srgb_filename(outname) ? rgb_to_srgb(render) : render);
print_info("save image: {}", elapsed_formatted(timer));
} else {
#ifdef YOCTO_OPENGL
// rendering context
auto context = make_trace_context(params);

// init image
auto image = image_t<vec4f>{state.render.size()};
auto render = image<vec4f>{state.render.size()};

// opengl image
auto glimage = glimage_state{};
Expand All @@ -174,14 +175,14 @@ void run(const vector<string>& args) {
// make sure we can start
trace_cancel(context);
state = make_trace_state(scene, params);
if (image.size() != state.render.size())
image = image_t<vec4f>{state.render.size()};
if (render.size() != state.render.size())
render = image<vec4f>{state.render.size()};

// render preview
trace_preview(image, context, state, scene, bvh, lights, params);
trace_preview(render, context, state, scene, bvh, lights, params);

// update image
set_image(glimage, image);
set_image(glimage, render);

// start
trace_start(context, state, scene, bvh, lights, params);
Expand All @@ -193,8 +194,8 @@ void run(const vector<string>& args) {
// render update
auto render_update = [&]() {
if (context.done) {
get_image(image, state);
set_image(glimage, image);
get_image(render, state);
set_image(glimage, render);
trace_start(context, state, scene, bvh, lights, params);
}
};
Expand All @@ -211,7 +212,7 @@ void run(const vector<string>& args) {
callbacks.clear = [&](const gui_input& input) { clear_image(glimage); };
callbacks.draw = [&](const gui_input& input) {
render_update();
update_image_params(input, image, glparams);
update_image_params(input, render, glparams);
draw_image(glimage, glparams);
};
callbacks.widgets = [&](const gui_input& input) {
Expand All @@ -222,7 +223,7 @@ void run(const vector<string>& args) {
render_restart();
}
draw_tonemap_widgets(input, glparams.exposure, glparams.filmic);
draw_image_widgets(input, image, glparams);
draw_image_widgets(input, render, glparams);
if (edit) {
if (draw_scene_widgets(scene, selection, render_cancel)) {
render_restart();
Expand Down
2 changes: 1 addition & 1 deletion libs/yocto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ add_library(yocto STATIC
yocto_sceneio.h yocto_sceneio.cpp
yocto_gui.h yocto_gui.cpp
yocto_cutrace.h yocto_cutrace.cpp
yocto_parallel.h yocto_cli.h
yocto_cli.h
yocto_diagram.h yocto_diagram.cpp
)

Expand Down
26 changes: 13 additions & 13 deletions libs/yocto/yocto_diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ diagram_shape dimagerect(vec2i size) {

return shape;
}
diagram_shape dimagerect(const image_t<vec4f>& img) {
diagram_shape dimagerect(const image<vec4f>& img) {
return dimagerect(img.size());
}

Expand All @@ -1246,7 +1246,7 @@ diagram_shape dimagegrid(vec2i size) {
shape.quads = shape_.quads;
return shape;
}
diagram_shape dimagegrid(const image_t<vec4f>& img) {
diagram_shape dimagegrid(const image<vec4f>& img) {
return dimagegrid(img.size());
}

Expand All @@ -1263,7 +1263,7 @@ diagram_shape dimagelabel(vec2i size, float scale) {
.quads = dconstants::quad_quads,
};
}
diagram_shape dimagelabel(const image_t<vec4f>& image, float scale) {
diagram_shape dimagelabel(const image<vec4f>& image, float scale) {
return dimagelabel(image.size(), scale);
}

Expand Down Expand Up @@ -1988,7 +1988,7 @@ static material_data make_stroke_material(

// Make an image texture
static texture_data make_image_texture(
const image_t<vec4f>& image, bool linear, bool nearest) {
const image<vec4f>& image, bool linear, bool nearest) {
if (linear) {
return texture_data{.pixelsf = image, .nearest = nearest};
} else {
Expand Down Expand Up @@ -2104,7 +2104,7 @@ static scene_data convert_scene(const diagram_scene& diagram) {
}

// crop image vertically
static image_t<vec4f> crop_image(const image_t<vec4f>& source) {
static image<vec4f> crop_image(const image<vec4f>& source) {
// find min and max
auto [width, height] = source.size();
auto min = 0, max = height;
Expand Down Expand Up @@ -2135,7 +2135,7 @@ static image_t<vec4f> crop_image(const image_t<vec4f>& source) {
if (max < min) return source;

// crop
auto cropped = image_t<vec4f>({width, max - min});
auto cropped = image<vec4f>({width, max - min});
for (auto j : range(min, max)) {
for (auto i : range(width)) {
cropped[{i, j - min}] = source[{i, j}];
Expand All @@ -2147,14 +2147,14 @@ static image_t<vec4f> crop_image(const image_t<vec4f>& source) {
}

// Image rendering
static image_t<vec4f> render_image(const scene_data& scene, int resolution,
static image<vec4f> render_image(const scene_data& scene, int resolution,
int samples, bool noparallel = false);

// Render a diagram to an image
image_t<vec4f> render_diagram(const diagram_data& diagram, int resolution,
image<vec4f> render_diagram(const diagram_data& diagram, int resolution,
int samples, bool boxes, bool crop) {
// final image
auto composite = image_t<vec4f>{{resolution, resolution}, {1, 1, 1, 1}};
auto composite = image<vec4f>{{resolution, resolution}, {1, 1, 1, 1}};

// render scenes
for (auto& scene : diagram.scenes) {
Expand All @@ -2165,7 +2165,7 @@ image_t<vec4f> render_diagram(const diagram_data& diagram, int resolution,
auto render = render_image(yscene, resolution, samples, false);

// helpers
auto draw_quad = [](image_t<vec4f>& composite, vec2i center, vec2i size,
auto draw_quad = [](image<vec4f>& composite, vec2i center, vec2i size,
vec4f color) {
auto extents = composite.size();
for (auto i : range(-size.x / 2, +size.x / 2)) {
Expand All @@ -2181,7 +2181,7 @@ image_t<vec4f> render_diagram(const diagram_data& diagram, int resolution,
center + vec2i{+size.x / 2, j}, vec2i{0, 0}, extents - 1)] = color;
}
};
auto copy_quad = [](image_t<vec4f>& composite, const image_t<vec4f>& source,
auto copy_quad = [](image<vec4f>& composite, const image<vec4f>& source,
vec2i icenter, vec2i scenter, vec2i size) {
auto csize = composite.size();
auto ssize = source.size();
Expand Down Expand Up @@ -2325,15 +2325,15 @@ static vec4f render_ray(
}

// Progressively computes an image.
static image_t<vec4f> render_image(
static image<vec4f> render_image(
const scene_data& scene, int resolution, int samples, bool noparallel) {
// Bvh
auto bvh = make_scene_bvh(scene, false, noparallel);
// Camera
auto& camera = scene.cameras[0];
// Image
auto size = vec2i{resolution, (int)round(resolution / camera.aspect)};
auto render = image_t<vec4f>{size, {0, 0, 0, 0}};
auto render = image<vec4f>{size, {0, 0, 0, 0}};
// Start rendering
auto nsamples = (int)round(sqrt((float)samples));
if (noparallel) {
Expand Down
45 changes: 22 additions & 23 deletions libs/yocto/yocto_diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ struct diagram_labels {
// Diagram style
struct diagram_style {
// Style data
vec4f stroke = {0, 0, 0, 1};
vec4f fill = {0.4, 1.0, 1.0, 1};
vec4f text = {0, 0, 0, 1};
image_t<vec4f> texture = {};
bool highlight = false;
bool arrow = false;
bool nearest = false;
bool linear = false;
bool wireframe = true;
float thickness = 0.015f;
float textscale = 0.05f;
float connect = 0;
vec4f stroke = {0, 0, 0, 1};
vec4f fill = {0.4, 1.0, 1.0, 1};
vec4f text = {0, 0, 0, 1};
image<vec4f> texture = {};
bool highlight = false;
bool arrow = false;
bool nearest = false;
bool linear = false;
bool wireframe = true;
float thickness = 0.015f;
float textscale = 0.05f;
float connect = 0;
};

// Diagram object
Expand Down Expand Up @@ -156,9 +156,8 @@ namespace yocto {
diagram_data make_diagram();

// Rendering a diagram
image_t<vec4f> render_diagram(const diagram_data& diagram,
int resolution = 1440, int samples = 64, bool boxes = false,
bool crop = true);
image<vec4f> render_diagram(const diagram_data& diagram, int resolution = 1440,
int samples = 64, bool boxes = false, bool crop = true);

} // namespace yocto

Expand Down Expand Up @@ -365,22 +364,22 @@ inline diagram_style dfilled(vec4f fill = dcolors::fill1,
vec4f stroke = dcolors::black, float thickness = dthickness::default_) {
return {.stroke = stroke, .fill = fill, .thickness = thickness};
}
inline diagram_style dtextured(const image_t<vec4f>& texture,
inline diagram_style dtextured(const image<vec4f>& texture,
vec4f stroke = dcolors::black, float thickness = dthickness::default_) {
return {.stroke = stroke,
.fill = {1, 1, 1, 1},
.thickness = thickness,
.texture = texture};
}
inline diagram_style dtextured(const image_t<vec4f>& texture, bool interpolate,
inline diagram_style dtextured(const image<vec4f>& texture, bool interpolate,
vec4f stroke = dcolors::black, float thickness = dthickness::default_) {
return {.stroke = stroke,
.fill = {1, 1, 1, 1},
.thickness = thickness,
.texture = texture,
.nearest = !interpolate};
}
inline diagram_style dimtextured(const image_t<vec4f>& texture,
inline diagram_style dimtextured(const image<vec4f>& texture,
vec4f stroke = dcolors::transparent,
float thickness = dthickness::default_) {
return {
Expand All @@ -391,8 +390,8 @@ inline diagram_style dimtextured(const image_t<vec4f>& texture,
.nearest = true,
};
}
inline diagram_style dimtextured(const image_t<vec4f>& texture,
bool interpolate, vec4f stroke = dcolors::transparent,
inline diagram_style dimtextured(const image<vec4f>& texture, bool interpolate,
vec4f stroke = dcolors::transparent,
float thickness = dthickness::default_) {
return {.stroke = stroke,
.fill = {1, 1, 1, 1},
Expand Down Expand Up @@ -576,11 +575,11 @@ diagram_shape daffinegrid(

// Image
diagram_shape dimagerect(vec2i size);
diagram_shape dimagerect(const image_t<vec4f>& image);
diagram_shape dimagerect(const image<vec4f>& image);
diagram_shape dimagegrid(vec2i size);
diagram_shape dimagegrid(const image_t<vec4f>& image);
diagram_shape dimagegrid(const image<vec4f>& image);
diagram_shape dimagelabel(vec2i size, float scale = 1);
diagram_shape dimagelabel(const image_t<vec4f>& image, float scale = 1);
diagram_shape dimagelabel(const image<vec4f>& image, float scale = 1);

// Random points
enum struct drandompoints_type {
Expand Down
Loading

0 comments on commit babc74b

Please sign in to comment.