From d510d70b6a156039f49dbb39d2e080ff28103309 Mon Sep 17 00:00:00 2001
From: Jorge Rodriguez <jorge@lunarworkshop.com>
Date: Tue, 9 Sep 2014 16:35:00 -0700
Subject: [PATCH] Report downsample progress by when we empty the ring buffer,
 it's more accurate that way.

---
 stb_image_resize.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/stb_image_resize.h b/stb_image_resize.h
index cc3b697..215a0ab 100644
--- a/stb_image_resize.h
+++ b/stb_image_resize.h
@@ -1500,6 +1500,7 @@ static void stbir__empty_ring_buffer(stbir__info* stbir_info, int first_necessar
 				int output_row_start = stbir_info->ring_buffer_first_scanline * output_stride_bytes;
 				float* ring_buffer_entry = stbir__get_ring_buffer_entry(ring_buffer, stbir_info->ring_buffer_begin_index, ring_buffer_length);
 				stbir__encode_scanline(stbir_info, output_w, (char *) output_data + output_row_start, ring_buffer_entry, channels, alpha_channel, decode);
+				STBIR_PROGRESS_REPORT((float)stbir_info->ring_buffer_first_scanline / output_w);
 			}
 
 			if (stbir_info->ring_buffer_first_scanline == stbir_info->ring_buffer_last_scanline)
@@ -1556,8 +1557,6 @@ static void stbir__buffer_loop_downsample(stbir__info* stbir_info)
 
 		// Now the horizontal buffer is ready to write to all ring buffer rows.
 		stbir__resample_vertical_downsample(stbir_info, y, out_first_scanline, out_last_scanline, out_center_of_in);
-
-		STBIR_PROGRESS_REPORT((float)(y + pixel_margin) / (stbir_info->input_h + pixel_margin * 2));
 	}
 
 	stbir__empty_ring_buffer(stbir_info, stbir_info->output_h);