aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-06-20 22:20:28 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-06-20 22:20:28 +0200
commit0dceefc5fa81a6c851b51acab695a8c149ec8e3b (patch)
treed26bf3f752e6fa622d14f44e091930004b2d12de /libavutil
parent329898aa45f5f8e8b89386ecd40b8db96746d53c (diff)
parent9e500efdbe0deeff1602500ebc229a0a6b6bb1a2 (diff)
downloadffmpeg-0dceefc5fa81a6c851b51acab695a8c149ec8e3b.tar.gz
Merge commit '9e500efdbe0deeff1602500ebc229a0a6b6bb1a2'
* commit '9e500efdbe0deeff1602500ebc229a0a6b6bb1a2': Add av_image_check_sar() and use it to validate SAR Conflicts: libavcodec/dpx.c libavcodec/dvdec.c libavcodec/ffv1dec.c libavcodec/utils.c libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/imgutils.c23
-rw-r--r--libavutil/imgutils.h15
-rw-r--r--libavutil/version.h2
3 files changed, 39 insertions, 1 deletions
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 274099b75f..00b203182b 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -27,7 +27,9 @@
#include "internal.h"
#include "intreadwrite.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)
@@ -239,6 +241,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 ab32d667d3..775baaa3b7 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
@@ -190,6 +191,20 @@ int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
*/
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 1b6053cfaf..b5dfc97f7b 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -56,7 +56,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 89
+#define LIBAVUTIL_VERSION_MINOR 90
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \