mirror of
https://github.com/nothings/stb
synced 2025-01-06 14:52:00 +03:00
tweak docs; fix compile error in UNUSED_PARAM stuff
This commit is contained in:
parent
99f3b78bbd
commit
a9778b8dbd
@ -47,13 +47,19 @@
|
||||
For interactive use with slow resize operations, you can install
|
||||
a progress-report callback:
|
||||
|
||||
#define STBIR_PROGRESS_REPORT(val) my_progress_report(val)
|
||||
#define STBIR_PROGRESS_REPORT(val) some_func(val)
|
||||
|
||||
The parameter val is a float which goes from 0 to 1 as progress is made.
|
||||
|
||||
For example:
|
||||
|
||||
void my_progress_report(float progress)
|
||||
static void my_progress_report(float progress);
|
||||
#define STBIR_PROGRESS_REPORT(val) my_progress_report(val)
|
||||
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
#include "stb_image_resize.h"
|
||||
|
||||
static void my_progress_report(float progress)
|
||||
{
|
||||
printf("Progress: %f%%\n", progress*100);
|
||||
}
|
||||
@ -87,7 +93,9 @@
|
||||
|
||||
4. If you pass the flag STBIR_FLAG_ALPHA_PREMULTIPLIED, the
|
||||
resizer does not do anything special for the alpha channel;
|
||||
it is resampled identically to other channels.
|
||||
it is resampled identically to other channels. This produces
|
||||
the correct results for premultiplied-alpha images, but produces
|
||||
less-than-ideal results for non-premultiplied-alpha images.
|
||||
|
||||
5. If you do not pass the flag STBIR_FLAG_ALPHA_PREMULTIPLIED,
|
||||
then the resizer weights the contribution of input pixels
|
||||
@ -105,7 +113,11 @@
|
||||
value to the alpha channel of every image, and then subtracting
|
||||
or clamping it at the end.)
|
||||
|
||||
6. You can separately control whether the alpha channel is
|
||||
6. You can suppress the behavior described in #5 and make
|
||||
all-0-alpha pixels have 0 in all channels by #defining
|
||||
STBIR_NO_ALPHA_EPSILON.
|
||||
|
||||
7. You can separately control whether the alpha channel is
|
||||
interpreted as linear or affected by the colorspace. By default
|
||||
it is linear; you almost never want to apply the colorspace.
|
||||
(For example, graphics hardware does not apply sRGB conversion
|
||||
@ -123,7 +135,8 @@
|
||||
and modify this file as you see fit.
|
||||
|
||||
TODO
|
||||
Installable filters
|
||||
Don't decode all of the image data when only processing a subtile
|
||||
Installable filters?
|
||||
Resize that respects alpha test coverage
|
||||
(Reference code: FloatImage::alphaTestCoverage and FloatImage::scaleAlphaToCoverage:
|
||||
https://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvimage/FloatImage.cpp )
|
||||
@ -640,7 +653,7 @@ static float stbir__support_trapezoid(float scale)
|
||||
|
||||
static float stbir__filter_bilinear(float x, float s)
|
||||
{
|
||||
STBIR__UNUSED_PARAM(s)
|
||||
STBIR__UNUSED_PARAM(s);
|
||||
|
||||
x = (float)fabs(x);
|
||||
|
||||
@ -652,7 +665,7 @@ static float stbir__filter_bilinear(float x, float s)
|
||||
|
||||
static float stbir__filter_bicubic(float x, float s)
|
||||
{
|
||||
STBIR__UNUSED_PARAM(s)
|
||||
STBIR__UNUSED_PARAM(s);
|
||||
|
||||
x = (float)fabs(x);
|
||||
|
||||
@ -666,7 +679,7 @@ static float stbir__filter_bicubic(float x, float s)
|
||||
|
||||
static float stbir__filter_catmullrom(float x, float s)
|
||||
{
|
||||
STBIR__UNUSED_PARAM(s)
|
||||
STBIR__UNUSED_PARAM(s);
|
||||
|
||||
x = (float)fabs(x);
|
||||
|
||||
@ -680,7 +693,7 @@ static float stbir__filter_catmullrom(float x, float s)
|
||||
|
||||
static float stbir__filter_mitchell(float x, float s)
|
||||
{
|
||||
STBIR__UNUSED_PARAM(s)
|
||||
STBIR__UNUSED_PARAM(s);
|
||||
|
||||
x = (float)fabs(x);
|
||||
|
||||
@ -694,19 +707,19 @@ static float stbir__filter_mitchell(float x, float s)
|
||||
|
||||
static float stbir__support_zero(float s)
|
||||
{
|
||||
STBIR__UNUSED_PARAM(s)
|
||||
STBIR__UNUSED_PARAM(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static float stbir__support_one(float s)
|
||||
{
|
||||
STBIR__UNUSED_PARAM(s)
|
||||
STBIR__UNUSED_PARAM(s);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static float stbir__support_two(float s)
|
||||
{
|
||||
STBIR__UNUSED_PARAM(s)
|
||||
STBIR__UNUSED_PARAM(s);
|
||||
return 2;
|
||||
}
|
||||
|
||||
@ -1281,7 +1294,6 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef STBIR_NO_ALPHA_EPSILON
|
||||
if (!(stbir_info->flags & STBIR_FLAG_ALPHA_PREMULTIPLIED))
|
||||
{
|
||||
for (x = -stbir__get_filter_pixel_margin_horizontal(stbir_info); x < max_x; x++)
|
||||
@ -1290,11 +1302,12 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
||||
|
||||
// If the alpha value is 0 it will clobber the color values. Make sure it's not.
|
||||
float alpha = decode_buffer[decode_pixel_index + alpha_channel];
|
||||
#ifndef STBIR_NO_ALPHA_EPSILON
|
||||
if (stbir_info->type != STBIR_TYPE_FLOAT) {
|
||||
alpha += STBIR_ALPHA_EPSILON;
|
||||
decode_buffer[decode_pixel_index + alpha_channel] = alpha;
|
||||
}
|
||||
|
||||
#endif
|
||||
for (c = 0; c < channels; c++)
|
||||
{
|
||||
if (c == alpha_channel)
|
||||
@ -1304,7 +1317,6 @@ static void stbir__decode_scanline(stbir__info* stbir_info, int n)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (edge_horizontal == STBIR_EDGE_ZERO)
|
||||
{
|
||||
@ -1474,7 +1486,6 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void
|
||||
int x;
|
||||
int n;
|
||||
|
||||
#ifndef STBIR_NO_ALPHA_EPSILON
|
||||
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_PREMULTIPLIED))
|
||||
{
|
||||
for (x=0; x < num_pixels; ++x)
|
||||
@ -1492,7 +1503,6 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void
|
||||
// conversion.
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (decode)
|
||||
{
|
||||
|
@ -124,6 +124,23 @@ inline float mtfrand()
|
||||
return (float)(mtrand() % ninenine)/ninenine;
|
||||
}
|
||||
|
||||
static void resizer(int argc, char **argv)
|
||||
{
|
||||
unsigned char* input_pixels;
|
||||
unsigned char* output_pixels;
|
||||
int w, h;
|
||||
int n;
|
||||
int out_w, out_h;
|
||||
input_pixels = stbi_load(argv[1], &w, &h, &n, 0);
|
||||
out_w = w/4;
|
||||
out_h = h/4;
|
||||
output_pixels = (unsigned char*) malloc(out_w*out_h*n);
|
||||
//stbir_resize_uint8_srgb(input_pixels, w, h, 0, output_pixels, out_w, out_h, 0, n, -1,0);
|
||||
stbir_resize_uint8(input_pixels, w, h, 0, output_pixels, out_w, out_h, 0, n);
|
||||
stbi_write_png("output.png", out_w, out_h, n, output_pixels, 0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
void test_suite(int argc, char **argv);
|
||||
|
||||
@ -135,6 +152,8 @@ int main(int argc, char** argv)
|
||||
int n;
|
||||
int out_w, out_h, out_stride;
|
||||
|
||||
//resizer(argc, argv);
|
||||
|
||||
#if 1
|
||||
test_suite(argc, argv);
|
||||
return 0;
|
||||
@ -733,6 +752,12 @@ void test_filters(void)
|
||||
STBIR_ASSERT(output[2] == input[1]);
|
||||
}
|
||||
|
||||
// checkerboard
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
// Now for some fun.
|
||||
unsigned char input[2 * 1];
|
||||
|
Loading…
Reference in New Issue
Block a user