From c5d2bcf9d08b8f01140ada92c99fa2f47e2f18ec Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Sat, 9 Jul 2022 14:51:59 -0400 Subject: [PATCH] fix: apply image slice scale after slice window to avoid mask issues MSE draws masks on the slice window and expects the sizes to be equivalent. This was presenting problems with the way I was trying to do internal scale as I was applying the scale upfront as the slice window loads and would need to scale the mask to match. Instead, applying the scale only when the output is generated from the slice window. --- src/gui/image_slice_window.cpp | 11 ++++++----- src/gui/image_slice_window.hpp | 4 ++-- src/gui/value/image.cpp | 13 +++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/gui/image_slice_window.cpp b/src/gui/image_slice_window.cpp index 8e4e4636..a6659fce 100644 --- a/src/gui/image_slice_window.cpp +++ b/src/gui/image_slice_window.cpp @@ -61,12 +61,13 @@ void ImageSlice::centerSelection() { } } -Image ImageSlice::getSlice() const { - if (selection.width == target_size.GetWidth() && selection.height == target_size.GetHeight() && selection.x == 0 && selection.y == 0) { +Image ImageSlice::getSlice(double scale) const { + wxSize scaled_target_size = target_size * scale; + if (selection.width == scaled_target_size.GetWidth() && selection.height == scaled_target_size.GetHeight() && selection.x == 0 && selection.y == 0) { // exactly the right size return source.GetSubImage(selection); } - Image target(target_size.GetWidth(), target_size.GetHeight(), false); + Image target(scaled_target_size.GetWidth(), scaled_target_size.GetHeight(), false); if (sharpen && sharpen_amount > 0 && sharpen_amount <= 100) { sharp_resample_and_clip(source, target, selection, sharpen_amount); } else { @@ -195,8 +196,8 @@ void ImageSliceWindow::onOk(wxCommandEvent&) { EndModal(wxID_OK); } -Image ImageSliceWindow::getImage() const { - return slice.getSlice(); +Image ImageSliceWindow::getImage(double scale) const { + return slice.getSlice(scale); } // ----------------------------------------------------------------------------- : ImageSliceWindow : Controls diff --git a/src/gui/image_slice_window.hpp b/src/gui/image_slice_window.hpp index be505646..de86e16d 100644 --- a/src/gui/image_slice_window.hpp +++ b/src/gui/image_slice_window.hpp @@ -45,7 +45,7 @@ public: /// Attempt to center the current constraints void centerSelection(); /// Get the sliced image - Image getSlice() const; + Image getSlice(double scale = 1.0) const; // Zoom factor inline double zoomX() const { return target_size.GetWidth() / (double)selection.width; } @@ -63,7 +63,7 @@ public: ImageSliceWindow(Window* parent, const Image& source, const wxSize& target_size, const AlphaMask& target_mask); /// Return the sliced image - Image getImage() const; + Image getImage(double scale) const; // --------------------------------------------------- : Data private: diff --git a/src/gui/value/image.cpp b/src/gui/value/image.cpp index 2ba17163..99d9123d 100644 --- a/src/gui/value/image.cpp +++ b/src/gui/value/image.cpp @@ -41,16 +41,17 @@ void ImageValueEditor::sliceImage(const Image& image) { AlphaMask mask; style().mask.getNoCache(options,mask); // slice - // Specify a desired size based on the stylesheet and a scale multiplier defined within the user's settings. - // Storing at a greater than 100% resolution allows for better exports >100%, but may change how images look when filters (sharpen) are applied. - // Additionally, this bloats the set file size as even under-resolution images are upscaled to the new minimum size. - RealSize desired_slice_size = RealSize(style().getSize().width * settings.internal_scale, style().getSize().height * settings.internal_scale); - ImageSliceWindow s(wxGetTopLevelParent(&editor()), image, desired_slice_size, mask); + ImageSliceWindow s(wxGetTopLevelParent(&editor()), image, style().getSize(), mask); // clicked ok? if (s.ShowModal() == wxID_OK) { // store the image into the set LocalFileName new_image_file = getLocalPackage().newFileName(field().name, settings.internal_image_extension ? _(".png") : _("")); // a new unique name in the package - Image img = s.getImage(); + + // Specify a desired size based on the stylesheet and a scale multiplier defined within the user's settings. + // Storing at a greater than 100% resolution allows for better exports >100%, but may change how images look when filters (sharpen) are applied. + // It also disrupts some of the patterns in use for doing popout planeswalkers since you have to do the math at both scales. + // Additionally, this bloats the set file size as even under-resolution images are upscaled to the new minimum size. + Image img = s.getImage(settings.internal_scale); img.SaveFile(getLocalPackage().nameOut(new_image_file), wxBITMAP_TYPE_PNG); // always use PNG images, see #69. Disk space is cheap anyway. addAction(value_action(valueP(), new_image_file)); }