From fb059fcece709d67c1fe910b04da5fda92a64dca Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Sat, 6 Sep 2014 10:57:21 -0700 Subject: [PATCH] Progress report. --- stb_image_resize.h | 17 +++++++++++++++++ tests/resample_test.cpp | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/stb_image_resize.h b/stb_image_resize.h index 8cab4c9..42077bb 100644 --- a/stb_image_resize.h +++ b/stb_image_resize.h @@ -223,6 +223,19 @@ STBIRDEF int stbir_resize_region( const void *input_pixels , int input_w , int // (s0, t0) & (s1, t1) are the top-left and bottom right corner (uv addressing style: [0, 1]x[0, 1]) of a region of the input image to use. +// Define this if you want a progress report. +// Example: +// void my_progress_report(float progress) +// { +// printf("Progress: %f%%\n", progress*100); +// } +// +// #define STBIR_PROGRESS_REPORT my_progress_report + +#ifndef STBIR_PROGRESS_REPORT +#define STBIR_PROGRESS_REPORT(float_0_to_1) +#endif + // // //// end header file ///////////////////////////////////////////////////// @@ -1447,6 +1460,8 @@ static void stbir__buffer_loop_upsample(stbir__info* stbir_info) // Now all buffers should be ready to write a row of vertical sampling. stbir__resample_vertical_upsample(stbir_info, y, in_first_scanline, in_last_scanline, in_center_of_out); + + STBIR_PROGRESS_REPORT((float)y / stbir_info->output_h); } } @@ -1529,6 +1544,8 @@ 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 + stbir__get_filter_pixel_margin_vertical(stbir_info)) / (max_y + stbir__get_filter_pixel_margin_vertical(stbir_info))); } stbir__empty_ring_buffer(stbir_info, stbir_info->output_h); diff --git a/tests/resample_test.cpp b/tests/resample_test.cpp index ae420f9..738177c 100644 --- a/tests/resample_test.cpp +++ b/tests/resample_test.cpp @@ -46,6 +46,13 @@ void stbir_free(void* context, void* memory) { } +void stbir_progress(float p) +{ + STBIR_ASSERT(p >= 0 && p <= 1); +} + +#define STBIR_PROGRESS_REPORT stbir_progress + #define STB_IMAGE_RESIZE_IMPLEMENTATION #define STB_IMAGE_RESIZE_STATIC #include "stb_image_resize.h"