Skip to content

Commit

Permalink
Removal of yocto_image.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jan 30, 2024
1 parent 4011e13 commit de7548e
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 202 deletions.
2 changes: 1 addition & 1 deletion libs/yocto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
add_library(yocto STATIC
yocto_math.h
yocto_image.h
yocto_sampling.h yocto_shading.h
yocto_modeling.h yocto_animation.h
yocto_raycasting.h yocto_raycasting.cpp
yocto_shape.h yocto_shape.cpp
yocto_image.h yocto_image.cpp
yocto_scene.h yocto_scene.cpp
yocto_trace.h yocto_trace.cpp
yocto_modelio.h yocto_modelio.cpp
Expand Down
183 changes: 0 additions & 183 deletions libs/yocto/yocto_image.cpp

This file was deleted.

138 changes: 120 additions & 18 deletions libs/yocto/yocto_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,45 +311,45 @@ inline T reconstruct_image(const image_t<T>& img, vec2f uv,
namespace yocto {

// Conversion from/to floats.
image_t<vec4f> byte_to_float(const image_t<vec4b>& bt);
image_t<vec4b> float_to_byte(const image_t<vec4f>& fl);
inline image_t<vec4f> byte_to_float(const image_t<vec4b>& bt);
inline image_t<vec4b> float_to_byte(const image_t<vec4f>& fl);

// Conversion between linear and gamma-encoded images.
image_t<vec4f> srgb_to_rgb(const image_t<vec4f>& srgb);
image_t<vec4f> rgb_to_srgb(const image_t<vec4f>& rgb);
image_t<vec4f> srgbb_to_rgb(const image_t<vec4b>& srgb);
image_t<vec4b> rgb_to_srgbb(const image_t<vec4f>& rgb);
inline image_t<vec4f> srgb_to_rgb(const image_t<vec4f>& srgb);
inline image_t<vec4f> rgb_to_srgb(const image_t<vec4f>& rgb);
inline image_t<vec4f> srgbb_to_rgb(const image_t<vec4b>& srgb);
inline image_t<vec4b> rgb_to_srgbb(const image_t<vec4f>& rgb);

// Apply exposure and filmic tone mapping
image_t<vec4f> tonemap_image(const image_t<vec4f>& hdr, float exposure = 0,
bool filmic = false, bool srgb = true);
image_t<vec4b> tonemapb_image(const image_t<vec4f>& hdr, float exposure = 0,
bool filmic = false, bool srgb = true);
inline image_t<vec4f> tonemap_image(const image_t<vec4f>& hdr,
float exposure = 0, bool filmic = false, bool srgb = true);
inline image_t<vec4b> tonemapb_image(const image_t<vec4f>& hdr,
float exposure = 0, bool filmic = false, bool srgb = true);
// fast tone map for UI
void tonemap_image(image_t<vec4f>& ldr, const image_t<vec4f>& hdr,
inline void tonemap_image(image_t<vec4f>& ldr, const image_t<vec4f>& hdr,
float exposure = 0, bool filmic = false, bool srgb = true);

// Apply exposure and filmic tone mapping
image_t<vec4f> colorgrade_image(
inline image_t<vec4f> colorgrade_image(
const image_t<vec4f>& img, bool linear, const colorgrade_params& params);
// compute white balance
vec3f compute_white_balance(const image_t<vec4f>& img);
inline vec3f compute_white_balance(const image_t<vec4f>& img);
// fast color grade for UI
void colorgrade_image(image_t<vec4f>& graded, const image_t<vec4f>& img,
inline void colorgrade_image(image_t<vec4f>& graded, const image_t<vec4f>& img,
bool linear, const colorgrade_params& params);

// image compositing
image_t<vec4f> composite_image(
inline image_t<vec4f> composite_image(
const image_t<vec4f>& foreground, const image_t<vec4f>& background);

// removes alpha
image_t<vec4f> remove_alpha(const image_t<vec4f>& img);
inline image_t<vec4f> remove_alpha(const image_t<vec4f>& img);

// turns alpha into a gray scale image
image_t<vec4f> alpha_to_gray(const image_t<vec4f>& img);
inline image_t<vec4f> alpha_to_gray(const image_t<vec4f>& img);

// image difference
image_t<vec4f> image_difference(
inline image_t<vec4f> image_difference(
const image_t<vec4f>& a, const image_t<vec4f>& b, bool display);

// image resizing
Expand Down Expand Up @@ -1238,6 +1238,108 @@ inline T reconstruct_curve(const vector<T>& curve, float u,

} // namespace yocto

// -----------------------------------------------------------------------------
// IMPLEMENTATION OF IMAGE OPERATIONS
// -----------------------------------------------------------------------------
namespace yocto {

// Conversion from/to floats.
inline image_t<vec4f> byte_to_float(const image_t<vec4b>& bt) {
return transform_image(bt, [](vec4b a) { return byte_to_float(a); });
}
inline image_t<vec4b> float_to_byte(const image_t<vec4f>& fl) {
return transform_image(fl, [](vec4f a) { return float_to_byte(a); });
}

// Conversion between linear and gamma-encoded images.
inline image_t<vec4f> srgb_to_rgb(const image_t<vec4f>& srgb) {
return transform_image(srgb, [](vec4f a) { return srgb_to_rgb(a); });
}
inline image_t<vec4f> rgb_to_srgb(const image_t<vec4f>& rgb) {
return transform_image(rgb, [](vec4f a) { return rgb_to_srgb(a); });
}
inline image_t<vec4f> srgbb_to_rgb(const image_t<vec4b>& srgb) {
return transform_image(srgb, [](vec4b a) { return srgbb_to_rgb(a); });
}
inline image_t<vec4b> rgb_to_srgbb(const image_t<vec4f>& rgb) {
return transform_image(rgb, [](vec4f a) { return rgb_to_srgbb(a); });
}

// Apply exposure and filmic tone mapping
inline image_t<vec4f> tonemap_image(
const image_t<vec4f>& hdr, float exposure, bool filmic, bool srgb) {
return transform_image(hdr, [exposure, filmic, srgb](vec4f a) {
return tonemap(a, exposure, filmic, srgb);
});
}
inline image_t<vec4b> tonemapb_image(
const image_t<vec4f>& hdr, float exposure, bool filmic, bool srgb) {
return transform_image(hdr, [exposure, filmic, srgb](vec4f a) {
return float_to_byte(tonemap(a, exposure, filmic, srgb));
});
}
inline void tonemap_image(image_t<vec4f>& ldr, const image_t<vec4f>& hdr,
float exposure, bool filmic, bool srgb) {
return transform_image(ldr, hdr, [exposure, filmic, srgb](vec4f a) {
return tonemap(a, exposure, filmic, srgb);
});
}

// Apply exposure and filmic tone mapping
inline image_t<vec4f> colorgrade_image(
const image_t<vec4f>& img, bool linear, const colorgrade_params& params) {
return transform_image(
img, [linear, params](vec4f a) { return colorgrade(a, linear, params); });
}
inline void colorgrade_image(image_t<vec4f>& graded, const image_t<vec4f>& img,
bool linear, const colorgrade_params& params) {
return transform_image(graded, img,
[linear, params](vec4f a) { return colorgrade(a, linear, params); });
}

// compute white balance
inline vec3f compute_white_balance(const image_t<vec4f>& img) {
auto rgb = vec3f{0, 0, 0};
for (auto& p : img) rgb += xyz(p);
if (rgb == vec3f{0, 0, 0}) return {0, 0, 0};
return rgb / max(rgb);
}

// image compositing
inline image_t<vec4f> composite_image(
const image_t<vec4f>& foreground, const image_t<vec4f>& background) {
return transform_images(
foreground, background, [](vec4f a, vec4f b) { return composite(a, b); });
}

// removes alpha
inline image_t<vec4f> remove_alpha(const image_t<vec4f>& img) {
return transform_image(img, [](vec4f a) -> vec4f { return {xyz(a), 1}; });
}

// turns alpha into a gray scale image
inline image_t<vec4f> alpha_to_gray(const image_t<vec4f>& img) {
return transform_image(img, [](vec4f a) -> vec4f {
auto g = a.w;
return {g, g, g, 1};
});
}

inline image_t<vec4f> image_difference(
const image_t<vec4f>& a, const image_t<vec4f>& b, bool display) {
return transform_images(a, b, [display](vec4f a, vec4f b) -> vec4f {
auto diff = abs(a - b);
if (display) {
auto d = max(diff);
return {d, d, d, 1};
} else {
return diff;
}
});
}

} // namespace yocto

#ifndef __CUDACC__

// -----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit de7548e

Please sign in to comment.