Merge branch 'resample2' into resample
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
#include <malloc.h>
|
||||
|
||||
#if defined(_WIN32) && _MSC_VER > 1200
|
||||
#define STBIR_ASSERT(x) \
|
||||
if (!(x)) { \
|
||||
@ -8,6 +10,49 @@
|
||||
#define STBIR_ASSERT(x) assert(x)
|
||||
#endif
|
||||
|
||||
#define STBIR_MALLOC stbir_malloc
|
||||
#define STBIR_FREE stbir_free
|
||||
|
||||
class stbir_context {
|
||||
public:
|
||||
stbir_context()
|
||||
{
|
||||
size = 1000000;
|
||||
memory = malloc(size);
|
||||
}
|
||||
|
||||
~stbir_context()
|
||||
{
|
||||
free(memory);
|
||||
}
|
||||
|
||||
size_t size;
|
||||
void* memory;
|
||||
} g_context;
|
||||
|
||||
void* stbir_malloc(void* context, size_t size)
|
||||
{
|
||||
if (!context)
|
||||
return 0;
|
||||
|
||||
stbir_context* real_context = (stbir_context*)context;
|
||||
if (size > real_context->size)
|
||||
return 0;
|
||||
|
||||
return real_context->memory;
|
||||
}
|
||||
|
||||
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"
|
||||
@ -131,7 +176,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
ftime(&initial_time_millis);
|
||||
for (int i = 0; i < 100; i++)
|
||||
stbir_resize_arbitrary(NULL, input_data + w * border * n + border * n, in_w, in_h, w*n, output_data, out_w, out_h, out_stride, 0, 0, 1, 1, NULL, n, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB);
|
||||
stbir_resize(input_data + w * border * n + border * n, in_w, in_h, w*n, output_data, out_w, out_h, out_stride, STBIR_TYPE_UINT8, n, n - 1, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context);
|
||||
ftime(&final_time_millis);
|
||||
long lapsed_ms = (long)(final_time_millis.time - initial_time_millis.time) * 1000 + (final_time_millis.millitm - initial_time_millis.millitm);
|
||||
printf("Resample: %dms\n", lapsed_ms);
|
||||
@ -142,13 +187,21 @@ int main(int argc, char** argv)
|
||||
average /= 10;
|
||||
|
||||
printf("Average: %dms\n", average);
|
||||
#else
|
||||
stbir_resize_arbitrary(NULL, input_data + w * border * n + border * n, in_w, in_h, w*n, output_data, out_w, out_h, out_stride, s0, t0, s1, t1, NULL, n, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB);
|
||||
#endif
|
||||
|
||||
stbi_image_free(input_data);
|
||||
|
||||
stbi_write_png("output.png", out_w, out_h, n, output_data, out_stride);
|
||||
#else
|
||||
stbir_resize_region(input_data + w * border * n + border * n, in_w, in_h, w*n, output_data, out_w, out_h, out_stride, STBIR_TYPE_UINT8, n, n-1, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, s0, t0, s1, t1);
|
||||
|
||||
stbi_write_png("output-region.png", out_w, out_h, n, output_data, out_stride);
|
||||
|
||||
stbir_resize_subpixel(input_data + w * border * n + border * n, in_w, in_h, w*n, output_data, out_w, out_h, out_stride, STBIR_TYPE_UINT8, n, n-1, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, in_w*s0, in_h*t0, 0.5f, 0.5f);
|
||||
|
||||
stbi_write_png("output-subpixel.png", out_w, out_h, n, output_data, out_stride);
|
||||
|
||||
stbi_image_free(input_data);
|
||||
#endif
|
||||
|
||||
free(output_data);
|
||||
|
||||
@ -171,7 +224,7 @@ void resize_image(const char* filename, float width_percent, float height_percen
|
||||
|
||||
unsigned char* output_data = (unsigned char*)malloc(out_w * out_h * n);
|
||||
|
||||
stbir_resize_arbitrary(NULL, input_data, w, h, 0, output_data, out_w, out_h, 0, 0, 0, 1, 1, NULL, n, -1, 0, STBIR_TYPE_UINT8, filter, filter, edge, edge, colorspace);
|
||||
stbir_resize(input_data, w, h, 0, output_data, out_w, out_h, 0, STBIR_TYPE_UINT8, n, STBIR_ALPHA_CHANNEL_NONE, 0, edge, edge, filter, filter, colorspace, &g_context);
|
||||
|
||||
stbi_image_free(input_data);
|
||||
|
||||
@ -206,7 +259,7 @@ void test_format(const char* file, float width_percent, float height_percent, st
|
||||
|
||||
T* output_data = (T*)malloc(new_w * new_h * n * sizeof(T));
|
||||
|
||||
stbir_resize_arbitrary(NULL, T_data, w, h, 0, output_data, new_w, new_h, 0, 0, 0, 1, 1, NULL, n, -1, 0, type, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, colorspace);
|
||||
stbir_resize(T_data, w, h, 0, output_data, new_w, new_h, 0, type, n, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, colorspace, &g_context);
|
||||
|
||||
free(T_data);
|
||||
stbi_image_free(input_data);
|
||||
@ -250,7 +303,7 @@ void test_float(const char* file, float width_percent, float height_percent, stb
|
||||
|
||||
float* output_data = (float*)malloc(new_w * new_h * n * sizeof(float));
|
||||
|
||||
stbir_resize_arbitrary(NULL, T_data, w, h, 0, output_data, new_w, new_h, 0, 0, 0, 1, 1, NULL, n, -1, 0, type, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, colorspace);
|
||||
stbir_resize_float_generic(T_data, w, h, 0, output_data, new_w, new_h, 0, n, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, colorspace, &g_context);
|
||||
|
||||
free(T_data);
|
||||
stbi_image_free(input_data);
|
||||
@ -290,7 +343,7 @@ void test_channels(const char* file, float width_percent, float height_percent,
|
||||
|
||||
unsigned char* output_data = (unsigned char*)malloc(new_w * new_h * channels * sizeof(unsigned char));
|
||||
|
||||
stbir_resize_uint8_srgb(channels_data, w, h, 0, output_data, new_w, new_h, 0, channels, -1,0);
|
||||
stbir_resize_uint8_srgb(channels_data, w, h, 0, output_data, new_w, new_h, 0, channels, STBIR_ALPHA_CHANNEL_NONE, 0);
|
||||
|
||||
free(channels_data);
|
||||
stbi_image_free(input_data);
|
||||
@ -318,7 +371,7 @@ void test_subpixel(const char* file, float width_percent, float height_percent,
|
||||
|
||||
unsigned char* output_data = (unsigned char*)malloc(new_w * new_h * n * sizeof(unsigned char));
|
||||
|
||||
stbir_resize_arbitrary(NULL, input_data, w, h, 0, output_data, new_w, new_h, 0, 0, 0, s1, t1, NULL, n, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB);
|
||||
stbir_resize_region(input_data, w, h, 0, output_data, new_w, new_h, 0, STBIR_TYPE_UINT8, n, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, 0, 0, s1, t1);
|
||||
|
||||
stbi_image_free(input_data);
|
||||
|
||||
@ -353,13 +406,13 @@ void test_premul(const char* file)
|
||||
|
||||
unsigned char* output_data = (unsigned char*)malloc(new_w * new_h * n * sizeof(unsigned char));
|
||||
|
||||
stbir_resize_arbitrary(NULL, input_data, w, h, 0, output_data, new_w, new_h, 0, 0, 0, 1, 1, NULL, n, 3, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB);
|
||||
stbir_resize_uint8_generic(input_data, w, h, 0, output_data, new_w, new_h, 0, n, n - 1, 0, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context);
|
||||
|
||||
char output[200];
|
||||
sprintf(output, "test-output/premul-%s", file);
|
||||
stbi_write_png(output, new_w, new_h, n, output_data, 0);
|
||||
|
||||
stbir_resize_arbitrary(NULL, input_data, w, h, 0, output_data, new_w, new_h, 0, 0, 0, 1, 1, NULL, n, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB);
|
||||
stbir_resize_uint8_generic(input_data, w, h, 0, output_data, new_w, new_h, 0, n, n - 1, STBIR_FLAG_PREMULTIPLIED_ALPHA, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context);
|
||||
|
||||
sprintf(output, "test-output/nopremul-%s", file);
|
||||
stbi_write_png(output, new_w, new_h, n, output_data, 0);
|
||||
@ -381,13 +434,13 @@ void test_subpixel_1()
|
||||
|
||||
unsigned char output_data[16 * 16];
|
||||
|
||||
stbir_resize_arbitrary(NULL, image, 8, 8, 0, output_data, 16, 16, 0, 0, 0, 1, 1, NULL, 1, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB);
|
||||
stbir_resize_region(image, 8, 8, 0, output_data, 16, 16, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, 0, 0, 1, 1);
|
||||
|
||||
unsigned char output_left[8 * 16];
|
||||
unsigned char output_right[8 * 16];
|
||||
|
||||
stbir_resize_arbitrary(NULL, image, 8, 8, 0, output_left, 8, 16, 0, 0, 0, 0.5f, 1, NULL, 1, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB);
|
||||
stbir_resize_arbitrary(NULL, image, 8, 8, 0, output_right, 8, 16, 0, 0.5f, 0, 1, 1, NULL, 1, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB);
|
||||
stbir_resize_region(image, 8, 8, 0, output_left, 8, 16, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, 0, 0, 0.5f, 1);
|
||||
stbir_resize_region(image, 8, 8, 0, output_right, 8, 16, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, 0.5f, 0, 1, 1);
|
||||
|
||||
for (int x = 0; x < 8; x++)
|
||||
{
|
||||
@ -426,8 +479,8 @@ void test_subpixel_2()
|
||||
unsigned char output_data_1[16 * 16];
|
||||
unsigned char output_data_2[16 * 16];
|
||||
|
||||
stbir_resize_arbitrary(NULL, image, 8, 8, 0, output_data_1, 16, 16, 0, 0, 0, 1, 1, NULL, 1, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_WRAP, STBIR_EDGE_WRAP, STBIR_COLORSPACE_SRGB);
|
||||
stbir_resize_arbitrary(NULL, large_image, 32, 32, 0, output_data_2, 16, 16, 0, 0.25f, 0.25f, 0.5f, 0.5f, NULL, 1, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB);
|
||||
stbir_resize(image, 8, 8, 0, output_data_1, 16, 16, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_WRAP, STBIR_EDGE_WRAP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context);
|
||||
stbir_resize_region(large_image, 32, 32, 0, output_data_2, 16, 16, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_WRAP, STBIR_EDGE_WRAP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, 0.25f, 0.25f, 0.5f, 0.5f);
|
||||
|
||||
{for (int x = 0; x < 16; x++)
|
||||
{
|
||||
@ -449,7 +502,7 @@ void test_subpixel_3()
|
||||
unsigned char output_data_1[32 * 32];
|
||||
unsigned char output_data_2[32 * 32];
|
||||
|
||||
stbir_resize_region(image, 8, 8, 0, output_data_1, 32, 32, 0, STBIR_TYPE_UINT8, 1,0,-1, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_LINEAR, NULL, 0, 0, 1, 1);
|
||||
stbir_resize_region(image, 8, 8, 0, output_data_1, 32, 32, 0, STBIR_TYPE_UINT8, 1, 0, STBIR_ALPHA_CHANNEL_NONE, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_LINEAR, NULL, 0, 0, 1, 1);
|
||||
stbir_resize_uint8(image, 8, 8, 0, output_data_2, 32, 32, 0, 1);
|
||||
|
||||
for (int x = 0; x < 32; x++)
|
||||
@ -471,7 +524,7 @@ void test_subpixel_4()
|
||||
|
||||
unsigned char output[8 * 8];
|
||||
|
||||
stbir_resize_arbitrary(NULL, image, 8, 8, 0, output, 8, 8, 0, 0, 0, 1, 1, NULL, 1, -1, 0, STBIR_TYPE_UINT8, STBIR_FILTER_BILINEAR, STBIR_FILTER_BILINEAR, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_LINEAR);
|
||||
stbir_resize_region(image, 8, 8, 0, output, 8, 8, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_BILINEAR, STBIR_FILTER_BILINEAR, STBIR_COLORSPACE_LINEAR, &g_context, 0, 0, 1, 1);
|
||||
STBIR_ASSERT(memcmp(image, output, 8 * 8) == 0);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user