summaryrefslogtreecommitdiff
path: root/libavutil/imgutils.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2014-04-28 16:08:33 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2014-06-20 10:39:33 -0400
commit9e500efdbe0deeff1602500ebc229a0a6b6bb1a2 (patch)
treeab9fefcc3d3bab4d2a75f427e96587fd61ec2770 /libavutil/imgutils.c
parentd349afb07bacccb62eb5369c38d6406d2909d792 (diff)
Add av_image_check_sar() and use it to validate SAR
Diffstat (limited to 'libavutil/imgutils.c')
-rw-r--r--libavutil/imgutils.c23
1 files changed, 23 insertions, 0 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)