Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image support for width() and height() #1028

Merged
merged 3 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions apps/yimageproc/yimageproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ image<vec4f> filter_bilateral(const image<vec4f>& img, float spatial_sigma,
auto fw = vector<float>();
for (auto feature_sigma : features_sigma)
fw.push_back(1 / (2.0f * feature_sigma * feature_sigma));
for (auto j = 0; j < img.imsize().y; j++) {
for (auto i = 0; i < img.imsize().x; i++) {
for (auto j = 0; j < img.height(); j++) {
for (auto i = 0; i < img.width(); i++) {
auto av = zero4f;
auto aw = 0.0f;
for (auto fj = -filter_width; fj <= filter_width; fj++) {
for (auto fi = -filter_width; fi <= filter_width; fi++) {
auto ii = i + fi, jj = j + fj;
if (ii < 0 || jj < 0) continue;
if (ii >= img.imsize().x || jj >= img.imsize().y) continue;
if (ii >= img.width() || jj >= img.height()) continue;
auto uv = vec2f{float(i - ii), float(j - jj)};
auto rgb = img[{i, j}] - img[{i, j}];
auto w = (float)exp(-dot(uv, uv) * sw) *
Expand All @@ -76,15 +76,15 @@ image<vec4f> filter_bilateral(
auto fwidth = (int)ceil(2.57f * spatial_sigma);
auto sw = 1 / (2.0f * spatial_sigma * spatial_sigma);
auto rw = 1 / (2.0f * range_sigma * range_sigma);
for (auto j = 0; j < img.imsize().y; j++) {
for (auto i = 0; i < img.imsize().x; i++) {
for (auto j = 0; j < img.height(); j++) {
for (auto i = 0; i < img.width(); i++) {
auto av = zero4f;
auto aw = 0.0f;
for (auto fj = -fwidth; fj <= fwidth; fj++) {
for (auto fi = -fwidth; fi <= fwidth; fi++) {
auto ii = i + fi, jj = j + fj;
if (ii < 0 || jj < 0) continue;
if (ii >= img.imsize().x || jj >= img.imsize().y) continue;
if (ii >= img.width() || jj >= img.height()) continue;
auto uv = vec2f{float(i - ii), float(j - jj)};
auto rgb = img[{i, j}] - img[{ii, jj}];
auto w = exp(-dot(uv, uv) * sw) * exp(-dot(rgb, rgb) * rw);
Expand All @@ -101,8 +101,8 @@ image<vec4f> filter_bilateral(
bool make_image_preset(const string& type, image<vec4f>& img, string& error) {
auto set_region = [](image<vec4f>& img, const image<vec4f>& region,
const vec2i& offset) {
for (auto j = 0; j < region.imsize().y; j++) {
for (auto i = 0; i < region.imsize().x; i++) {
for (auto j = 0; j < region.height(); j++) {
for (auto i = 0; i < region.width(); i++) {
if (!img.contains({i, j})) continue;
img[vec2i{i, j} + offset] = region[{i, j}];
}
Expand Down Expand Up @@ -154,14 +154,14 @@ bool make_image_preset(const string& type, image<vec4f>& img, string& error) {
}
auto montage_size = zero2i;
for (auto& sub_img : sub_imgs) {
montage_size.x += sub_img.imsize().x;
montage_size.y = max(montage_size.y, sub_img.imsize().y);
montage_size.x += sub_img.width();
montage_size.y = max(montage_size.y, sub_img.height());
}
img = image<vec4f>(montage_size);
auto pos = 0;
for (auto& sub_img : sub_imgs) {
set_region(img, sub_img, {pos, 0});
pos += sub_img.imsize().x;
pos += sub_img.width();
}
} else if (type == "images2") {
auto sub_types = vector<string>{"sky", "sunsky"};
Expand All @@ -171,14 +171,14 @@ bool make_image_preset(const string& type, image<vec4f>& img, string& error) {
}
auto montage_size = zero2i;
for (auto& sub_img : sub_imgs) {
montage_size.x += sub_img.imsize().x;
montage_size.y = max(montage_size.y, sub_img.imsize().y);
montage_size.x += sub_img.width();
montage_size.y = max(montage_size.y, sub_img.height());
}
img = image<vec4f>(montage_size);
auto pos = 0;
for (auto& sub_img : sub_imgs) {
set_region(img, sub_img, {pos, 0});
pos += sub_img.imsize().x;
pos += sub_img.width();
}
} else if (type == "test-floor") {
img = make_grid(size);
Expand Down Expand Up @@ -295,17 +295,17 @@ int main(int argc, const char* argv[]) {
auto alpha = image<vec4f>{};
if (!load_image(alpha_filename, alpha, ioerror)) print_fatal(ioerror);
if (img.imsize() != alpha.imsize()) print_fatal("bad image size");
for (auto j = 0; j < img.imsize().y; j++)
for (auto i = 0; i < img.imsize().x; i++) img[{i, j}].w = alpha[{i, j}].w;
for (auto j = 0; j < img.height(); j++)
for (auto i = 0; i < img.width(); i++) img[{i, j}].w = alpha[{i, j}].w;
}

// set alpha
if (coloralpha_filename != "") {
auto alpha = image<vec4f>{};
if (!load_image(coloralpha_filename, alpha, ioerror)) print_fatal(ioerror);
if (img.imsize() != alpha.imsize()) print_fatal("bad image size");
for (auto j = 0; j < img.imsize().y; j++)
for (auto i = 0; i < img.imsize().x; i++)
for (auto j = 0; j < img.height(); j++)
for (auto i = 0; i < img.width(); i++)
img[{i, j}].w = mean(xyz(alpha[{i, j}]));
}

Expand Down
10 changes: 5 additions & 5 deletions apps/yimageview/yimageview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void compute_stats(
stats.histogram[(int)(clamp(p.y / max_histo, 0.f, 1.f) * 255)].y += 1;
stats.histogram[(int)(clamp(p.z / max_histo, 0.f, 1.f) * 255)].z += 1;
}
auto num_pixels = (size_t)img.imsize().x * (size_t)img.imsize().y;
auto num_pixels = (size_t)img.width() * (size_t)img.height();
for (auto& v : stats.histogram) v /= num_pixels;
stats.average /= num_pixels;
}
Expand Down Expand Up @@ -230,16 +230,16 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
draw_label(win, "filename", app->filename);
draw_label(win, "outname", app->outname);
draw_label(win, "image",
std::to_string(app->source.imsize().x) + " x " +
std::to_string(app->source.imsize().y));
std::to_string(app->source.width()) + " x " +
std::to_string(app->source.height()));
draw_slider(win, "zoom", app->glparams.scale, 0.1, 10);
draw_checkbox(win, "fit", app->glparams.fit);
auto ij = get_image_coords(input.mouse_pos, app->glparams.center,
app->glparams.scale, app->source.imsize());
draw_dragger(win, "mouse", ij);
auto img_pixel = zero4f, display_pixel = zero4f;
if (ij.x >= 0 && ij.x < app->source.imsize().x && ij.y >= 0 &&
ij.y < app->source.imsize().y) {
if (ij.x >= 0 && ij.x < app->source.width() && ij.y >= 0 &&
ij.y < app->source.height()) {
img_pixel = app->source[{ij.x, ij.y}];
display_pixel = app->display[{ij.x, ij.y}];
}
Expand Down
4 changes: 2 additions & 2 deletions apps/yimageviews/yimageviews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ int main(int argc, const char* argv[]) {
app->glparams.scale, app->source.imsize());
draw_dragger(win, "mouse", ij);
auto img_pixel = zero4f, display_pixel = zero4f;
if (ij.x >= 0 && ij.x < app->source.imsize().x && ij.y >= 0 &&
ij.y < app->source.imsize().y) {
if (ij.x >= 0 && ij.x < app->source.width() && ij.y >= 0 &&
ij.y < app->source.height()) {
img_pixel = app->source[{ij.x, ij.y}];
display_pixel = app->display[{ij.x, ij.y}];
}
Expand Down
24 changes: 12 additions & 12 deletions apps/ysceneitrace/ysceneitrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ bool draw_widgets(
auto edited = 0;
draw_label(win, "name", iotexture->name);
draw_label(win, "hdr",
std::to_string(iotexture->hdr.imsize().x) + " x " +
std::to_string(iotexture->hdr.imsize().y));
std::to_string(iotexture->hdr.width()) + " x " +
std::to_string(iotexture->hdr.height()));
draw_label(win, "ldr",
std::to_string(iotexture->ldr.imsize().x) + " x " +
std::to_string(iotexture->ldr.imsize().y));
std::to_string(iotexture->ldr.width()) + " x " +
std::to_string(iotexture->ldr.height()));
// TODO: load texture
return edited;
}
Expand Down Expand Up @@ -526,8 +526,8 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
draw_label(win, "imagename", app->imagename);
if (app->ok) {
draw_label(win, "image",
std::to_string(app->render.imsize().x) + " x " +
std::to_string(app->render.imsize().y) + " @ " +
std::to_string(app->render.width()) + " x " +
std::to_string(app->render.height()) + " @ " +
std::to_string(app->render_sample));
draw_slider(win, "zoom", app->glparams.scale, 0.1, 10);
draw_checkbox(win, "zoom to fit", app->glparams.fit);
Expand All @@ -544,8 +544,8 @@ void draw_widgets(gui_window* win, app_states* apps, const gui_input& input) {
auto ij = get_image_coords(input.mouse_pos, app->glparams.center,
app->glparams.scale, app->render.imsize());
draw_dragger(win, "mouse", ij);
if (ij.x >= 0 && ij.x < app->render.imsize().x && ij.y >= 0 &&
ij.y < app->render.imsize().y) {
if (ij.x >= 0 && ij.x < app->render.width() && ij.y >= 0 &&
ij.y < app->render.height()) {
draw_coloredit(win, "pixel", app->render[{ij.x, ij.y}]);
} else {
auto zero4f_ = zero4f;
Expand Down Expand Up @@ -806,13 +806,13 @@ int main(int argc, const char* argv[]) {
!input.widgets_active) {
auto ij = get_image_coords(input.mouse_pos, app->glparams.center,
app->glparams.scale, app->render.imsize());
if (ij.x >= 0 && ij.x < app->render.imsize().x && ij.y >= 0 &&
ij.y < app->render.imsize().y) {
if (ij.x >= 0 && ij.x < app->render.width() && ij.y >= 0 &&
ij.y < app->render.height()) {
auto ray = camera_ray(app->camera->frame, app->camera->lens,
app->camera->lens, app->camera->film,
vec2f{ij.x + 0.5f, ij.y + 0.5f} /
vec2f{(float)app->render.imsize().x,
(float)app->render.imsize().y});
vec2f{(float)app->render.width(),
(float)app->render.height()});
if (auto isec = intersect_scene_bvh(app->scene, ray); isec.hit) {
app->selected_instance = app->ioscene->instances[isec.instance];
}
Expand Down
8 changes: 4 additions & 4 deletions apps/ysceneview/ysceneview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ bool draw_widgets(
if (!iotexture) return false;
draw_label(win, "name", iotexture->name);
draw_label(win, "hdr",
std::to_string(iotexture->hdr.imsize().x) + " x " +
std::to_string(iotexture->hdr.imsize().y));
std::to_string(iotexture->hdr.width()) + " x " +
std::to_string(iotexture->hdr.height()));
draw_label(win, "ldr",
std::to_string(iotexture->ldr.imsize().x) + " x " +
std::to_string(iotexture->ldr.imsize().y));
std::to_string(iotexture->ldr.width()) + " x " +
std::to_string(iotexture->ldr.height()));
return false;
}

Expand Down
Loading