Skip to content

Commit

Permalink
Changed images
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jan 12, 2024
1 parent d74b651 commit 2351bb5
Show file tree
Hide file tree
Showing 22 changed files with 5,165 additions and 2,862 deletions.
3 changes: 1 addition & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
BasedOnStyle: Google

# Language: Cpp
Standard: Cpp11
Standard: Cpp11

AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true

AllowShortCaseLabelsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true

BreakConstructorInitializersBeforeComma: true
Expand Down
9 changes: 4 additions & 5 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function(add_yapp name)
add_executable(${name} ${name}.cpp)
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR}/libs)
add_executable(${name} ${name}.cpp)
set_target_properties(${name} PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED YES)
target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR}/libs)
target_link_libraries(${name} PRIVATE yocto)
endfunction()

Expand All @@ -16,6 +16,5 @@ add_yapp(yconverts)
add_yapp(ysamples)

if(YOCTO_CUDA)
add_yapp(ycutrace)
add_yapp(ycutrace)
endif()

8 changes: 4 additions & 4 deletions apps/ycolorgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void run(const vector<string>& args) {
// switch between interactive and offline
if (!interactive) {
// apply color grade
image = colorgrade_image(image, params);
image = colorgrade_image(image, true, params);

// save image
save_image(outname, image);
Expand All @@ -83,8 +83,8 @@ void run(const vector<string>& args) {
auto params = colorgrade_params{};

// display image
auto display = make_image(image.width, image.height, false);
colorgrade_image_mt(display, image, params);
auto display = image;
colorgrade_image(display, image, true, params);

// opengl image
auto glimage = glimage_state{};
Expand Down Expand Up @@ -123,7 +123,7 @@ void run(const vector<string>& args) {
"highlights color", params.highlights_color);
end_gui_header();
if (edited) {
colorgrade_image_mt(display, image, params);
colorgrade_image(display, image, true, params);
set_image(glimage, display);
}
}
Expand Down
17 changes: 7 additions & 10 deletions apps/yimalpha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,22 @@ void run(const vector<string>& args) {
auto alpha = load_image(alphaname);

// check sizes
if (image.width != alpha.width || image.height != alpha.height)
if (image.size() != alpha.size())
throw io_error("different image sizes");

// check types
if (image.linear != alpha.linear) throw io_error("different image types");

// edit alpha
auto out = make_image(image.width, image.height, image.linear);
for (auto idx : range(image.pixels.size())) {
auto calpha = alpha.pixels[idx];
auto out = image_t<vec4f>{image.size()};
for (auto idx : range(image.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.pixels[idx] = {alpha_, alpha_, alpha_, alpha_};
out[idx] = {alpha_, alpha_, alpha_, alpha_};
} else {
auto color = image.pixels[idx];
auto color = image[idx];
color.w = alpha_;
out.pixels[idx] = color;
out[idx] = color;
}
}

Expand Down
8 changes: 2 additions & 6 deletions apps/yimdiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ void run(const vector<string>& args) {
auto image2 = load_image(filename2);

// check sizes
if (image1.width != image2.width || image1.height != image2.height)
throw io_error("different image sizes");

// check types
if (image1.linear != image2.linear) throw io_error("different image types");
if (image1.size() != image2.size()) throw io_error("different image sizes");

// compute diff
auto diff = image_difference(image1, image2, true);
Expand All @@ -71,7 +67,7 @@ void run(const vector<string>& args) {

// check diff
if (signal) {
for (auto& c : diff.pixels) {
for (auto& c : diff) {
if (max(xyz(c)) > threshold) {
throw std::runtime_error{"image content differ"};
}
Expand Down
14 changes: 8 additions & 6 deletions apps/ytonemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ void run(const vector<string>& args) {
parse_cli(cli, args);

// load
auto image = load_image(imagename);
auto image = load_image(imagename, is_ldr_filename(imagename));
auto linear = is_hdr_filename(imagename);

// resize if needed
if (width != 0 || height != 0) {
image = resize_image(image, width, height);
image = resize_image(image, {width, height});
}

// switch between interactive and offline
if (!interactive) {
// tonemap if needed
if (image.linear && is_ldr_filename(outname)) {
if (linear && is_ldr_filename(outname)) {
image = tonemap_image(image, exposure, filmic);
}

Expand All @@ -78,10 +79,11 @@ void run(const vector<string>& args) {
} else {
#ifdef YOCTO_OPENGL
// display image
auto display = make_image(image.width, image.height, false);
if (!linear) image = srgb_to_rgb(image);
auto display = image;
float exposure = 0;
bool filmic = false;
tonemap_image_mt(display, image, exposure, filmic);
tonemap_image(display, image, exposure, filmic);

// opengl image
auto glimage = glimage_state{};
Expand All @@ -100,7 +102,7 @@ void run(const vector<string>& args) {
};
callbacks.widgets = [&](const gui_input& input) {
if (draw_tonemap_widgets(input, exposure, filmic)) {
tonemap_image_mt(display, image, exposure, filmic);
tonemap_image(display, image, exposure, filmic);
set_image(glimage, display);
}
draw_image_widgets(input, image, display, glparams);
Expand Down
8 changes: 4 additions & 4 deletions apps/ytrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void run(const vector<string>& args) {

// add environment
if (!envname.empty()) {
add_environment(scene, envname);
add_environment(scene, "environment", envname);
}

// camera
Expand Down Expand Up @@ -164,7 +164,7 @@ void run(const vector<string>& args) {
auto context = make_trace_context(params);

// init image
auto image = make_image(state.width, state.height, true);
auto image = image_t<vec4f>{state.render.size()};

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

// render preview
trace_preview(image, context, state, scene, bvh, lights, params);
Expand Down
6 changes: 3 additions & 3 deletions libs/yocto/yocto_cutrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ cutrace_bvh make_cutrace_bvh(cutrace_context& context,
// compact
auto compacted_size = download_buffer_value(compacted_size_buffer);
sbvh.buffer = make_buffer(
context.cuda_stream, compacted_size, (byte*)nullptr);
context.cuda_stream, compacted_size, (byte*)nullptr);
check_result(optixAccelCompact(context.optix_context,
/*cuda_stream:*/ 0, sbvh.handle, sbvh.buffer.device_ptr(),
sbvh.buffer.size_in_bytes(), &sbvh.handle));
Expand Down Expand Up @@ -861,7 +861,7 @@ cutrace_bvh make_cutrace_bvh(cutrace_context& context,
// compact
auto compacted_size = download_buffer_value(compacted_size_buffer);
ibvh.buffer = make_buffer(
context.cuda_stream, compacted_size, (byte*)nullptr);
context.cuda_stream, compacted_size, (byte*)nullptr);
check_result(optixAccelCompact(context.optix_context,
/*cuda_stream:*/ 0, ibvh.handle, ibvh.buffer.device_ptr(),
ibvh.buffer.size_in_bytes(), &ibvh.handle));
Expand Down Expand Up @@ -896,7 +896,7 @@ cutrace_state make_cutrace_state(cutrace_context& context,
}
state.samples = 0;
state.image = make_buffer(
context.cuda_stream, state.width * state.height, (vec4f*)nullptr);
context.cuda_stream, state.width * state.height, (vec4f*)nullptr);
state.albedo = make_buffer(
context.cuda_stream, state.width * state.height, (vec3f*)nullptr);
state.normal = make_buffer(
Expand Down
4 changes: 2 additions & 2 deletions libs/yocto/yocto_cutrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ struct cuspan {
CUdeviceptr device_ptr() const { return _data; }
size_t size_in_bytes() const { return _size * sizeof(T); }
void swap(cuspan& other) {
std::swap(_data, other._data);
std::swap(_size, other._size);
std::swap(_data, other._data);
std::swap(_size, other._size);
}

CUdeviceptr _data = 0;
Expand Down
Loading

0 comments on commit 2351bb5

Please sign in to comment.