new quickstart docs;
reformat docs; new simple uint32 test
This commit is contained in:
parent
3c261481a6
commit
9f66b441bd
@ -2,23 +2,33 @@
|
||||
by Jorge L Rodriguez (@VinoBS) - 2014
|
||||
http://github.com/nothings/stb
|
||||
|
||||
Written with emphasis on usage and speed. Only scaling is
|
||||
currently supported, no rotations or translations.
|
||||
|
||||
DOCUMENTATION
|
||||
Written with emphasis on usability, portability, and efficiency. (No
|
||||
SIMD or threads, so it will not be the fastest implementation around.)
|
||||
Only scaling is supported, no rotations or translations.
|
||||
|
||||
COMPILING & LINKING
|
||||
In one C/C++ file that #includes this file, do this:
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
before the #include. That will create the implementation in that file.
|
||||
|
||||
VERY QUICK GUIDE
|
||||
A typical resize of a in_w by in_h image to out_w by out_h with 4 channels where channel #3 is the alpha channel might look like:
|
||||
int success = stbir_resize_uint8_srgb_edgemode(input_pixels, in_w, in_h, 0, output_pixels, out_w, out_h, 0, 4, 3, 0, STBIR_EDGE_CLAMP);
|
||||
QUICKSTART
|
||||
stbir_resize_uint8( input_pixels , in_w , in_h , 0,
|
||||
output_pixels, out_w, out_h, 0, num_channels)
|
||||
stbir_resize_float(...)
|
||||
stbir_resize_uint8_srgb( input_pixels , in_w , in_h , 0,
|
||||
output_pixels, out_w, out_h, 0,
|
||||
num_channels , alpha_ chan , 0)
|
||||
stbir_resize_uint8_srgb_edgemode(
|
||||
input_pixels , in_w , in_h , 0,
|
||||
output_pixels, out_w, out_h, 0,
|
||||
num_channels , alpha_chan , 0, STBIR_EDGE_CLAMP)
|
||||
WRAP/REFLECT/ZERO
|
||||
|
||||
FULL API
|
||||
See the "header file" section of the source for API documentation.
|
||||
|
||||
ADDITIONAL DOCUMENTATION
|
||||
|
||||
MEMORY ALLOCATION
|
||||
The resize functions here perform a single memory allocation using
|
||||
malloc. To control the memory allocation, before the #include that
|
||||
@ -149,13 +159,13 @@
|
||||
#ifndef STBIR_INCLUDE_STB_IMAGE_RESIZE_H
|
||||
#define STBIR_INCLUDE_STB_IMAGE_RESIZE_H
|
||||
|
||||
typedef unsigned char stbir_uint8;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
typedef unsigned char stbir_uint8;
|
||||
typedef unsigned short stbir_uint16;
|
||||
typedef unsigned int stbir_uint32;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
typedef uint8_t stbir_uint8;
|
||||
typedef uint16_t stbir_uint16;
|
||||
typedef uint32_t stbir_uint32;
|
||||
#endif
|
||||
|
@ -750,6 +750,40 @@ void test_filters(void)
|
||||
}
|
||||
}
|
||||
|
||||
#define UMAX32 4294967295U
|
||||
|
||||
static void write32(char *filename, stbir_uint32 *output, int w, int h)
|
||||
{
|
||||
stbir_uint8 *data = (stbir_uint8*) malloc(w*h*3);
|
||||
for (int i=0; i < w*h*3; ++i)
|
||||
data[i] = output[i]>>24;
|
||||
stbi_write_png(filename, w, h, 3, data, 0);
|
||||
free(data);
|
||||
}
|
||||
|
||||
static void test_32(void)
|
||||
{
|
||||
int w=100,h=120,x,y, out_w,out_h;
|
||||
stbir_uint32 *input = (stbir_uint32*) malloc(4 * 3 * w * h);
|
||||
stbir_uint32 *output = (stbir_uint32*) malloc(4 * 3 * 3*w * 3*h);
|
||||
for (y=0; y < h; ++y) {
|
||||
for (x=0; x < w; ++x) {
|
||||
input[y*3*w + x*3 + 0] = x * ( UMAX32/w );
|
||||
input[y*3*w + x*3 + 1] = y * ( UMAX32/h );
|
||||
input[y*3*w + x*3 + 2] = UMAX32/2;
|
||||
}
|
||||
}
|
||||
out_w = w*33/16;
|
||||
out_h = h*33/16;
|
||||
stbir_resize(input,w,h,0,output,out_w,out_h,0,STBIR_TYPE_UINT32,3,-1,0,STBIR_EDGE_CLAMP,STBIR_EDGE_CLAMP,STBIR_FILTER_DEFAULT,STBIR_FILTER_DEFAULT,STBIR_COLORSPACE_LINEAR,NULL);
|
||||
write32("test-output/seantest_1.png", output,out_w,out_h);
|
||||
|
||||
out_w = w*16/33;
|
||||
out_h = h*16/33;
|
||||
stbir_resize(input,w,h,0,output,out_w,out_h,0,STBIR_TYPE_UINT32,3,-1,0,STBIR_EDGE_CLAMP,STBIR_EDGE_CLAMP,STBIR_FILTER_DEFAULT,STBIR_FILTER_DEFAULT,STBIR_COLORSPACE_LINEAR,NULL);
|
||||
write32("test-output/seantest_2.png", output,out_w,out_h);
|
||||
}
|
||||
|
||||
|
||||
void test_suite(int argc, char **argv)
|
||||
{
|
||||
@ -758,6 +792,8 @@ void test_suite(int argc, char **argv)
|
||||
|
||||
_mkdir("test-output");
|
||||
|
||||
test_32();
|
||||
|
||||
if (argc > 1)
|
||||
barbara = argv[1];
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user