diff mbox series

[FFmpeg-devel,1/4] avcodec/mjpegdec: export display matrix frame side data when available

Message ID 20210908183426.53347-1-jamrial@gmail.com
State Accepted
Commit e93c9986027d17917c3b4f533b28ee4a2ce7cd4c
Headers show
Series [FFmpeg-devel,1/4] avcodec/mjpegdec: export display matrix frame side data when available | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed
andriy/make_ppc success Make finished
andriy/make_fate_ppc fail Make fate failed

Commit Message

James Almer Sept. 8, 2021, 6:34 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/mjpegdec.c | 53 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

Comments

Eoff, Ullysses A Sept. 21, 2021, 3:21 a.m. UTC | #1
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of James Almer
> Sent: Wednesday, September 08, 2021 11:34 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/mjpegdec: export display matrix frame side data when available
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/mjpegdec.c | 53 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
> 
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index 2a5868fe1d..7bec5ce221 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -30,6 +30,7 @@
>   * MJPEG decoder.
>   */
> 
> +#include "libavutil/display.h"
>  #include "libavutil/imgutils.h"
>  #include "libavutil/avassert.h"
>  #include "libavutil/opt.h"
> @@ -2406,6 +2407,7 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame)
>      int i, index;
>      int ret = 0;
>      int is16bit;
> +    AVDictionaryEntry *e = NULL;
> 
>      s->force_pal8 = 0;
> 
> @@ -2864,6 +2866,57 @@ the_end:
>          }
>      }
> 
> +    if (e = av_dict_get(s->exif_metadata, "Orientation", e, AV_DICT_IGNORE_SUFFIX)) {
> +        char *value = e->value + strspn(e->value, " \n\t\r"), *endptr;
> +        int orientation = strtol(value, &endptr, 0);
> +
> +        if (!*endptr) {
> +            AVFrameSideData *sd = NULL;
> +
> +            if (orientation >= 2 && orientation <= 8) {
> +                int32_t *matrix;
> +
> +                sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9);
> +                if (!sd) {
> +                    av_log(s->avctx, AV_LOG_ERROR, "Could not allocate frame side data\n");
> +                    return AVERROR(ENOMEM);
> +                }
> +
> +                matrix = (int32_t *)sd->data;
> +
> +                switch (orientation) {
> +                case 2:
> +                    av_display_rotation_set(matrix, 0.0);
> +                    av_display_matrix_flip(matrix, 1, 0);
> +                    break;
> +                case 3:
> +                    av_display_rotation_set(matrix, 180.0);
> +                    break;
> +                case 4:
> +                    av_display_rotation_set(matrix, 180.0);
> +                    av_display_matrix_flip(matrix, 1, 0);
> +                    break;
> +                case 5:
> +                    av_display_rotation_set(matrix, 90.0);
> +                    av_display_matrix_flip(matrix, 0, 1);
> +                    break;
> +                case 6:
> +                    av_display_rotation_set(matrix, 90.0);
> +                    break;
> +                case 7:
> +                    av_display_rotation_set(matrix, -90.0);
> +                    av_display_matrix_flip(matrix, 0, 1);
> +                    break;
> +                case 8:
> +                    av_display_rotation_set(matrix, -90.0);
> +                    break;
> +                default:
> +                    av_assert0(0);
> +                }
> +            }
> +        }
> +    }
> +
>      av_dict_copy(&frame->metadata, s->exif_metadata, 0);
>      av_dict_free(&s->exif_metadata);
> 

James, please see regression reported in https://trac.ffmpeg.org/ticket/9432

> --
> 2.33.0
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 2a5868fe1d..7bec5ce221 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -30,6 +30,7 @@ 
  * MJPEG decoder.
  */
 
+#include "libavutil/display.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/avassert.h"
 #include "libavutil/opt.h"
@@ -2406,6 +2407,7 @@  int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame)
     int i, index;
     int ret = 0;
     int is16bit;
+    AVDictionaryEntry *e = NULL;
 
     s->force_pal8 = 0;
 
@@ -2864,6 +2866,57 @@  the_end:
         }
     }
 
+    if (e = av_dict_get(s->exif_metadata, "Orientation", e, AV_DICT_IGNORE_SUFFIX)) {
+        char *value = e->value + strspn(e->value, " \n\t\r"), *endptr;
+        int orientation = strtol(value, &endptr, 0);
+
+        if (!*endptr) {
+            AVFrameSideData *sd = NULL;
+
+            if (orientation >= 2 && orientation <= 8) {
+                int32_t *matrix;
+
+                sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9);
+                if (!sd) {
+                    av_log(s->avctx, AV_LOG_ERROR, "Could not allocate frame side data\n");
+                    return AVERROR(ENOMEM);
+                }
+
+                matrix = (int32_t *)sd->data;
+
+                switch (orientation) {
+                case 2:
+                    av_display_rotation_set(matrix, 0.0);
+                    av_display_matrix_flip(matrix, 1, 0);
+                    break;
+                case 3:
+                    av_display_rotation_set(matrix, 180.0);
+                    break;
+                case 4:
+                    av_display_rotation_set(matrix, 180.0);
+                    av_display_matrix_flip(matrix, 1, 0);
+                    break;
+                case 5:
+                    av_display_rotation_set(matrix, 90.0);
+                    av_display_matrix_flip(matrix, 0, 1);
+                    break;
+                case 6:
+                    av_display_rotation_set(matrix, 90.0);
+                    break;
+                case 7:
+                    av_display_rotation_set(matrix, -90.0);
+                    av_display_matrix_flip(matrix, 0, 1);
+                    break;
+                case 8:
+                    av_display_rotation_set(matrix, -90.0);
+                    break;
+                default:
+                    av_assert0(0);
+                }
+            }
+        }
+    }
+
     av_dict_copy(&frame->metadata, s->exif_metadata, 0);
     av_dict_free(&s->exif_metadata);