|
@@ -1,4 +1,4 @@
|
|
-/* stb_image_resize - v0.90 - public domain image resizing
|
|
|
|
|
|
+/* stb_image_resize - v0.94 - public domain image resizing
|
|
by Jorge L Rodriguez (@VinoBS) - 2014
|
|
by Jorge L Rodriguez (@VinoBS) - 2014
|
|
http://github.com/nothings/stb
|
|
http://github.com/nothings/stb
|
|
|
|
|
|
@@ -107,8 +107,8 @@
|
|
industry, it is still uncommon in the videogame/real-time world.
|
|
industry, it is still uncommon in the videogame/real-time world.
|
|
|
|
|
|
If you linearly filter non-premultiplied alpha, strange effects
|
|
If you linearly filter non-premultiplied alpha, strange effects
|
|
- occur. (For example, the average of 1% opaque bright green
|
|
|
|
- and 99% opaque black produces 50% transparent dark green when
|
|
|
|
|
|
+ occur. (For example, the 50/50 average of 99% transparent bright green
|
|
|
|
+ and 1% transparent black produces 50% transparent dark green when
|
|
non-premultiplied, whereas premultiplied it produces 50%
|
|
non-premultiplied, whereas premultiplied it produces 50%
|
|
transparent near-black. The former introduces green energy
|
|
transparent near-black. The former introduces green energy
|
|
that doesn't exist in the source image.)
|
|
that doesn't exist in the source image.)
|
|
@@ -152,16 +152,20 @@
|
|
(For example, graphics hardware does not apply sRGB conversion
|
|
(For example, graphics hardware does not apply sRGB conversion
|
|
to the alpha channel.)
|
|
to the alpha channel.)
|
|
|
|
|
|
- ADDITIONAL CONTRIBUTORS
|
|
|
|
|
|
+ CONTRIBUTORS
|
|
|
|
+ Jorge L Rodriguez: Implementation
|
|
Sean Barrett: API design, optimizations
|
|
Sean Barrett: API design, optimizations
|
|
|
|
+ Aras Pranckevicius: bugfix
|
|
|
|
|
|
REVISIONS
|
|
REVISIONS
|
|
|
|
+ 0.94 (2017-03-18) fixed warnings
|
|
|
|
+ 0.93 (2017-03-03) fixed bug with certain combinations of heights
|
|
|
|
+ 0.92 (2017-01-02) fix integer overflow on large (>2GB) images
|
|
|
|
+ 0.91 (2016-04-02) fix warnings; fix handling of subpixel regions
|
|
0.90 (2014-09-17) first released version
|
|
0.90 (2014-09-17) first released version
|
|
|
|
|
|
LICENSE
|
|
LICENSE
|
|
- This software is in the public domain. Where that dedication is not
|
|
|
|
- recognized, you are granted a perpetual, irrevocable license to copy
|
|
|
|
- and modify this file as you see fit.
|
|
|
|
|
|
+ See end of file for license information.
|
|
|
|
|
|
TODO
|
|
TODO
|
|
Don't decode all of the image data when only processing a partial tile
|
|
Don't decode all of the image data when only processing a partial tile
|
|
@@ -382,15 +386,6 @@ STBIRDEF int stbir_resize_region( const void *input_pixels , int input_w , int
|
|
#define STBIR_ASSERT(x) assert(x)
|
|
#define STBIR_ASSERT(x) assert(x)
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-#ifdef STBIR_DEBUG
|
|
|
|
-#define STBIR__DEBUG_ASSERT STBIR_ASSERT
|
|
|
|
-#else
|
|
|
|
-#define STBIR__DEBUG_ASSERT
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-// If you hit this it means I haven't done it yet.
|
|
|
|
-#define STBIR__UNIMPLEMENTED(x) STBIR_ASSERT(!(x))
|
|
|
|
-
|
|
|
|
// For memset
|
|
// For memset
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
@@ -538,10 +533,11 @@ typedef struct
|
|
int horizontal_num_contributors;
|
|
int horizontal_num_contributors;
|
|
int vertical_num_contributors;
|
|
int vertical_num_contributors;
|
|
|
|
|
|
- int ring_buffer_length_bytes; // The length of an individual entry in the ring buffer. The total number of ring buffers is stbir__get_filter_pixel_width(filter)
|
|
|
|
|
|
+ int ring_buffer_length_bytes; // The length of an individual entry in the ring buffer. The total number of ring buffers is stbir__get_filter_pixel_width(filter)
|
|
|
|
+ int ring_buffer_num_entries; // Total number of entries in the ring buffer.
|
|
int ring_buffer_first_scanline;
|
|
int ring_buffer_first_scanline;
|
|
int ring_buffer_last_scanline;
|
|
int ring_buffer_last_scanline;
|
|
- int ring_buffer_begin_index;
|
|
|
|
|
|
+ int ring_buffer_begin_index; // first_scanline is at this index in the ring buffer
|
|
float* ring_buffer;
|
|
float* ring_buffer;
|
|
|
|
|
|
float* encode_buffer; // A temporary buffer to store floats so we don't lose precision while we do multiply-adds.
|
|
float* encode_buffer; // A temporary buffer to store floats so we don't lose precision while we do multiply-adds.
|
|
@@ -556,16 +552,17 @@ typedef struct
|
|
int encode_buffer_size;
|
|
int encode_buffer_size;
|
|
} stbir__info;
|
|
} stbir__info;
|
|
|
|
|
|
|
|
+
|
|
|
|
+static const float stbir__max_uint8_as_float = 255.0f;
|
|
|
|
+static const float stbir__max_uint16_as_float = 65535.0f;
|
|
|
|
+static const double stbir__max_uint32_as_float = 4294967295.0;
|
|
|
|
+
|
|
|
|
+
|
|
static stbir__inline int stbir__min(int a, int b)
|
|
static stbir__inline int stbir__min(int a, int b)
|
|
{
|
|
{
|
|
return a < b ? a : b;
|
|
return a < b ? a : b;
|
|
}
|
|
}
|
|
|
|
|
|
-static stbir__inline int stbir__max(int a, int b)
|
|
|
|
-{
|
|
|
|
- return a > b ? a : b;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static stbir__inline float stbir__saturate(float x)
|
|
static stbir__inline float stbir__saturate(float x)
|
|
{
|
|
{
|
|
if (x < 0)
|
|
if (x < 0)
|
|
@@ -757,7 +754,7 @@ static float stbir__filter_trapezoid(float x, float scale)
|
|
{
|
|
{
|
|
float halfscale = scale / 2;
|
|
float halfscale = scale / 2;
|
|
float t = 0.5f + halfscale;
|
|
float t = 0.5f + halfscale;
|
|
- STBIR__DEBUG_ASSERT(scale <= 1);
|
|
|
|
|
|
+ STBIR_ASSERT(scale <= 1);
|
|
|
|
|
|
x = (float)fabs(x);
|
|
x = (float)fabs(x);
|
|
|
|
|
|
@@ -775,7 +772,7 @@ static float stbir__filter_trapezoid(float x, float scale)
|
|
|
|
|
|
static float stbir__support_trapezoid(float scale)
|
|
static float stbir__support_trapezoid(float scale)
|
|
{
|
|
{
|
|
- STBIR__DEBUG_ASSERT(scale <= 1);
|
|
|
|
|
|
+ STBIR_ASSERT(scale <= 1);
|
|
return 0.5f + scale / 2;
|
|
return 0.5f + scale / 2;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -989,7 +986,7 @@ static int stbir__edge_wrap_slow(stbir_edge edge, int n, int max)
|
|
return n; // NOTREACHED
|
|
return n; // NOTREACHED
|
|
|
|
|
|
default:
|
|
default:
|
|
- STBIR__UNIMPLEMENTED("Unimplemented edge type");
|
|
|
|
|
|
+ STBIR_ASSERT(!"Unimplemented edge type");
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1032,18 +1029,18 @@ static void stbir__calculate_sample_range_downsample(int n, float in_pixels_radi
|
|
*out_last_pixel = (int)(floor(out_pixel_influence_upperbound - 0.5));
|
|
*out_last_pixel = (int)(floor(out_pixel_influence_upperbound - 0.5));
|
|
}
|
|
}
|
|
|
|
|
|
-static void stbir__calculate_coefficients_upsample(stbir__info* stbir_info, stbir_filter filter, float scale, int in_first_pixel, int in_last_pixel, float in_center_of_out, stbir__contributors* contributor, float* coefficient_group)
|
|
|
|
|
|
+static void stbir__calculate_coefficients_upsample(stbir_filter filter, float scale, int in_first_pixel, int in_last_pixel, float in_center_of_out, stbir__contributors* contributor, float* coefficient_group)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
float total_filter = 0;
|
|
float total_filter = 0;
|
|
float filter_scale;
|
|
float filter_scale;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(in_last_pixel - in_first_pixel <= (int)ceil(stbir__filter_info_table[filter].support(1/scale) * 2)); // Taken directly from stbir__get_coefficient_width() which we can't call because we don't know if we're horizontal or vertical.
|
|
|
|
|
|
+ STBIR_ASSERT(in_last_pixel - in_first_pixel <= (int)ceil(stbir__filter_info_table[filter].support(1/scale) * 2)); // Taken directly from stbir__get_coefficient_width() which we can't call because we don't know if we're horizontal or vertical.
|
|
|
|
|
|
contributor->n0 = in_first_pixel;
|
|
contributor->n0 = in_first_pixel;
|
|
contributor->n1 = in_last_pixel;
|
|
contributor->n1 = in_last_pixel;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(contributor->n1 >= contributor->n0);
|
|
|
|
|
|
+ STBIR_ASSERT(contributor->n1 >= contributor->n0);
|
|
|
|
|
|
for (i = 0; i <= in_last_pixel - in_first_pixel; i++)
|
|
for (i = 0; i <= in_last_pixel - in_first_pixel; i++)
|
|
{
|
|
{
|
|
@@ -1061,10 +1058,10 @@ static void stbir__calculate_coefficients_upsample(stbir__info* stbir_info, stbi
|
|
total_filter += coefficient_group[i];
|
|
total_filter += coefficient_group[i];
|
|
}
|
|
}
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(stbir__filter_info_table[filter].kernel((float)(in_last_pixel + 1) + 0.5f - in_center_of_out, 1/scale) == 0);
|
|
|
|
|
|
+ STBIR_ASSERT(stbir__filter_info_table[filter].kernel((float)(in_last_pixel + 1) + 0.5f - in_center_of_out, 1/scale) == 0);
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(total_filter > 0.9);
|
|
|
|
- STBIR__DEBUG_ASSERT(total_filter < 1.1f); // Make sure it's not way off.
|
|
|
|
|
|
+ STBIR_ASSERT(total_filter > 0.9);
|
|
|
|
+ STBIR_ASSERT(total_filter < 1.1f); // Make sure it's not way off.
|
|
|
|
|
|
// Make sure the sum of all coefficients is 1.
|
|
// Make sure the sum of all coefficients is 1.
|
|
filter_scale = 1 / total_filter;
|
|
filter_scale = 1 / total_filter;
|
|
@@ -1082,16 +1079,16 @@ static void stbir__calculate_coefficients_upsample(stbir__info* stbir_info, stbi
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static void stbir__calculate_coefficients_downsample(stbir__info* stbir_info, stbir_filter filter, float scale_ratio, int out_first_pixel, int out_last_pixel, float out_center_of_in, stbir__contributors* contributor, float* coefficient_group)
|
|
|
|
|
|
+static void stbir__calculate_coefficients_downsample(stbir_filter filter, float scale_ratio, int out_first_pixel, int out_last_pixel, float out_center_of_in, stbir__contributors* contributor, float* coefficient_group)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(out_last_pixel - out_first_pixel <= (int)ceil(stbir__filter_info_table[filter].support(scale_ratio) * 2)); // Taken directly from stbir__get_coefficient_width() which we can't call because we don't know if we're horizontal or vertical.
|
|
|
|
|
|
+ STBIR_ASSERT(out_last_pixel - out_first_pixel <= (int)ceil(stbir__filter_info_table[filter].support(scale_ratio) * 2)); // Taken directly from stbir__get_coefficient_width() which we can't call because we don't know if we're horizontal or vertical.
|
|
|
|
|
|
contributor->n0 = out_first_pixel;
|
|
contributor->n0 = out_first_pixel;
|
|
contributor->n1 = out_last_pixel;
|
|
contributor->n1 = out_last_pixel;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(contributor->n1 >= contributor->n0);
|
|
|
|
|
|
+ STBIR_ASSERT(contributor->n1 >= contributor->n0);
|
|
|
|
|
|
for (i = 0; i <= out_last_pixel - out_first_pixel; i++)
|
|
for (i = 0; i <= out_last_pixel - out_first_pixel; i++)
|
|
{
|
|
{
|
|
@@ -1100,7 +1097,7 @@ static void stbir__calculate_coefficients_downsample(stbir__info* stbir_info, st
|
|
coefficient_group[i] = stbir__filter_info_table[filter].kernel(x, scale_ratio) * scale_ratio;
|
|
coefficient_group[i] = stbir__filter_info_table[filter].kernel(x, scale_ratio) * scale_ratio;
|
|
}
|
|
}
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(stbir__filter_info_table[filter].kernel((float)(out_last_pixel + 1) + 0.5f - out_center_of_in, scale_ratio) == 0);
|
|
|
|
|
|
+ STBIR_ASSERT(stbir__filter_info_table[filter].kernel((float)(out_last_pixel + 1) + 0.5f - out_center_of_in, scale_ratio) == 0);
|
|
|
|
|
|
for (i = out_last_pixel - out_first_pixel; i >= 0; i--)
|
|
for (i = out_last_pixel - out_first_pixel; i >= 0; i--)
|
|
{
|
|
{
|
|
@@ -1112,7 +1109,7 @@ static void stbir__calculate_coefficients_downsample(stbir__info* stbir_info, st
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static void stbir__normalize_downsample_coefficients(stbir__info* stbir_info, stbir__contributors* contributors, float* coefficients, stbir_filter filter, float scale_ratio, float shift, int input_size, int output_size)
|
|
|
|
|
|
+static void stbir__normalize_downsample_coefficients(stbir__contributors* contributors, float* coefficients, stbir_filter filter, float scale_ratio, int input_size, int output_size)
|
|
{
|
|
{
|
|
int num_contributors = stbir__get_contributors(scale_ratio, filter, input_size, output_size);
|
|
int num_contributors = stbir__get_contributors(scale_ratio, filter, input_size, output_size);
|
|
int num_coefficients = stbir__get_coefficient_width(filter, scale_ratio);
|
|
int num_coefficients = stbir__get_coefficient_width(filter, scale_ratio);
|
|
@@ -1135,8 +1132,8 @@ static void stbir__normalize_downsample_coefficients(stbir__info* stbir_info, st
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(total > 0.9f);
|
|
|
|
- STBIR__DEBUG_ASSERT(total < 1.1f);
|
|
|
|
|
|
+ STBIR_ASSERT(total > 0.9f);
|
|
|
|
+ STBIR_ASSERT(total < 1.1f);
|
|
|
|
|
|
scale = 1 / total;
|
|
scale = 1 / total;
|
|
|
|
|
|
@@ -1189,7 +1186,7 @@ static void stbir__normalize_downsample_coefficients(stbir__info* stbir_info, st
|
|
|
|
|
|
// Each scan line uses the same kernel values so we should calculate the kernel
|
|
// Each scan line uses the same kernel values so we should calculate the kernel
|
|
// values once and then we can use them for every scan line.
|
|
// values once and then we can use them for every scan line.
|
|
-static void stbir__calculate_filters(stbir__info* stbir_info, stbir__contributors* contributors, float* coefficients, stbir_filter filter, float scale_ratio, float shift, int input_size, int output_size)
|
|
|
|
|
|
+static void stbir__calculate_filters(stbir__contributors* contributors, float* coefficients, stbir_filter filter, float scale_ratio, float shift, int input_size, int output_size)
|
|
{
|
|
{
|
|
int n;
|
|
int n;
|
|
int total_contributors = stbir__get_contributors(scale_ratio, filter, input_size, output_size);
|
|
int total_contributors = stbir__get_contributors(scale_ratio, filter, input_size, output_size);
|
|
@@ -1206,7 +1203,7 @@ static void stbir__calculate_filters(stbir__info* stbir_info, stbir__contributor
|
|
|
|
|
|
stbir__calculate_sample_range_upsample(n, out_pixels_radius, scale_ratio, shift, &in_first_pixel, &in_last_pixel, &in_center_of_out);
|
|
stbir__calculate_sample_range_upsample(n, out_pixels_radius, scale_ratio, shift, &in_first_pixel, &in_last_pixel, &in_center_of_out);
|
|
|
|
|
|
- stbir__calculate_coefficients_upsample(stbir_info, filter, scale_ratio, in_first_pixel, in_last_pixel, in_center_of_out, stbir__get_contributor(contributors, n), stbir__get_coefficient(coefficients, filter, scale_ratio, n, 0));
|
|
|
|
|
|
+ stbir__calculate_coefficients_upsample(filter, scale_ratio, in_first_pixel, in_last_pixel, in_center_of_out, stbir__get_contributor(contributors, n), stbir__get_coefficient(coefficients, filter, scale_ratio, n, 0));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -1222,10 +1219,10 @@ static void stbir__calculate_filters(stbir__info* stbir_info, stbir__contributor
|
|
|
|
|
|
stbir__calculate_sample_range_downsample(n_adjusted, in_pixels_radius, scale_ratio, shift, &out_first_pixel, &out_last_pixel, &out_center_of_in);
|
|
stbir__calculate_sample_range_downsample(n_adjusted, in_pixels_radius, scale_ratio, shift, &out_first_pixel, &out_last_pixel, &out_center_of_in);
|
|
|
|
|
|
- stbir__calculate_coefficients_downsample(stbir_info, filter, scale_ratio, out_first_pixel, out_last_pixel, out_center_of_in, stbir__get_contributor(contributors, n), stbir__get_coefficient(coefficients, filter, scale_ratio, n, 0));
|
|
|
|
|
|
+ stbir__calculate_coefficients_downsample(filter, scale_ratio, out_first_pixel, out_last_pixel, out_center_of_in, stbir__get_contributor(contributors, n), stbir__get_coefficient(coefficients, filter, scale_ratio, n, 0));
|
|
}
|
|
}
|
|
|
|
|
|
- stbir__normalize_downsample_coefficients(stbir_info, contributors, coefficients, filter, scale_ratio, shift, input_size, output_size);
|
|
|
|
|
|
+ stbir__normalize_downsample_coefficients(contributors, coefficients, filter, scale_ratio, input_size, output_size);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1246,11 +1243,11 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
|
int type = stbir_info->type;
|
|
int type = stbir_info->type;
|
|
int colorspace = stbir_info->colorspace;
|
|
int colorspace = stbir_info->colorspace;
|
|
int input_w = stbir_info->input_w;
|
|
int input_w = stbir_info->input_w;
|
|
- int input_stride_bytes = stbir_info->input_stride_bytes;
|
|
|
|
|
|
+ size_t input_stride_bytes = stbir_info->input_stride_bytes;
|
|
float* decode_buffer = stbir__get_decode_buffer(stbir_info);
|
|
float* decode_buffer = stbir__get_decode_buffer(stbir_info);
|
|
stbir_edge edge_horizontal = stbir_info->edge_horizontal;
|
|
stbir_edge edge_horizontal = stbir_info->edge_horizontal;
|
|
stbir_edge edge_vertical = stbir_info->edge_vertical;
|
|
stbir_edge edge_vertical = stbir_info->edge_vertical;
|
|
- int in_buffer_row_offset = stbir__edge_wrap(edge_vertical, n, stbir_info->input_h) * input_stride_bytes;
|
|
|
|
|
|
+ size_t in_buffer_row_offset = stbir__edge_wrap(edge_vertical, n, stbir_info->input_h) * input_stride_bytes;
|
|
const void* input_data = (char *) stbir_info->input_data + in_buffer_row_offset;
|
|
const void* input_data = (char *) stbir_info->input_data + in_buffer_row_offset;
|
|
int max_x = input_w + stbir_info->horizontal_filter_pixel_margin;
|
|
int max_x = input_w + stbir_info->horizontal_filter_pixel_margin;
|
|
int decode = STBIR__DECODE(type, colorspace);
|
|
int decode = STBIR__DECODE(type, colorspace);
|
|
@@ -1275,7 +1272,7 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
|
int decode_pixel_index = x * channels;
|
|
int decode_pixel_index = x * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
for (c = 0; c < channels; c++)
|
|
for (c = 0; c < channels; c++)
|
|
- decode_buffer[decode_pixel_index + c] = ((float)((const unsigned char*)input_data)[input_pixel_index + c]) / 255;
|
|
|
|
|
|
+ decode_buffer[decode_pixel_index + c] = ((float)((const unsigned char*)input_data)[input_pixel_index + c]) / stbir__max_uint8_as_float;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -1288,7 +1285,7 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
|
decode_buffer[decode_pixel_index + c] = stbir__srgb_uchar_to_linear_float[((const unsigned char*)input_data)[input_pixel_index + c]];
|
|
decode_buffer[decode_pixel_index + c] = stbir__srgb_uchar_to_linear_float[((const unsigned char*)input_data)[input_pixel_index + c]];
|
|
|
|
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
- decode_buffer[decode_pixel_index + alpha_channel] = ((float)((const unsigned char*)input_data)[input_pixel_index + alpha_channel]) / 255;
|
|
|
|
|
|
+ decode_buffer[decode_pixel_index + alpha_channel] = ((float)((const unsigned char*)input_data)[input_pixel_index + alpha_channel]) / stbir__max_uint8_as_float;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -1298,7 +1295,7 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
|
int decode_pixel_index = x * channels;
|
|
int decode_pixel_index = x * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
for (c = 0; c < channels; c++)
|
|
for (c = 0; c < channels; c++)
|
|
- decode_buffer[decode_pixel_index + c] = ((float)((const unsigned short*)input_data)[input_pixel_index + c]) / 65535;
|
|
|
|
|
|
+ decode_buffer[decode_pixel_index + c] = ((float)((const unsigned short*)input_data)[input_pixel_index + c]) / stbir__max_uint16_as_float;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -1308,10 +1305,10 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
|
int decode_pixel_index = x * channels;
|
|
int decode_pixel_index = x * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
for (c = 0; c < channels; c++)
|
|
for (c = 0; c < channels; c++)
|
|
- decode_buffer[decode_pixel_index + c] = stbir__srgb_to_linear(((float)((const unsigned short*)input_data)[input_pixel_index + c]) / 65535);
|
|
|
|
|
|
+ decode_buffer[decode_pixel_index + c] = stbir__srgb_to_linear(((float)((const unsigned short*)input_data)[input_pixel_index + c]) / stbir__max_uint16_as_float);
|
|
|
|
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
- decode_buffer[decode_pixel_index + alpha_channel] = ((float)((const unsigned short*)input_data)[input_pixel_index + alpha_channel]) / 65535;
|
|
|
|
|
|
+ decode_buffer[decode_pixel_index + alpha_channel] = ((float)((const unsigned short*)input_data)[input_pixel_index + alpha_channel]) / stbir__max_uint16_as_float;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -1321,7 +1318,7 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
|
int decode_pixel_index = x * channels;
|
|
int decode_pixel_index = x * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
for (c = 0; c < channels; c++)
|
|
for (c = 0; c < channels; c++)
|
|
- decode_buffer[decode_pixel_index + c] = (float)(((double)((const unsigned int*)input_data)[input_pixel_index + c]) / 4294967295);
|
|
|
|
|
|
+ decode_buffer[decode_pixel_index + c] = (float)(((double)((const unsigned int*)input_data)[input_pixel_index + c]) / stbir__max_uint32_as_float);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -1331,10 +1328,10 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
|
int decode_pixel_index = x * channels;
|
|
int decode_pixel_index = x * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels;
|
|
for (c = 0; c < channels; c++)
|
|
for (c = 0; c < channels; c++)
|
|
- decode_buffer[decode_pixel_index + c] = stbir__srgb_to_linear((float)(((double)((const unsigned int*)input_data)[input_pixel_index + c]) / 4294967295));
|
|
|
|
|
|
+ decode_buffer[decode_pixel_index + c] = stbir__srgb_to_linear((float)(((double)((const unsigned int*)input_data)[input_pixel_index + c]) / stbir__max_uint32_as_float));
|
|
|
|
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
- decode_buffer[decode_pixel_index + alpha_channel] = (float)(((double)((const unsigned int*)input_data)[input_pixel_index + alpha_channel]) / 4294967295);
|
|
|
|
|
|
+ decode_buffer[decode_pixel_index + alpha_channel] = (float)(((double)((const unsigned int*)input_data)[input_pixel_index + alpha_channel]) / stbir__max_uint32_as_float);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -1363,7 +1360,7 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
|
break;
|
|
break;
|
|
|
|
|
|
default:
|
|
default:
|
|
- STBIR__UNIMPLEMENTED("Unknown type/colorspace/channels combination.");
|
|
|
|
|
|
+ STBIR_ASSERT(!"Unknown type/colorspace/channels combination.");
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1416,6 +1413,8 @@ static float* stbir__add_empty_ring_buffer_entry(stbir__info* stbir_info, int n)
|
|
int ring_buffer_index;
|
|
int ring_buffer_index;
|
|
float* ring_buffer;
|
|
float* ring_buffer;
|
|
|
|
|
|
|
|
+ stbir_info->ring_buffer_last_scanline = n;
|
|
|
|
+
|
|
if (stbir_info->ring_buffer_begin_index < 0)
|
|
if (stbir_info->ring_buffer_begin_index < 0)
|
|
{
|
|
{
|
|
ring_buffer_index = stbir_info->ring_buffer_begin_index = 0;
|
|
ring_buffer_index = stbir_info->ring_buffer_begin_index = 0;
|
|
@@ -1423,24 +1422,21 @@ static float* stbir__add_empty_ring_buffer_entry(stbir__info* stbir_info, int n)
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- ring_buffer_index = (stbir_info->ring_buffer_begin_index + (stbir_info->ring_buffer_last_scanline - stbir_info->ring_buffer_first_scanline) + 1) % stbir_info->vertical_filter_pixel_width;
|
|
|
|
- STBIR__DEBUG_ASSERT(ring_buffer_index != stbir_info->ring_buffer_begin_index);
|
|
|
|
|
|
+ ring_buffer_index = (stbir_info->ring_buffer_begin_index + (stbir_info->ring_buffer_last_scanline - stbir_info->ring_buffer_first_scanline)) % stbir_info->ring_buffer_num_entries;
|
|
|
|
+ STBIR_ASSERT(ring_buffer_index != stbir_info->ring_buffer_begin_index);
|
|
}
|
|
}
|
|
|
|
|
|
ring_buffer = stbir__get_ring_buffer_entry(stbir_info->ring_buffer, ring_buffer_index, stbir_info->ring_buffer_length_bytes / sizeof(float));
|
|
ring_buffer = stbir__get_ring_buffer_entry(stbir_info->ring_buffer, ring_buffer_index, stbir_info->ring_buffer_length_bytes / sizeof(float));
|
|
memset(ring_buffer, 0, stbir_info->ring_buffer_length_bytes);
|
|
memset(ring_buffer, 0, stbir_info->ring_buffer_length_bytes);
|
|
|
|
|
|
- stbir_info->ring_buffer_last_scanline = n;
|
|
|
|
-
|
|
|
|
return ring_buffer;
|
|
return ring_buffer;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, int n, float* output_buffer)
|
|
|
|
|
|
+static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, float* output_buffer)
|
|
{
|
|
{
|
|
int x, k;
|
|
int x, k;
|
|
int output_w = stbir_info->output_w;
|
|
int output_w = stbir_info->output_w;
|
|
- int kernel_pixel_width = stbir_info->horizontal_filter_pixel_width;
|
|
|
|
int channels = stbir_info->channels;
|
|
int channels = stbir_info->channels;
|
|
float* decode_buffer = stbir__get_decode_buffer(stbir_info);
|
|
float* decode_buffer = stbir__get_decode_buffer(stbir_info);
|
|
stbir__contributors* horizontal_contributors = stbir_info->horizontal_contributors;
|
|
stbir__contributors* horizontal_contributors = stbir_info->horizontal_contributors;
|
|
@@ -1456,11 +1452,11 @@ static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, int n,
|
|
int coefficient_group = coefficient_width * x;
|
|
int coefficient_group = coefficient_width * x;
|
|
int coefficient_counter = 0;
|
|
int coefficient_counter = 0;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(n1 >= n0);
|
|
|
|
- STBIR__DEBUG_ASSERT(n0 >= -stbir_info->horizontal_filter_pixel_margin);
|
|
|
|
- STBIR__DEBUG_ASSERT(n1 >= -stbir_info->horizontal_filter_pixel_margin);
|
|
|
|
- STBIR__DEBUG_ASSERT(n0 < stbir_info->input_w + stbir_info->horizontal_filter_pixel_margin);
|
|
|
|
- STBIR__DEBUG_ASSERT(n1 < stbir_info->input_w + stbir_info->horizontal_filter_pixel_margin);
|
|
|
|
|
|
+ STBIR_ASSERT(n1 >= n0);
|
|
|
|
+ STBIR_ASSERT(n0 >= -stbir_info->horizontal_filter_pixel_margin);
|
|
|
|
+ STBIR_ASSERT(n1 >= -stbir_info->horizontal_filter_pixel_margin);
|
|
|
|
+ STBIR_ASSERT(n0 < stbir_info->input_w + stbir_info->horizontal_filter_pixel_margin);
|
|
|
|
+ STBIR_ASSERT(n1 < stbir_info->input_w + stbir_info->horizontal_filter_pixel_margin);
|
|
|
|
|
|
switch (channels) {
|
|
switch (channels) {
|
|
case 1:
|
|
case 1:
|
|
@@ -1468,7 +1464,7 @@ static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, int n,
|
|
{
|
|
{
|
|
int in_pixel_index = k * 1;
|
|
int in_pixel_index = k * 1;
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
@@ -1477,7 +1473,7 @@ static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, int n,
|
|
{
|
|
{
|
|
int in_pixel_index = k * 2;
|
|
int in_pixel_index = k * 2;
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
}
|
|
}
|
|
@@ -1487,7 +1483,7 @@ static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, int n,
|
|
{
|
|
{
|
|
int in_pixel_index = k * 3;
|
|
int in_pixel_index = k * 3;
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
|
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
|
@@ -1498,7 +1494,7 @@ static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, int n,
|
|
{
|
|
{
|
|
int in_pixel_index = k * 4;
|
|
int in_pixel_index = k * 4;
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
|
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
|
@@ -1511,7 +1507,7 @@ static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, int n,
|
|
int in_pixel_index = k * channels;
|
|
int in_pixel_index = k * channels;
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++];
|
|
int c;
|
|
int c;
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
for (c = 0; c < channels; c++)
|
|
for (c = 0; c < channels; c++)
|
|
output_buffer[out_pixel_index + c] += decode_buffer[in_pixel_index + c] * coefficient;
|
|
output_buffer[out_pixel_index + c] += decode_buffer[in_pixel_index + c] * coefficient;
|
|
}
|
|
}
|
|
@@ -1520,12 +1516,10 @@ static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, int n,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, int n, float* output_buffer)
|
|
|
|
|
|
+static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, float* output_buffer)
|
|
{
|
|
{
|
|
int x, k;
|
|
int x, k;
|
|
int input_w = stbir_info->input_w;
|
|
int input_w = stbir_info->input_w;
|
|
- int output_w = stbir_info->output_w;
|
|
|
|
- int kernel_pixel_width = stbir_info->horizontal_filter_pixel_width;
|
|
|
|
int channels = stbir_info->channels;
|
|
int channels = stbir_info->channels;
|
|
float* decode_buffer = stbir__get_decode_buffer(stbir_info);
|
|
float* decode_buffer = stbir__get_decode_buffer(stbir_info);
|
|
stbir__contributors* horizontal_contributors = stbir_info->horizontal_contributors;
|
|
stbir__contributors* horizontal_contributors = stbir_info->horizontal_contributors;
|
|
@@ -1534,7 +1528,7 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, int n
|
|
int filter_pixel_margin = stbir_info->horizontal_filter_pixel_margin;
|
|
int filter_pixel_margin = stbir_info->horizontal_filter_pixel_margin;
|
|
int max_x = input_w + filter_pixel_margin * 2;
|
|
int max_x = input_w + filter_pixel_margin * 2;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(!stbir__use_width_upsampling(stbir_info));
|
|
|
|
|
|
+ STBIR_ASSERT(!stbir__use_width_upsampling(stbir_info));
|
|
|
|
|
|
switch (channels) {
|
|
switch (channels) {
|
|
case 1:
|
|
case 1:
|
|
@@ -1552,7 +1546,7 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, int n
|
|
{
|
|
{
|
|
int out_pixel_index = k * 1;
|
|
int out_pixel_index = k * 1;
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1573,7 +1567,7 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, int n
|
|
{
|
|
{
|
|
int out_pixel_index = k * 2;
|
|
int out_pixel_index = k * 2;
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
}
|
|
}
|
|
@@ -1595,7 +1589,7 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, int n
|
|
{
|
|
{
|
|
int out_pixel_index = k * 3;
|
|
int out_pixel_index = k * 3;
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
|
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
|
@@ -1618,7 +1612,7 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, int n
|
|
{
|
|
{
|
|
int out_pixel_index = k * 4;
|
|
int out_pixel_index = k * 4;
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
|
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
|
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
|
@@ -1643,7 +1637,7 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, int n
|
|
int c;
|
|
int c;
|
|
int out_pixel_index = k * channels;
|
|
int out_pixel_index = k * channels;
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
|
- STBIR__DEBUG_ASSERT(coefficient != 0);
|
|
|
|
|
|
+ STBIR_ASSERT(coefficient != 0);
|
|
for (c = 0; c < channels; c++)
|
|
for (c = 0; c < channels; c++)
|
|
output_buffer[out_pixel_index + c] += decode_buffer[in_pixel_index + c] * coefficient;
|
|
output_buffer[out_pixel_index + c] += decode_buffer[in_pixel_index + c] * coefficient;
|
|
}
|
|
}
|
|
@@ -1659,9 +1653,9 @@ static void stbir__decode_and_resample_upsample(stbir__info* stbir_info, int n)
|
|
|
|
|
|
// Now resample it into the ring buffer.
|
|
// Now resample it into the ring buffer.
|
|
if (stbir__use_width_upsampling(stbir_info))
|
|
if (stbir__use_width_upsampling(stbir_info))
|
|
- stbir__resample_horizontal_upsample(stbir_info, n, stbir__add_empty_ring_buffer_entry(stbir_info, n));
|
|
|
|
|
|
+ stbir__resample_horizontal_upsample(stbir_info, stbir__add_empty_ring_buffer_entry(stbir_info, n));
|
|
else
|
|
else
|
|
- stbir__resample_horizontal_downsample(stbir_info, n, stbir__add_empty_ring_buffer_entry(stbir_info, n));
|
|
|
|
|
|
+ stbir__resample_horizontal_downsample(stbir_info, stbir__add_empty_ring_buffer_entry(stbir_info, n));
|
|
|
|
|
|
// Now it's sitting in the ring buffer ready to be used as source for the vertical sampling.
|
|
// Now it's sitting in the ring buffer ready to be used as source for the vertical sampling.
|
|
}
|
|
}
|
|
@@ -1675,17 +1669,17 @@ static void stbir__decode_and_resample_downsample(stbir__info* stbir_info, int n
|
|
|
|
|
|
// Now resample it into the horizontal buffer.
|
|
// Now resample it into the horizontal buffer.
|
|
if (stbir__use_width_upsampling(stbir_info))
|
|
if (stbir__use_width_upsampling(stbir_info))
|
|
- stbir__resample_horizontal_upsample(stbir_info, n, stbir_info->horizontal_buffer);
|
|
|
|
|
|
+ stbir__resample_horizontal_upsample(stbir_info, stbir_info->horizontal_buffer);
|
|
else
|
|
else
|
|
- stbir__resample_horizontal_downsample(stbir_info, n, stbir_info->horizontal_buffer);
|
|
|
|
|
|
+ stbir__resample_horizontal_downsample(stbir_info, stbir_info->horizontal_buffer);
|
|
|
|
|
|
// Now it's sitting in the horizontal buffer ready to be distributed into the ring buffers.
|
|
// Now it's sitting in the horizontal buffer ready to be distributed into the ring buffers.
|
|
}
|
|
}
|
|
|
|
|
|
// Get the specified scan line from the ring buffer.
|
|
// Get the specified scan line from the ring buffer.
|
|
-static float* stbir__get_ring_buffer_scanline(int get_scanline, float* ring_buffer, int begin_index, int first_scanline, int ring_buffer_size, int ring_buffer_length)
|
|
|
|
|
|
+static float* stbir__get_ring_buffer_scanline(int get_scanline, float* ring_buffer, int begin_index, int first_scanline, int ring_buffer_num_entries, int ring_buffer_length)
|
|
{
|
|
{
|
|
- int ring_buffer_index = (begin_index + (get_scanline - first_scanline)) % ring_buffer_size;
|
|
|
|
|
|
+ int ring_buffer_index = (begin_index + (get_scanline - first_scanline)) % ring_buffer_num_entries;
|
|
return stbir__get_ring_buffer_entry(ring_buffer, ring_buffer_index, ring_buffer_length);
|
|
return stbir__get_ring_buffer_entry(ring_buffer, ring_buffer_index, ring_buffer_length);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1720,19 +1714,23 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void
|
|
|
|
|
|
// build a table of all channels that need colorspace correction, so
|
|
// build a table of all channels that need colorspace correction, so
|
|
// we don't perform colorspace correction on channels that don't need it.
|
|
// we don't perform colorspace correction on channels that don't need it.
|
|
- for (x=0, num_nonalpha=0; x < channels; ++x)
|
|
|
|
|
|
+ for (x = 0, num_nonalpha = 0; x < channels; ++x)
|
|
|
|
+ {
|
|
if (x != alpha_channel || (stbir_info->flags & STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
if (x != alpha_channel || (stbir_info->flags & STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
- nonalpha[num_nonalpha++] = x;
|
|
|
|
|
|
+ {
|
|
|
|
+ nonalpha[num_nonalpha++] = (stbir_uint16)x;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
#define STBIR__ROUND_INT(f) ((int) ((f)+0.5))
|
|
#define STBIR__ROUND_INT(f) ((int) ((f)+0.5))
|
|
#define STBIR__ROUND_UINT(f) ((stbir_uint32) ((f)+0.5))
|
|
#define STBIR__ROUND_UINT(f) ((stbir_uint32) ((f)+0.5))
|
|
|
|
|
|
#ifdef STBIR__SATURATE_INT
|
|
#ifdef STBIR__SATURATE_INT
|
|
- #define STBIR__ENCODE_LINEAR8(f) stbir__saturate8 (STBIR__ROUND_INT((f) * 255 ))
|
|
|
|
- #define STBIR__ENCODE_LINEAR16(f) stbir__saturate16(STBIR__ROUND_INT((f) * 65535))
|
|
|
|
|
|
+ #define STBIR__ENCODE_LINEAR8(f) stbir__saturate8 (STBIR__ROUND_INT((f) * stbir__max_uint8_as_float ))
|
|
|
|
+ #define STBIR__ENCODE_LINEAR16(f) stbir__saturate16(STBIR__ROUND_INT((f) * stbir__max_uint16_as_float))
|
|
#else
|
|
#else
|
|
- #define STBIR__ENCODE_LINEAR8(f) (unsigned char ) STBIR__ROUND_INT(stbir__saturate(f) * 255 )
|
|
|
|
- #define STBIR__ENCODE_LINEAR16(f) (unsigned short) STBIR__ROUND_INT(stbir__saturate(f) * 65535)
|
|
|
|
|
|
+ #define STBIR__ENCODE_LINEAR8(f) (unsigned char ) STBIR__ROUND_INT(stbir__saturate(f) * stbir__max_uint8_as_float )
|
|
|
|
+ #define STBIR__ENCODE_LINEAR16(f) (unsigned short) STBIR__ROUND_INT(stbir__saturate(f) * stbir__max_uint16_as_float)
|
|
#endif
|
|
#endif
|
|
|
|
|
|
switch (decode)
|
|
switch (decode)
|
|
@@ -1787,7 +1785,7 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void
|
|
for (n = 0; n < num_nonalpha; n++)
|
|
for (n = 0; n < num_nonalpha; n++)
|
|
{
|
|
{
|
|
int index = pixel_index + nonalpha[n];
|
|
int index = pixel_index + nonalpha[n];
|
|
- ((unsigned short*)output_buffer)[index] = (unsigned short)STBIR__ROUND_INT(stbir__linear_to_srgb(stbir__saturate(encode_buffer[index])) * 65535);
|
|
|
|
|
|
+ ((unsigned short*)output_buffer)[index] = (unsigned short)STBIR__ROUND_INT(stbir__linear_to_srgb(stbir__saturate(encode_buffer[index])) * stbir__max_uint16_as_float);
|
|
}
|
|
}
|
|
|
|
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
@@ -1804,7 +1802,7 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void
|
|
for (n = 0; n < channels; n++)
|
|
for (n = 0; n < channels; n++)
|
|
{
|
|
{
|
|
int index = pixel_index + n;
|
|
int index = pixel_index + n;
|
|
- ((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_UINT(((double)stbir__saturate(encode_buffer[index])) * 4294967295);
|
|
|
|
|
|
+ ((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_UINT(((double)stbir__saturate(encode_buffer[index])) * stbir__max_uint32_as_float);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
@@ -1817,11 +1815,11 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void
|
|
for (n = 0; n < num_nonalpha; n++)
|
|
for (n = 0; n < num_nonalpha; n++)
|
|
{
|
|
{
|
|
int index = pixel_index + nonalpha[n];
|
|
int index = pixel_index + nonalpha[n];
|
|
- ((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_UINT(((double)stbir__linear_to_srgb(stbir__saturate(encode_buffer[index]))) * 4294967295);
|
|
|
|
|
|
+ ((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_UINT(((double)stbir__linear_to_srgb(stbir__saturate(encode_buffer[index]))) * stbir__max_uint32_as_float);
|
|
}
|
|
}
|
|
|
|
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
|
|
- ((unsigned int*)output_buffer)[pixel_index + alpha_channel] = (unsigned int)STBIR__ROUND_INT(((double)stbir__saturate(encode_buffer[pixel_index + alpha_channel])) * 4294967295);
|
|
|
|
|
|
+ ((unsigned int*)output_buffer)[pixel_index + alpha_channel] = (unsigned int)STBIR__ROUND_INT(((double)stbir__saturate(encode_buffer[pixel_index + alpha_channel])) * stbir__max_uint32_as_float);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -1855,12 +1853,12 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void
|
|
break;
|
|
break;
|
|
|
|
|
|
default:
|
|
default:
|
|
- STBIR__UNIMPLEMENTED("Unknown type/colorspace/channels combination.");
|
|
|
|
|
|
+ STBIR_ASSERT(!"Unknown type/colorspace/channels combination.");
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, int in_first_scanline, int in_last_scanline, float in_center_of_out)
|
|
|
|
|
|
+static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n)
|
|
{
|
|
{
|
|
int x, k;
|
|
int x, k;
|
|
int output_w = stbir_info->output_w;
|
|
int output_w = stbir_info->output_w;
|
|
@@ -1870,7 +1868,7 @@ static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, in
|
|
int alpha_channel = stbir_info->alpha_channel;
|
|
int alpha_channel = stbir_info->alpha_channel;
|
|
int type = stbir_info->type;
|
|
int type = stbir_info->type;
|
|
int colorspace = stbir_info->colorspace;
|
|
int colorspace = stbir_info->colorspace;
|
|
- int kernel_pixel_width = stbir_info->vertical_filter_pixel_width;
|
|
|
|
|
|
+ int ring_buffer_entries = stbir_info->ring_buffer_num_entries;
|
|
void* output_data = stbir_info->output_data;
|
|
void* output_data = stbir_info->output_data;
|
|
float* encode_buffer = stbir_info->encode_buffer;
|
|
float* encode_buffer = stbir_info->encode_buffer;
|
|
int decode = STBIR__DECODE(type, colorspace);
|
|
int decode = STBIR__DECODE(type, colorspace);
|
|
@@ -1881,7 +1879,6 @@ static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, in
|
|
float* ring_buffer = stbir_info->ring_buffer;
|
|
float* ring_buffer = stbir_info->ring_buffer;
|
|
int ring_buffer_begin_index = stbir_info->ring_buffer_begin_index;
|
|
int ring_buffer_begin_index = stbir_info->ring_buffer_begin_index;
|
|
int ring_buffer_first_scanline = stbir_info->ring_buffer_first_scanline;
|
|
int ring_buffer_first_scanline = stbir_info->ring_buffer_first_scanline;
|
|
- int ring_buffer_last_scanline = stbir_info->ring_buffer_last_scanline;
|
|
|
|
int ring_buffer_length = stbir_info->ring_buffer_length_bytes/sizeof(float);
|
|
int ring_buffer_length = stbir_info->ring_buffer_length_bytes/sizeof(float);
|
|
|
|
|
|
int n0,n1, output_row_start;
|
|
int n0,n1, output_row_start;
|
|
@@ -1892,7 +1889,7 @@ static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, in
|
|
|
|
|
|
output_row_start = n * stbir_info->output_stride_bytes;
|
|
output_row_start = n * stbir_info->output_stride_bytes;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(stbir__use_height_upsampling(stbir_info));
|
|
|
|
|
|
+ STBIR_ASSERT(stbir__use_height_upsampling(stbir_info));
|
|
|
|
|
|
memset(encode_buffer, 0, output_w * sizeof(float) * channels);
|
|
memset(encode_buffer, 0, output_w * sizeof(float) * channels);
|
|
|
|
|
|
@@ -1905,7 +1902,7 @@ static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, in
|
|
for (k = n0; k <= n1; k++)
|
|
for (k = n0; k <= n1; k++)
|
|
{
|
|
{
|
|
int coefficient_index = coefficient_counter++;
|
|
int coefficient_index = coefficient_counter++;
|
|
- float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, kernel_pixel_width, ring_buffer_length);
|
|
|
|
|
|
+ float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length);
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
for (x = 0; x < output_w; ++x)
|
|
for (x = 0; x < output_w; ++x)
|
|
{
|
|
{
|
|
@@ -1918,7 +1915,7 @@ static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, in
|
|
for (k = n0; k <= n1; k++)
|
|
for (k = n0; k <= n1; k++)
|
|
{
|
|
{
|
|
int coefficient_index = coefficient_counter++;
|
|
int coefficient_index = coefficient_counter++;
|
|
- float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, kernel_pixel_width, ring_buffer_length);
|
|
|
|
|
|
+ float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length);
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
for (x = 0; x < output_w; ++x)
|
|
for (x = 0; x < output_w; ++x)
|
|
{
|
|
{
|
|
@@ -1932,7 +1929,7 @@ static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, in
|
|
for (k = n0; k <= n1; k++)
|
|
for (k = n0; k <= n1; k++)
|
|
{
|
|
{
|
|
int coefficient_index = coefficient_counter++;
|
|
int coefficient_index = coefficient_counter++;
|
|
- float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, kernel_pixel_width, ring_buffer_length);
|
|
|
|
|
|
+ float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length);
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
for (x = 0; x < output_w; ++x)
|
|
for (x = 0; x < output_w; ++x)
|
|
{
|
|
{
|
|
@@ -1947,7 +1944,7 @@ static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, in
|
|
for (k = n0; k <= n1; k++)
|
|
for (k = n0; k <= n1; k++)
|
|
{
|
|
{
|
|
int coefficient_index = coefficient_counter++;
|
|
int coefficient_index = coefficient_counter++;
|
|
- float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, kernel_pixel_width, ring_buffer_length);
|
|
|
|
|
|
+ float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length);
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
for (x = 0; x < output_w; ++x)
|
|
for (x = 0; x < output_w; ++x)
|
|
{
|
|
{
|
|
@@ -1963,7 +1960,7 @@ static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, in
|
|
for (k = n0; k <= n1; k++)
|
|
for (k = n0; k <= n1; k++)
|
|
{
|
|
{
|
|
int coefficient_index = coefficient_counter++;
|
|
int coefficient_index = coefficient_counter++;
|
|
- float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, kernel_pixel_width, ring_buffer_length);
|
|
|
|
|
|
+ float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length);
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
for (x = 0; x < output_w; ++x)
|
|
for (x = 0; x < output_w; ++x)
|
|
{
|
|
{
|
|
@@ -1978,16 +1975,14 @@ static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n, in
|
|
stbir__encode_scanline(stbir_info, output_w, (char *) output_data + output_row_start, encode_buffer, channels, alpha_channel, decode);
|
|
stbir__encode_scanline(stbir_info, output_w, (char *) output_data + output_row_start, encode_buffer, channels, alpha_channel, decode);
|
|
}
|
|
}
|
|
|
|
|
|
-static void stbir__resample_vertical_downsample(stbir__info* stbir_info, int n, int in_first_scanline, int in_last_scanline, float in_center_of_out)
|
|
|
|
|
|
+static void stbir__resample_vertical_downsample(stbir__info* stbir_info, int n)
|
|
{
|
|
{
|
|
int x, k;
|
|
int x, k;
|
|
int output_w = stbir_info->output_w;
|
|
int output_w = stbir_info->output_w;
|
|
- int output_h = stbir_info->output_h;
|
|
|
|
stbir__contributors* vertical_contributors = stbir_info->vertical_contributors;
|
|
stbir__contributors* vertical_contributors = stbir_info->vertical_contributors;
|
|
float* vertical_coefficients = stbir_info->vertical_coefficients;
|
|
float* vertical_coefficients = stbir_info->vertical_coefficients;
|
|
int channels = stbir_info->channels;
|
|
int channels = stbir_info->channels;
|
|
- int kernel_pixel_width = stbir_info->vertical_filter_pixel_width;
|
|
|
|
- void* output_data = stbir_info->output_data;
|
|
|
|
|
|
+ int ring_buffer_entries = stbir_info->ring_buffer_num_entries;
|
|
float* horizontal_buffer = stbir_info->horizontal_buffer;
|
|
float* horizontal_buffer = stbir_info->horizontal_buffer;
|
|
int coefficient_width = stbir_info->vertical_coefficient_width;
|
|
int coefficient_width = stbir_info->vertical_coefficient_width;
|
|
int contributor = n + stbir_info->vertical_filter_pixel_margin;
|
|
int contributor = n + stbir_info->vertical_filter_pixel_margin;
|
|
@@ -1995,14 +1990,13 @@ static void stbir__resample_vertical_downsample(stbir__info* stbir_info, int n,
|
|
float* ring_buffer = stbir_info->ring_buffer;
|
|
float* ring_buffer = stbir_info->ring_buffer;
|
|
int ring_buffer_begin_index = stbir_info->ring_buffer_begin_index;
|
|
int ring_buffer_begin_index = stbir_info->ring_buffer_begin_index;
|
|
int ring_buffer_first_scanline = stbir_info->ring_buffer_first_scanline;
|
|
int ring_buffer_first_scanline = stbir_info->ring_buffer_first_scanline;
|
|
- int ring_buffer_last_scanline = stbir_info->ring_buffer_last_scanline;
|
|
|
|
int ring_buffer_length = stbir_info->ring_buffer_length_bytes/sizeof(float);
|
|
int ring_buffer_length = stbir_info->ring_buffer_length_bytes/sizeof(float);
|
|
int n0,n1;
|
|
int n0,n1;
|
|
|
|
|
|
n0 = vertical_contributors[contributor].n0;
|
|
n0 = vertical_contributors[contributor].n0;
|
|
n1 = vertical_contributors[contributor].n1;
|
|
n1 = vertical_contributors[contributor].n1;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(!stbir__use_height_upsampling(stbir_info));
|
|
|
|
|
|
+ STBIR_ASSERT(!stbir__use_height_upsampling(stbir_info));
|
|
|
|
|
|
for (k = n0; k <= n1; k++)
|
|
for (k = n0; k <= n1; k++)
|
|
{
|
|
{
|
|
@@ -2010,7 +2004,7 @@ static void stbir__resample_vertical_downsample(stbir__info* stbir_info, int n,
|
|
int coefficient_group = coefficient_width * contributor;
|
|
int coefficient_group = coefficient_width * contributor;
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
float coefficient = vertical_coefficients[coefficient_group + coefficient_index];
|
|
|
|
|
|
- float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, kernel_pixel_width, ring_buffer_length);
|
|
|
|
|
|
+ float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length);
|
|
|
|
|
|
switch (channels) {
|
|
switch (channels) {
|
|
case 1:
|
|
case 1:
|
|
@@ -2067,7 +2061,7 @@ static void stbir__buffer_loop_upsample(stbir__info* stbir_info)
|
|
float scale_ratio = stbir_info->vertical_scale;
|
|
float scale_ratio = stbir_info->vertical_scale;
|
|
float out_scanlines_radius = stbir__filter_info_table[stbir_info->vertical_filter].support(1/scale_ratio) * scale_ratio;
|
|
float out_scanlines_radius = stbir__filter_info_table[stbir_info->vertical_filter].support(1/scale_ratio) * scale_ratio;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(stbir__use_height_upsampling(stbir_info));
|
|
|
|
|
|
+ STBIR_ASSERT(stbir__use_height_upsampling(stbir_info));
|
|
|
|
|
|
for (y = 0; y < stbir_info->output_h; y++)
|
|
for (y = 0; y < stbir_info->output_h; y++)
|
|
{
|
|
{
|
|
@@ -2076,7 +2070,7 @@ static void stbir__buffer_loop_upsample(stbir__info* stbir_info)
|
|
|
|
|
|
stbir__calculate_sample_range_upsample(y, out_scanlines_radius, scale_ratio, stbir_info->vertical_shift, &in_first_scanline, &in_last_scanline, &in_center_of_out);
|
|
stbir__calculate_sample_range_upsample(y, out_scanlines_radius, scale_ratio, stbir_info->vertical_shift, &in_first_scanline, &in_last_scanline, &in_center_of_out);
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(in_last_scanline - in_first_scanline <= stbir_info->vertical_filter_pixel_width);
|
|
|
|
|
|
+ STBIR_ASSERT(in_last_scanline - in_first_scanline + 1 <= stbir_info->ring_buffer_num_entries);
|
|
|
|
|
|
if (stbir_info->ring_buffer_begin_index >= 0)
|
|
if (stbir_info->ring_buffer_begin_index >= 0)
|
|
{
|
|
{
|
|
@@ -2095,7 +2089,7 @@ static void stbir__buffer_loop_upsample(stbir__info* stbir_info)
|
|
else
|
|
else
|
|
{
|
|
{
|
|
stbir_info->ring_buffer_first_scanline++;
|
|
stbir_info->ring_buffer_first_scanline++;
|
|
- stbir_info->ring_buffer_begin_index = (stbir_info->ring_buffer_begin_index + 1) % stbir_info->vertical_filter_pixel_width;
|
|
|
|
|
|
+ stbir_info->ring_buffer_begin_index = (stbir_info->ring_buffer_begin_index + 1) % stbir_info->ring_buffer_num_entries;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2108,7 +2102,7 @@ static void stbir__buffer_loop_upsample(stbir__info* stbir_info)
|
|
stbir__decode_and_resample_upsample(stbir_info, stbir_info->ring_buffer_last_scanline + 1);
|
|
stbir__decode_and_resample_upsample(stbir_info, stbir_info->ring_buffer_last_scanline + 1);
|
|
|
|
|
|
// Now all buffers should be ready to write a row of vertical sampling.
|
|
// 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__resample_vertical_upsample(stbir_info, y);
|
|
|
|
|
|
STBIR_PROGRESS_REPORT((float)y / stbir_info->output_h);
|
|
STBIR_PROGRESS_REPORT((float)y / stbir_info->output_h);
|
|
}
|
|
}
|
|
@@ -2153,7 +2147,7 @@ static void stbir__empty_ring_buffer(stbir__info* stbir_info, int first_necessar
|
|
else
|
|
else
|
|
{
|
|
{
|
|
stbir_info->ring_buffer_first_scanline++;
|
|
stbir_info->ring_buffer_first_scanline++;
|
|
- stbir_info->ring_buffer_begin_index = (stbir_info->ring_buffer_begin_index + 1) % stbir_info->vertical_filter_pixel_width;
|
|
|
|
|
|
+ stbir_info->ring_buffer_begin_index = (stbir_info->ring_buffer_begin_index + 1) % stbir_info->ring_buffer_num_entries;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2168,7 +2162,7 @@ static void stbir__buffer_loop_downsample(stbir__info* stbir_info)
|
|
int pixel_margin = stbir_info->vertical_filter_pixel_margin;
|
|
int pixel_margin = stbir_info->vertical_filter_pixel_margin;
|
|
int max_y = stbir_info->input_h + pixel_margin;
|
|
int max_y = stbir_info->input_h + pixel_margin;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(!stbir__use_height_upsampling(stbir_info));
|
|
|
|
|
|
+ STBIR_ASSERT(!stbir__use_height_upsampling(stbir_info));
|
|
|
|
|
|
for (y = -pixel_margin; y < max_y; y++)
|
|
for (y = -pixel_margin; y < max_y; y++)
|
|
{
|
|
{
|
|
@@ -2177,7 +2171,7 @@ static void stbir__buffer_loop_downsample(stbir__info* stbir_info)
|
|
|
|
|
|
stbir__calculate_sample_range_downsample(y, in_pixels_radius, scale_ratio, stbir_info->vertical_shift, &out_first_scanline, &out_last_scanline, &out_center_of_in);
|
|
stbir__calculate_sample_range_downsample(y, in_pixels_radius, scale_ratio, stbir_info->vertical_shift, &out_first_scanline, &out_last_scanline, &out_center_of_in);
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT(out_last_scanline - out_first_scanline <= stbir_info->vertical_filter_pixel_width);
|
|
|
|
|
|
+ STBIR_ASSERT(out_last_scanline - out_first_scanline + 1 <= stbir_info->ring_buffer_num_entries);
|
|
|
|
|
|
if (out_last_scanline < 0 || out_first_scanline >= output_h)
|
|
if (out_last_scanline < 0 || out_first_scanline >= output_h)
|
|
continue;
|
|
continue;
|
|
@@ -2194,7 +2188,7 @@ static void stbir__buffer_loop_downsample(stbir__info* stbir_info)
|
|
stbir__add_empty_ring_buffer_entry(stbir_info, stbir_info->ring_buffer_last_scanline + 1);
|
|
stbir__add_empty_ring_buffer_entry(stbir_info, stbir_info->ring_buffer_last_scanline + 1);
|
|
|
|
|
|
// Now the horizontal buffer is ready to write to all ring buffer rows.
|
|
// 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__resample_vertical_downsample(stbir_info, y);
|
|
}
|
|
}
|
|
|
|
|
|
stbir__empty_ring_buffer(stbir_info, stbir_info->output_h);
|
|
stbir__empty_ring_buffer(stbir_info, stbir_info->output_h);
|
|
@@ -2228,8 +2222,8 @@ static void stbir__calculate_transform(stbir__info *info, float s0, float t0, fl
|
|
info->horizontal_scale = ((float)info->output_w / info->input_w) / (s1 - s0);
|
|
info->horizontal_scale = ((float)info->output_w / info->input_w) / (s1 - s0);
|
|
info->vertical_scale = ((float)info->output_h / info->input_h) / (t1 - t0);
|
|
info->vertical_scale = ((float)info->output_h / info->input_h) / (t1 - t0);
|
|
|
|
|
|
- info->horizontal_shift = s0 * info->input_w / (s1 - s0);
|
|
|
|
- info->vertical_shift = t0 * info->input_h / (t1 - t0);
|
|
|
|
|
|
+ info->horizontal_shift = s0 * info->output_w / (s1 - s0);
|
|
|
|
+ info->vertical_shift = t0 * info->output_h / (t1 - t0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2251,13 +2245,16 @@ static stbir_uint32 stbir__calculate_memory(stbir__info *info)
|
|
info->horizontal_num_contributors = stbir__get_contributors(info->horizontal_scale, info->horizontal_filter, info->input_w, info->output_w);
|
|
info->horizontal_num_contributors = stbir__get_contributors(info->horizontal_scale, info->horizontal_filter, info->input_w, info->output_w);
|
|
info->vertical_num_contributors = stbir__get_contributors(info->vertical_scale , info->vertical_filter , info->input_h, info->output_h);
|
|
info->vertical_num_contributors = stbir__get_contributors(info->vertical_scale , info->vertical_filter , info->input_h, info->output_h);
|
|
|
|
|
|
|
|
+ // One extra entry because floating point precision problems sometimes cause an extra to be necessary.
|
|
|
|
+ info->ring_buffer_num_entries = filter_height + 1;
|
|
|
|
+
|
|
info->horizontal_contributors_size = info->horizontal_num_contributors * sizeof(stbir__contributors);
|
|
info->horizontal_contributors_size = info->horizontal_num_contributors * sizeof(stbir__contributors);
|
|
info->horizontal_coefficients_size = stbir__get_total_horizontal_coefficients(info) * sizeof(float);
|
|
info->horizontal_coefficients_size = stbir__get_total_horizontal_coefficients(info) * sizeof(float);
|
|
info->vertical_contributors_size = info->vertical_num_contributors * sizeof(stbir__contributors);
|
|
info->vertical_contributors_size = info->vertical_num_contributors * sizeof(stbir__contributors);
|
|
info->vertical_coefficients_size = stbir__get_total_vertical_coefficients(info) * sizeof(float);
|
|
info->vertical_coefficients_size = stbir__get_total_vertical_coefficients(info) * sizeof(float);
|
|
info->decode_buffer_size = (info->input_w + pixel_margin * 2) * info->channels * sizeof(float);
|
|
info->decode_buffer_size = (info->input_w + pixel_margin * 2) * info->channels * sizeof(float);
|
|
info->horizontal_buffer_size = info->output_w * info->channels * sizeof(float);
|
|
info->horizontal_buffer_size = info->output_w * info->channels * sizeof(float);
|
|
- info->ring_buffer_size = info->output_w * info->channels * filter_height * sizeof(float);
|
|
|
|
|
|
+ info->ring_buffer_size = info->output_w * info->channels * info->ring_buffer_num_entries * sizeof(float);
|
|
info->encode_buffer_size = info->output_w * info->channels * sizeof(float);
|
|
info->encode_buffer_size = info->output_w * info->channels * sizeof(float);
|
|
|
|
|
|
STBIR_ASSERT(info->horizontal_filter != 0);
|
|
STBIR_ASSERT(info->horizontal_filter != 0);
|
|
@@ -2379,7 +2376,7 @@ static int stbir__resize_allocated(stbir__info *info,
|
|
info->ring_buffer = STBIR__NEXT_MEMPTR(info->decode_buffer, float);
|
|
info->ring_buffer = STBIR__NEXT_MEMPTR(info->decode_buffer, float);
|
|
info->encode_buffer = STBIR__NEXT_MEMPTR(info->ring_buffer, float);
|
|
info->encode_buffer = STBIR__NEXT_MEMPTR(info->ring_buffer, float);
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT((size_t)STBIR__NEXT_MEMPTR(info->encode_buffer, unsigned char) == (size_t)tempmem + tempmem_size_in_bytes);
|
|
|
|
|
|
+ STBIR_ASSERT((size_t)STBIR__NEXT_MEMPTR(info->encode_buffer, unsigned char) == (size_t)tempmem + tempmem_size_in_bytes);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -2387,7 +2384,7 @@ static int stbir__resize_allocated(stbir__info *info,
|
|
info->ring_buffer = STBIR__NEXT_MEMPTR(info->horizontal_buffer, float);
|
|
info->ring_buffer = STBIR__NEXT_MEMPTR(info->horizontal_buffer, float);
|
|
info->encode_buffer = NULL;
|
|
info->encode_buffer = NULL;
|
|
|
|
|
|
- STBIR__DEBUG_ASSERT((size_t)STBIR__NEXT_MEMPTR(info->ring_buffer, unsigned char) == (size_t)tempmem + tempmem_size_in_bytes);
|
|
|
|
|
|
+ STBIR_ASSERT((size_t)STBIR__NEXT_MEMPTR(info->ring_buffer, unsigned char) == (size_t)tempmem + tempmem_size_in_bytes);
|
|
}
|
|
}
|
|
|
|
|
|
#undef STBIR__NEXT_MEMPTR
|
|
#undef STBIR__NEXT_MEMPTR
|
|
@@ -2395,8 +2392,8 @@ static int stbir__resize_allocated(stbir__info *info,
|
|
// This signals that the ring buffer is empty
|
|
// This signals that the ring buffer is empty
|
|
info->ring_buffer_begin_index = -1;
|
|
info->ring_buffer_begin_index = -1;
|
|
|
|
|
|
- stbir__calculate_filters(info, info->horizontal_contributors, info->horizontal_coefficients, info->horizontal_filter, info->horizontal_scale, info->horizontal_shift, info->input_w, info->output_w);
|
|
|
|
- stbir__calculate_filters(info, info->vertical_contributors, info->vertical_coefficients, info->vertical_filter, info->vertical_scale, info->vertical_shift, info->input_h, info->output_h);
|
|
|
|
|
|
+ stbir__calculate_filters(info->horizontal_contributors, info->horizontal_coefficients, info->horizontal_filter, info->horizontal_scale, info->horizontal_shift, info->input_w, info->output_w);
|
|
|
|
+ stbir__calculate_filters(info->vertical_contributors, info->vertical_coefficients, info->vertical_filter, info->vertical_scale, info->vertical_shift, info->input_h, info->output_h);
|
|
|
|
|
|
STBIR_PROGRESS_REPORT(0);
|
|
STBIR_PROGRESS_REPORT(0);
|
|
|
|
|
|
@@ -2408,10 +2405,10 @@ static int stbir__resize_allocated(stbir__info *info,
|
|
STBIR_PROGRESS_REPORT(1);
|
|
STBIR_PROGRESS_REPORT(1);
|
|
|
|
|
|
#ifdef STBIR_DEBUG_OVERWRITE_TEST
|
|
#ifdef STBIR_DEBUG_OVERWRITE_TEST
|
|
- STBIR__DEBUG_ASSERT(memcmp(overwrite_output_before_pre, &((unsigned char*)output_data)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE) == 0);
|
|
|
|
- STBIR__DEBUG_ASSERT(memcmp(overwrite_output_after_pre, &((unsigned char*)output_data)[begin_forbidden], OVERWRITE_ARRAY_SIZE) == 0);
|
|
|
|
- STBIR__DEBUG_ASSERT(memcmp(overwrite_tempmem_before_pre, &((unsigned char*)tempmem)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE) == 0);
|
|
|
|
- STBIR__DEBUG_ASSERT(memcmp(overwrite_tempmem_after_pre, &((unsigned char*)tempmem)[tempmem_size_in_bytes], OVERWRITE_ARRAY_SIZE) == 0);
|
|
|
|
|
|
+ STBIR_ASSERT(memcmp(overwrite_output_before_pre, &((unsigned char*)output_data)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE) == 0);
|
|
|
|
+ STBIR_ASSERT(memcmp(overwrite_output_after_pre, &((unsigned char*)output_data)[begin_forbidden], OVERWRITE_ARRAY_SIZE) == 0);
|
|
|
|
+ STBIR_ASSERT(memcmp(overwrite_tempmem_before_pre, &((unsigned char*)tempmem)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE) == 0);
|
|
|
|
+ STBIR_ASSERT(memcmp(overwrite_tempmem_after_pre, &((unsigned char*)tempmem)[tempmem_size_in_bytes], OVERWRITE_ARRAY_SIZE) == 0);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
@@ -2583,3 +2580,45 @@ STBIRDEF int stbir_resize_region( const void *input_pixels , int input_w , int
|
|
}
|
|
}
|
|
|
|
|
|
#endif // STB_IMAGE_RESIZE_IMPLEMENTATION
|
|
#endif // STB_IMAGE_RESIZE_IMPLEMENTATION
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+------------------------------------------------------------------------------
|
|
|
|
+This software is available under 2 licenses -- choose whichever you prefer.
|
|
|
|
+------------------------------------------------------------------------------
|
|
|
|
+ALTERNATIVE A - MIT License
|
|
|
|
+Copyright (c) 2017 Sean Barrett
|
|
|
|
+Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
+this software and associated documentation files (the "Software"), to deal in
|
|
|
|
+the Software without restriction, including without limitation the rights to
|
|
|
|
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
+of the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
+so, subject to the following conditions:
|
|
|
|
+The above copyright notice and this permission notice shall be included in all
|
|
|
|
+copies or substantial portions of the Software.
|
|
|
|
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
+SOFTWARE.
|
|
|
|
+------------------------------------------------------------------------------
|
|
|
|
+ALTERNATIVE B - Public Domain (www.unlicense.org)
|
|
|
|
+This is free and unencumbered software released into the public domain.
|
|
|
|
+Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
|
|
|
+software, either in source code form or as a compiled binary, for any purpose,
|
|
|
|
+commercial or non-commercial, and by any means.
|
|
|
|
+In jurisdictions that recognize copyright laws, the author or authors of this
|
|
|
|
+software dedicate any and all copyright interest in the software to the public
|
|
|
|
+domain. We make this dedication for the benefit of the public at large and to
|
|
|
|
+the detriment of our heirs and successors. We intend this dedication to be an
|
|
|
|
+overt act of relinquishment in perpetuity of all present and future rights to
|
|
|
|
+this software under copyright law.
|
|
|
|
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
+------------------------------------------------------------------------------
|
|
|
|
+*/
|