Skip to content

Commit 289745c

Browse files
committed
Fix scaler not re-applied to final image when preview and final image source (x,y) are identical. Move source (x,y) into image_info.
1 parent b4be64f commit 289745c

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

src/filter_dialog.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ static void dialog_scaled_preview_check_resize(GtkWidget * preview_scaled, gint
497497
void pixel_art_scalers_run(GimpDrawable *drawable, GimpPreview *preview)
498498
{
499499
GimpPixelRgn src_rgn;
500-
gint x, y;
501500
gint original_bpp;
502501
guint scale_factor;
503502
image_info source_image;
@@ -511,19 +510,20 @@ void pixel_art_scalers_run(GimpDrawable *drawable, GimpPreview *preview)
511510

512511
// Get the working image area for either the preview sub-window or the entire image
513512
if (preview) {
514-
gimp_preview_get_position (preview, &x, &y);
513+
gimp_preview_get_position (preview, &source_image.x, &source_image.y);
515514
gimp_preview_get_size (preview, &source_image.width, &source_image.height);
516515
}
517516
else if (! gimp_drawable_mask_intersect (drawable->drawable_id,
518-
&x, &y, &source_image.width, &source_image.height)) {
517+
&source_image.x, &source_image.y,
518+
&source_image.width, &source_image.height)) {
519519
return;
520520
}
521521

522522
// Get bit depth and alpha mask status
523523
source_image.bpp = drawable->bpp;
524524
original_bpp = source_image.bpp;
525525

526-
if (scaled_output_check_reapply_scalers(scaler_mode_get(), x, y)) {
526+
if (scaled_output_check_reapply_scalers(scaler_mode_get(), source_image)) {
527527

528528
// ====== GET THE SOURCE IMAGE ======
529529

@@ -536,14 +536,15 @@ void pixel_art_scalers_run(GimpDrawable *drawable, GimpPreview *preview)
536536
// Initialize source pixel region with drawable
537537
gimp_pixel_rgn_init (&src_rgn,
538538
drawable,
539-
x, y,
539+
source_image.x, source_image.y,
540540
source_image.width, source_image.height,
541541
FALSE, FALSE);
542542

543543
// Copy source image to working buffer
544544
gimp_pixel_rgn_get_rect (&src_rgn,
545545
(guchar *) source_image.p_imagebuf,
546-
x, y, source_image.width, source_image.height);
546+
source_image.x, source_image.y,
547+
source_image.width, source_image.height);
547548

548549
// Add alpha channel byte to source buffer if needed (scalers expect 4BPP RGBA)
549550
if (source_image.bpp == BYTE_SIZE_RGB_3BPP) { // i.e. !has_alpha
@@ -582,7 +583,7 @@ void pixel_art_scalers_run(GimpDrawable *drawable, GimpPreview *preview)
582583
// ====== APPLY THE SCALER ======
583584

584585
// Allocate output buffer for upscaled image
585-
scaled_output_check_reallocate(scale_factor, source_image.width, source_image.height);
586+
scaled_output_check_reallocate(scale_factor, source_image);
586587

587588
// Expects 4BPP RGBA in source_image.p_imagebuf, outputs same to scaled_output->p_imagebuf
588589
scaler_apply(scaler_mode_get(),

src/filter_scalers.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,36 +150,42 @@ void scaled_output_invalidate(void) {
150150
//
151151
// Used to assist with output caching
152152
//
153-
gint scaled_output_check_reapply_scalers(gint scaler_mode_new, gint x_new, gint y_new) {
153+
gint scaled_output_check_reapply_scalers(gint scaler_mode_new, image_info src_image) {
154154

155-
gint result;
155+
gint result;
156+
gint scale_factor_new = scaler_scale_factor_get( scaler_mode_new );
156157

157-
result = ((scaled_output.scaler_mode != scaler_mode_new) ||
158-
(scaled_output.x != x_new) ||
159-
(scaled_output.y != y_new) ||
160-
(scaled_output.valid_image == FALSE));
158+
result = ((scaled_output.scaler_mode != scaler_mode_new) ||
159+
(scaled_output.x != src_image.x) ||
160+
(scaled_output.y != src_image.y) ||
161+
(scaled_output.width != (src_image.width * scale_factor_new)) ||
162+
(scaled_output.height != (src_image.height * scale_factor_new)) ||
163+
(scaled_output.valid_image == FALSE));
161164

162-
scaled_output.x = x_new;
163-
scaled_output.y = y_new;
165+
scaled_output.x = src_image.x;
166+
scaled_output.y = src_image.y;
164167

165-
return (result);
168+
if (result)
169+
scaled_output_invalidate();
170+
171+
return (result);
166172
}
167173

168174

169175
// scaled_output_check_reallocate
170176
//
171177
// Update output buffer size and re-allocate if needed
172178
//
173-
void scaled_output_check_reallocate(gint scale_factor_new, gint width_new, gint height_new)
179+
void scaled_output_check_reallocate(gint scale_factor_new, image_info src_image)
174180
{
175181
if ((scale_factor_new != scaled_output.scale_factor) ||
176-
((width_new * scale_factor_new) != scaled_output.width) ||
177-
((height_new * scale_factor_new) != scaled_output.height) ||
182+
((src_image.width * scale_factor_new) != scaled_output.width) ||
183+
((src_image.height * scale_factor_new) != scaled_output.height) ||
178184
(scaled_output.p_imagebuf == NULL)) {
179185

180186
// Update the buffer size and re-allocate. The x uint32_t is for RGBA buffer size
181-
scaled_output.width = width_new * scale_factor_new;
182-
scaled_output.height = height_new * scale_factor_new;
187+
scaled_output.width = src_image.width * scale_factor_new;
188+
scaled_output.height = src_image.height * scale_factor_new;
183189
scaled_output.scale_factor = scale_factor_new;
184190
scaled_output.size_bytes = scaled_output.width * scaled_output.height * BYTE_SIZE_RGBA_4BPP;
185191

src/filter_scalers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@
126126
void scaler_apply(int, uint32_t *, uint32_t *, int, int);
127127

128128
void scaled_output_invalidate(void);
129-
gint scaled_output_check_reapply_scalers(gint, gint, gint);
130-
void scaled_output_check_reallocate(gint, gint, gint);
129+
gint scaled_output_check_reapply_scalers(gint, image_info);
130+
void scaled_output_check_reallocate(gint, image_info);
131131

132132
void image_info_init(image_info *);
133133

0 commit comments

Comments
 (0)