[FFmpeg-cvslog] avcodec/exif/exif_add_metadata: add support for SSHORT & SBYTE

Michael Niedermayer git at videolan.org
Sun Apr 20 17:21:41 CEST 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Apr 20 02:58:02 2014 +0200| [a94de50ba02f5c260ca7c571b43fb595c8f951b6] | committer: Michael Niedermayer

avcodec/exif/exif_add_metadata: add support for SSHORT & SBYTE

No working testcase, this omission was just spoted when the parser apparently went out of
sync.

Reviewed-by; Thilo Borgmann <thilo.borgmann at mail.de>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a94de50ba02f5c260ca7c571b43fb595c8f951b6
---

 libavcodec/exif.c        |    6 ++++--
 libavcodec/tiff.c        |    2 +-
 libavcodec/tiff_common.c |   10 ++++++----
 libavcodec/tiff_common.h |    4 ++--
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavcodec/exif.c b/libavcodec/exif.c
index 984adaf..0f3f80c 100644
--- a/libavcodec/exif.c
+++ b/libavcodec/exif.c
@@ -48,9 +48,11 @@ static int exif_add_metadata(AVCodecContext *avctx, int count, int type,
 {
     switch(type) {
     case TIFF_DOUBLE   : return ff_tadd_doubles_metadata(count, name, sep, gb, le, metadata);
-    case TIFF_SHORT    : return ff_tadd_shorts_metadata(count, name, sep, gb, le, metadata);
+    case TIFF_SSHORT   : return ff_tadd_shorts_metadata(count, name, sep, gb, le, 1, metadata);
+    case TIFF_SHORT    : return ff_tadd_shorts_metadata(count, name, sep, gb, le, 0, metadata);
+    case TIFF_SBYTE    : return ff_tadd_bytes_metadata(count, name, sep, gb, le, 1, metadata);
     case TIFF_BYTE     :
-    case TIFF_UNDEFINED: return ff_tadd_bytes_metadata(count, name, sep, gb, le, metadata);
+    case TIFF_UNDEFINED: return ff_tadd_bytes_metadata(count, name, sep, gb, le, 0, metadata);
     case TIFF_STRING   : return ff_tadd_string_metadata(count, name, gb, le, metadata);
     case TIFF_SRATIONAL:
     case TIFF_RATIONAL : return ff_tadd_rational_metadata(count, name, sep, gb, le, metadata);
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index af1b4e0..c6193ad 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -221,7 +221,7 @@ static int add_metadata(int count, int type,
 {
     switch(type) {
     case TIFF_DOUBLE: return ff_tadd_doubles_metadata(count, name, sep, &s->gb, s->le, avpriv_frame_get_metadatap(frame));
-    case TIFF_SHORT : return ff_tadd_shorts_metadata(count, name, sep, &s->gb, s->le, avpriv_frame_get_metadatap(frame));
+    case TIFF_SHORT : return ff_tadd_shorts_metadata(count, name, sep, &s->gb, s->le, 0, avpriv_frame_get_metadatap(frame));
     case TIFF_STRING: return ff_tadd_string_metadata(count, name, &s->gb, s->le, avpriv_frame_get_metadatap(frame));
     default         : return AVERROR_INVALIDDATA;
     };
diff --git a/libavcodec/tiff_common.c b/libavcodec/tiff_common.c
index f14ecf1..35119af 100644
--- a/libavcodec/tiff_common.c
+++ b/libavcodec/tiff_common.c
@@ -176,7 +176,7 @@ int ff_tadd_doubles_metadata(int count, const char *name, const char *sep,
 
 
 int ff_tadd_shorts_metadata(int count, const char *name, const char *sep,
-                            GetByteContext *gb, int le, AVDictionary **metadata)
+                            GetByteContext *gb, int le, int is_signed, AVDictionary **metadata)
 {
     AVBPrint bp;
     char *ap;
@@ -190,7 +190,8 @@ int ff_tadd_shorts_metadata(int count, const char *name, const char *sep,
     av_bprint_init(&bp, 10 * count, AV_BPRINT_SIZE_UNLIMITED);
 
     for (i = 0; i < count; i++) {
-        av_bprintf(&bp, "%s%5i", auto_sep(count, sep, i, 8), ff_tget_short(gb, le));
+        int v = is_signed ? (int16_t)ff_tget_short(gb, le) :  ff_tget_short(gb, le);
+        av_bprintf(&bp, "%s%5i", auto_sep(count, sep, i, 8), v);
     }
 
     if ((i = av_bprint_finalize(&bp, &ap))) {
@@ -207,7 +208,7 @@ int ff_tadd_shorts_metadata(int count, const char *name, const char *sep,
 
 
 int ff_tadd_bytes_metadata(int count, const char *name, const char *sep,
-                           GetByteContext *gb, int le, AVDictionary **metadata)
+                           GetByteContext *gb, int le, int is_signed, AVDictionary **metadata)
 {
     AVBPrint bp;
     char *ap;
@@ -221,7 +222,8 @@ int ff_tadd_bytes_metadata(int count, const char *name, const char *sep,
     av_bprint_init(&bp, 10 * count, AV_BPRINT_SIZE_UNLIMITED);
 
     for (i = 0; i < count; i++) {
-        av_bprintf(&bp, "%s%3i", auto_sep(count, sep, i, 16), bytestream2_get_byte(gb));
+        int v = is_signed ? (int8_t)bytestream2_get_byte(gb) :  bytestream2_get_byte(gb);
+        av_bprintf(&bp, "%s%3i", auto_sep(count, sep, i, 16), v);
     }
 
     if ((i = av_bprint_finalize(&bp, &ap))) {
diff --git a/libavcodec/tiff_common.h b/libavcodec/tiff_common.h
index 01a7b08..16c9e50 100644
--- a/libavcodec/tiff_common.h
+++ b/libavcodec/tiff_common.h
@@ -121,13 +121,13 @@ int ff_tadd_doubles_metadata(int count, const char *name, const char *sep,
  *  into the metadata dictionary.
  */
 int ff_tadd_shorts_metadata(int count, const char *name, const char *sep,
-                            GetByteContext *gb, int le, AVDictionary **metadata);
+                            GetByteContext *gb, int le, int is_signed, AVDictionary **metadata);
 
 /** Adds count bytes converted to a string
  *  into the metadata dictionary.
  */
 int ff_tadd_bytes_metadata(int count, const char *name, const char *sep,
-                           GetByteContext *gb, int le, AVDictionary **metadata);
+                           GetByteContext *gb, int le, int is_signed, AVDictionary **metadata);
 
 /** Adds a string of count characters
  *  into the metadata dictionary.



More information about the ffmpeg-cvslog mailing list