Skip to content

Commit

Permalink
stb_image_resize2.h 2.00
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Barrett committed Oct 10, 2023
1 parent 5736b15 commit c4bbb6e
Show file tree
Hide file tree
Showing 14 changed files with 15,329 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ library | lastest version | category | LoC | description
**[stb_image.h](stb_image.h)** | 2.28 | graphics | 7987 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC
**[stb_truetype.h](stb_truetype.h)** | 1.26 | graphics | 5077 | parse, decode, and rasterize characters from truetype fonts
**[stb_image_write.h](stb_image_write.h)** | 1.16 | graphics | 1724 | image writing to disk: PNG, TGA, BMP
**[stb_image_resize.h](stb_image_resize.h)** | 0.97 | graphics | 2634 | resize images larger/smaller with good quality
**[stb_image_resize2.h](stb_image_resize2.h)** | 2.00 | graphics | 10303 | resize images larger/smaller with good quality
**[stb_rect_pack.h](stb_rect_pack.h)** | 1.01 | graphics | 623 | simple 2D rectangle packer with decent quality
**[stb_perlin.h](stb_perlin.h)** | 0.5 | graphics | 428 | perlin's revised simplex noise w/ different seeds
**[stb_ds.h](stb_ds.h)** | 0.67 | utility | 1895 | typesafe dynamic array and hash tables for C, will compile in C++
Expand All @@ -43,7 +43,7 @@ library | lastest version | category | LoC | description
**[stb_include.h](stb_include.h)** | 0.02 | misc | 295 | implement recursive #include support, particularly for GLSL

Total libraries: 21
Total lines of C code: 43117
Total lines of C code: 50786


FAQ
Expand Down
File renamed without changes.
10,303 changes: 10,303 additions & 0 deletions stb_image_resize2.h

Large diffs are not rendered by default.

224 changes: 224 additions & 0 deletions stb_image_resize_test/dotimings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef _MSC_VER

#define stop() __debugbreak()
#include <windows.h>
#define int64 __int64
#pragma warning(disable:4127)

#define get_milliseconds GetTickCount

#else

#define stop() __builtin_trap()
#define int64 long long

typedef unsigned int U32;
typedef unsigned long long U64;

#include <time.h>
static int get_milliseconds()
{
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC, &ts );
return (U32) ( ( ((U64)(U32)ts.tv_sec) * 1000LL ) + (U64)(((U32)ts.tv_nsec+500000)/1000000) );
}

#endif

#if defined(TIME_SIMD)
// default for most platforms
#elif defined(TIME_SCALAR)
#define STBIR_NO_SIMD
#else
#error You must define TIME_SIMD or TIME_SCALAR when compiling this file.
#endif

#define STBIR_PROFILE
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#define STBIR__V_FIRST_INFO_BUFFER v_info
#include "stb_image_resize2.h" // new one!

#if defined(TIME_SIMD) && !defined(STBIR_SIMD)
#error Timing SIMD, but scalar was ON!
#endif

#if defined(TIME_SCALAR) && defined(STBIR_SIMD)
#error Timing scalar, but SIMD was ON!
#endif

#define HEADER 32


static int file_write( const char *filename, void * buffer, size_t size )
{
FILE * f = fopen( filename, "wb" );
if ( f == 0 ) return 0;
if ( fwrite( buffer, 1, size, f) != size ) return 0;
fclose(f);
return 1;
}

int64 nresize( void * o, int ox, int oy, int op, void * i, int ix, int iy, int ip, int buf, int type, int edg, int flt )
{
STBIR_RESIZE resize;
int t;
int64 b;

stbir_resize_init( &resize, i, ix, iy, ip, o, ox, oy, op, buf, type );
stbir_set_edgemodes( &resize, edg, edg );
stbir_set_filters( &resize, flt, flt );

stbir_build_samplers_with_splits( &resize, 1 );

b = 0x7fffffffffffffffULL;
for( t = 0 ; t < 16 ; t++ )
{
STBIR_PROFILE_INFO profile;
int64 v;
if(!stbir_resize_extended( &resize ) )
stop();
stbir_resize_extended_profile_info( &profile, &resize );
v = profile.clocks[1]+profile.clocks[2];
if ( v < b )
{
b = v;
t = 0;
}
}

stbir_free_samplers( &resize );

return b;
}


#define INSIZES 5
#define TYPESCOUNT 5
#define NUM 64

static const int sizes[INSIZES]={63,126,252,520,772};
static const int types[TYPESCOUNT]={STBIR_1CHANNEL,STBIR_2CHANNEL,STBIR_RGB,STBIR_4CHANNEL,STBIR_RGBA};
static const int effective[TYPESCOUNT]={1,2,3,4,7};

int main( int argc, char ** argv )
{
unsigned char * input;
unsigned char * output;
int dimensionx, dimensiony;
int scalex, scaley;
int totalms;
int timing_count;
int ir;
int * file;
int * ts;
int64 totalcycles;

if ( argc != 6 )
{
printf("command: dotimings x_samps y_samps x_scale y_scale outfilename\n");
exit(1);
}

input = malloc( 4*1200*1200 );
memset( input, 0x80, 4*1200*1200 );
output = malloc( 4*10000*10000ULL );

dimensionx = atoi( argv[1] );
dimensiony = atoi( argv[2] );
scalex = atoi( argv[3] );
scaley = atoi( argv[4] );

timing_count = dimensionx * dimensiony * INSIZES * TYPESCOUNT;

file = malloc( sizeof(int) * ( 2 * timing_count + HEADER ) );
ts = file + HEADER;

totalms = get_milliseconds();
totalcycles = STBIR_PROFILE_FUNC();
for( ir = 0 ; ir < INSIZES ; ir++ )
{
int ix, iy, ty;
ix = iy = sizes[ir];

for( ty = 0 ; ty < TYPESCOUNT ; ty++ )
{
int h, hh;

h = 1;
for( hh = 0 ; hh < dimensiony; hh++ )
{
int ww, w = 1;
for( ww = 0 ; ww < dimensionx; ww++ )
{
int64 VF, HF;
int good;

v_info.control_v_first = 2; // vertical first
VF = nresize( output, w, h, (w*4*1)&~3, input, ix, iy, ix*4*1, types[ty], STBIR_TYPE_UINT8, STBIR_EDGE_CLAMP, STBIR_FILTER_MITCHELL );
v_info.control_v_first = 1; // horizonal first
HF = nresize( output, w, h, (w*4*1)&~3, input, ix, iy, ix*4*1, types[ty], STBIR_TYPE_UINT8, STBIR_EDGE_CLAMP, STBIR_FILTER_MITCHELL );

good = ( ((HF<=VF) && (!v_info.v_first)) || ((VF<=HF) && (v_info.v_first)));

// printf("\r%d,%d, %d,%d, %d, %I64d,%I64d, // Good: %c(%c-%d) CompEst: %.1f %.1f\n", ix, iy, w, h, ty, VF, HF, good?'y':'n', v_info.v_first?'v':'h', v_info.v_resize_classification, v_info.v_cost,v_info.h_cost );
ts[0] = (int)VF;
ts[1] = (int)HF;

ts += 2;

w += scalex;
}
printf(".");
h += scaley;
}
}
}
totalms = get_milliseconds() - totalms;
totalcycles = STBIR_PROFILE_FUNC() - totalcycles;

printf("\n");

file[0] = 'VFT1';

#if defined(_x86_64) || defined( __x86_64__ ) || defined( _M_X64 ) || defined(__x86_64) || defined(__SSE2__) || defined( _M_IX86_FP ) || defined(__i386) || defined( __i386__ ) || defined( _M_IX86 ) || defined( _X86_ )
file[1] = 1; // x64
#elif defined( _M_AMD64 ) || defined( __aarch64__ ) || defined( __arm64__ ) || defined(__ARM_NEON__) || defined(__ARM_NEON) || defined(__arm__) || defined( _M_ARM )
file[1] = 2; // arm
#else
file[1] = 99; // who knows???
#endif

#ifdef STBIR_SIMD8
file[2] = 2; // simd-8
#elif defined( STBIR_SIMD )
file[2] = 1; // simd-4
#else
file[2] = 0; // nosimd
#endif

file[3] = dimensionx; // dimx
file[4] = dimensiony; // dimy
file[5] = TYPESCOUNT; // channel types
file[ 6] = types[0]; file[7] = types[1]; file[8] = types[2]; file[9] = types[3]; file[10] = types[4]; // buffer_type
file[11] = effective[0]; file[12] = effective[1]; file[13] = effective[2]; file[14] = effective[3]; file[15] = effective[4]; // effective channels
file[16] = INSIZES; // resizes
file[17] = sizes[0]; file[18] = sizes[0]; // input sizes (w x h)
file[19] = sizes[1]; file[20] = sizes[1];
file[21] = sizes[2]; file[22] = sizes[2];
file[23] = sizes[3]; file[24] = sizes[3];
file[25] = sizes[4]; file[26] = sizes[4];
file[27] = scalex; file[28] = scaley; // scale the dimx and dimy amount ( for(i=0;i<dimx) outputx = 1 + i*scalex; )
file[29] = totalms;
((int64*)(file+30))[0] = totalcycles;

if ( !file_write( argv[5], file, sizeof(int) * ( 2 * timing_count + HEADER ) ) )
printf( "Error writing file: %s\n", argv[5] );
else
printf( "Successfully wrote timing file: %s\n", argv[5] );

return 0;
}
Loading

0 comments on commit c4bbb6e

Please sign in to comment.