resampler prototypes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parent 63cce5c · Browse files · 1 file·+66 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+66 added−0 removed
- other:+66 added−0 removed
Provenance
- Commit
c27ccec- Tree
59bd47d- Author
Sean Barrett <sean2@nothings.org>- Committer
Sean Barrett <sean2@nothings.org>- Parent
63cce5c
1 file changed+66 added−0 removed
modified:docs/stb_resample_ideas.txt+66 added
58 unmodified lines59 horizontal axis.60 61 62 63+Function prototypes:64+65+the highest-level one could be:66+67+ stb_resample_8bit(uint8_t *dest, int dest_width, int dest_height,68+ uint8_t const *src , int src_width, int src_height,69+ int channels,70+ stbr_filter filter);71+72+the lowest-level one could be:73+74+ stb_resample_arbitrary(void *dest, stbr_type dest_type, int dest_width, int dest_height, int dest_stride_in_bytes,75+ void const *src , stbr_type src_type, int src_width, int src_height, int src_stride_in_bytes,76+ int channels,77+ int nonpremul_alpha_channel_index,78+ stbr_wrapmode wrap, // clamp, wrap, mirror79+ stbr_filter filter,80+ float s0, float t0, float s1, float t1, // range of source to use, 0..1 in GPU texture-coordinate style81+ void *tempmem, size_t tempmem_size_in_bytes);82+83+And there would be a bunch of convenience functions at in-between levels.84+85+86+Some notes:87+88+ Intermediate-level functions should be provided for each source type & same dest type89+ so that the code is typesafe; only when people fall back to stb_resample_arbitrary should90+ they be at risk for type unsafety. (One way to deal with the explosion of functions of91+ every possible type would be to define one function for each input type, and accept three92+ separate output pointers, one for each type, only one of which can be non-NULL.)93+94+ nonpremul_alpha_channel_index:95+ if this is negative, no channels are processed specially96+ if this is non-negative, then it's the index of the alpha channel,97+ and the image should be treated as non-premultiplied alpha that98+ needs to be resampled accounting for this (weight the sampling99+ by the alpha channel, i.e. premultiply, filter, unpremultiply).100+ this mechanism only allows one alpha channel and ALL channels 101+ are scaled by it; an alternative would be to find some way to102+ pass in which channels serve as alpha channels for which other103+ channels, but eh.104+105+ s0,t0,s1,t1:106+ this allows fine subpixel-positioning and subpixel-resizing in an explicit way without107+ things having to be exact pixel multiples. it allows people to pseudo-stream108+ images by computing "tiles" of images a bit at a time without forcing those109+ tiles to quantize their source data.110+111+ tempmem, tempmem_size112+ all functions will needed tempmem, but they can allocate a fixed tempmem buffer113+ on the stack. providing an API that allows overriding the amount of tempmem114+ available allows people to process arbitrarily large images. the return115+ value for the function could be 0 on success or non-0 being the size of116+ tempmem needed.117+ 118+119+120+121+Reference:122+123+Cubic sampling function for seperable cubic:124+ f(x) = (a+2)*x^3 - (a+3)*x^2 + 1 for 0 <= x <= 1125+ f(x) = a*x^3 - 5*a*x^2 + 8*a*x - 4*a for 1 < x <= 2126+ f(x) = 0 otherwise127+ "a" is configurable, try -1/2 (from http://pixinsight.com/forum/index.php?topic=556.0 )128+