diff options
author | Andrew D'Addesio <modchipv12@gmail.com> | 2017-12-02 11:36:24 -0600 |
---|---|---|
committer | Rostislav Pehlivanov <atomnuker@gmail.com> | 2017-12-04 07:28:45 +0000 |
commit | 9b45bcf713e0bc30fff7d1e6c2facb539c27ec28 (patch) | |
tree | c49487b5946627050034b3774111bca3b637c77e /libavutil/common.h | |
parent | b73304f79eba9164162c7faf2c2d06e60728893c (diff) | |
download | ffmpeg-9b45bcf713e0bc30fff7d1e6c2facb539c27ec28.tar.gz |
libavutil: Add saturating subtraction functions
Add av_sat_sub32 and av_sat_dsub32 as the subtraction analogues to
av_sat_add32/av_sat_dadd32.
Also clarify the formulas for dadd32/dsub32.
Signed-off-by: Andrew D'Addesio <modchipv12@gmail.com>
Diffstat (limited to 'libavutil/common.h')
-rw-r--r-- | libavutil/common.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/libavutil/common.h b/libavutil/common.h index 8142b31fdb..5e0382827b 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -260,7 +260,7 @@ static av_always_inline int av_sat_add32_c(int a, int b) * * @param a first value * @param b value doubled and added to a - * @return sum with signed saturation + * @return sum sat(a + sat(2*b)) with signed saturation */ static av_always_inline int av_sat_dadd32_c(int a, int b) { @@ -268,6 +268,30 @@ static av_always_inline int av_sat_dadd32_c(int a, int b) } /** + * Subtract two signed 32-bit values with saturation. + * + * @param a one value + * @param b another value + * @return difference with signed saturation + */ +static av_always_inline int av_sat_sub32_c(int a, int b) +{ + return av_clipl_int32((int64_t)a - b); +} + +/** + * Subtract a doubled value from another value with saturation at both stages. + * + * @param a first value + * @param b value doubled and subtracted from a + * @return difference sat(a - sat(2*b)) with signed saturation + */ +static av_always_inline int av_sat_dsub32_c(int a, int b) +{ + return av_sat_sub32(a, av_sat_add32(b, b)); +} + +/** * Clip a float value into the amin-amax range. * @param a value to clip * @param amin minimum value of the clip range @@ -513,6 +537,12 @@ static av_always_inline av_const int av_parity_c(uint32_t v) #ifndef av_sat_dadd32 # define av_sat_dadd32 av_sat_dadd32_c #endif +#ifndef av_sat_sub32 +# define av_sat_sub32 av_sat_sub32_c +#endif +#ifndef av_sat_dsub32 +# define av_sat_dsub32 av_sat_dsub32_c +#endif #ifndef av_clipf # define av_clipf av_clipf_c #endif |