diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2014-04-28 16:08:33 -0400 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2014-06-20 10:39:33 -0400 |
commit | 9e500efdbe0deeff1602500ebc229a0a6b6bb1a2 (patch) | |
tree | ab9fefcc3d3bab4d2a75f427e96587fd61ec2770 /libavutil | |
parent | d349afb07bacccb62eb5369c38d6406d2909d792 (diff) | |
download | ffmpeg-9e500efdbe0deeff1602500ebc229a0a6b6bb1a2.tar.gz |
Add av_image_check_sar() and use it to validate SAR
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/imgutils.c | 23 | ||||
-rw-r--r-- | libavutil/imgutils.h | 15 | ||||
-rw-r--r-- | libavutil/version.h | 2 |
3 files changed, 39 insertions, 1 deletions
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c index 813724bea7..fc367d921b 100644 --- a/libavutil/imgutils.c +++ b/libavutil/imgutils.c @@ -25,7 +25,9 @@ #include "imgutils.h" #include "internal.h" #include "log.h" +#include "mathematics.h" #include "pixdesc.h" +#include "rational.h" void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc) @@ -228,6 +230,27 @@ int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *lo return AVERROR(EINVAL); } +int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar) +{ + int64_t scaled_dim; + + if (!sar.den) + return AVERROR(EINVAL); + + if (!sar.num || sar.num == sar.den) + return 0; + + if (sar.num < sar.den) + scaled_dim = av_rescale_rnd(w, sar.num, sar.den, AV_ROUND_ZERO); + else + scaled_dim = av_rescale_rnd(h, sar.den, sar.num, AV_ROUND_ZERO); + + if (scaled_dim > 0) + return 0; + + return AVERROR(EINVAL); +} + void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height) diff --git a/libavutil/imgutils.h b/libavutil/imgutils.h index 71510132ae..313037ae76 100644 --- a/libavutil/imgutils.h +++ b/libavutil/imgutils.h @@ -29,6 +29,7 @@ #include "avutil.h" #include "pixdesc.h" +#include "rational.h" /** * Compute the max pixel step for each plane of an image with a @@ -128,6 +129,20 @@ void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], */ int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx); +/** + * Check if the given sample aspect ratio of an image is valid. + * + * It is considered invalid if the denominator is 0 or if applying the ratio + * to the image size would make the smaller dimension less than 1. If the + * sar numerator is 0, it is considered unknown and will return as valid. + * + * @param w width of the image + * @param h height of the image + * @param sar sample aspect ratio of the image + * @return 0 if valid, a negative AVERROR code otherwise + */ +int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar); + int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt); /** diff --git a/libavutil/version.h b/libavutil/version.h index 427409f875..a4384b3ea6 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -54,7 +54,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 53 -#define LIBAVUTIL_VERSION_MINOR 16 +#define LIBAVUTIL_VERSION_MINOR 17 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |