Skip to content
Myr

more resampler notes

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 c27ccec · Browse files · 1 file+27 added−10 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+27 added−10 removed

  • other:+27 added−10 removed

1 file+27 added−10 removed

modified:docs/stb_resample_ideas.txt+27 added-10 removed
69 unmodified lines
70 stbr_filter filter);7172the lowest-level one could be:7374 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,74 stb_resample_arbitrary(void *dst, stbr_type dst_type, int dst_width, int dst_height, int dst_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);8283And there would be a bunch of convenience functions at in-between levels.83And there would be a bunch of convenience functions in-between those two levels.848586Some notes:8788 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.)9388 nonpremul_alpha_channel_index:89 if this is negative, no channels are processed specially90 if this is non-negative, then it's the index of the alpha channel,91 and the image should be treated as non-premultiplied alpha that
9 unmodified lines
101 things having to be exact pixel multiples. it allows people to pseudo-stream102 images by computing "tiles" of images a bit at a time without forcing those103 tiles to quantize their source data.104111 tempmem, tempmem_size105 tempmem, tempmem_size:106 all functions will needed tempmem, but they can allocate a fixed tempmem buffer107 on the stack. providing an API that allows overriding the amount of tempmem108 available allows people to process arbitrarily large images. the return109 value for the function could be 0 on success or non-0 being the size of110 tempmem needed.111 112 src_stride, dest_stride:113 the stride variables are signed to allow you to describe both traditional114 top-to-bottom images (pass in a pointer to the top-left pixel and115 a positive stride) and bottom-to-top images (pass in a pointer to116 the bottom-left pixel and a negative stride)117118 ordering of src & dest:119 put these in whatever order you like, i just chose one arbitrarily120121 width & height122 these are ints not unsigned ints or size_ts because i personally forbid123 unsigned variables for almost everything to avoid signed/unsigned comparison124 issues, but this is a matter of personal taste and you can do differently125126 Intermediate-level functions should be provided for each source type & same dest type127 so that the code is typesafe; only when people fall back to stb_resample_arbitrary should128 they be at risk for type unsafety. (One way to deal avoid an explosion of functions of129 every possible *combination* of types in a type-safe way would be to define one function130 for each input type, and accept three separate output pointers, one for each type, only131 one of which can be non-NULL. 9 functions isn't that bad, but if you want to have three132 or four intermediate-level functions with fewer parameters, 9*4 gets silly. Could also133 use the same trick for stb_resample_arbitrary, replacing it with three typesafe functions.)134135136137138Reference:139140Cubic sampling function for seperable cubic:141 f(x) = (a+2)*x^3 - (a+3)*x^2 + 1 for 0 <= x <= 1
4 unmodified lines