]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/exr.c
avcodec/decode: do not treat discarded frames as eof when draining
[ffmpeg] / libavcodec / exr.c
index 7cf3620d7f0d0e2138eb7ad9d913c719f241ae72..b37f91fa3f84104c24ce03bbe6b89444bca6e4cc 100644 (file)
 
 #include "avcodec.h"
 #include "bytestream.h"
+
+#if HAVE_BIGENDIAN
+#include "bswapdsp.h"
+#endif
+
 #include "get_bits.h"
 #include "internal.h"
 #include "mathops.h"
@@ -116,6 +121,10 @@ typedef struct EXRContext {
     AVFrame *picture;
     AVCodecContext *avctx;
 
+#if HAVE_BIGENDIAN
+    BswapDSPContext bbdsp;
+#endif
+
     enum ExrCompr compression;
     enum ExrPixelType pixel_type;
     int channel_offsets[4]; // 0 = red, 1 = green, 2 = blue and 3 = alpha
@@ -220,9 +229,9 @@ static union av_intfloat32 exr_half2float(uint16_t hf)
  *
  * @return normalized 16-bit unsigned int
  */
-static inline uint16_t exr_flt2uint(uint32_t v)
+static inline uint16_t exr_flt2uint(int32_t v)
 {
-    unsigned int exp = v >> 23;
+    int32_t exp = v >> 23;
     // "HACK": negative values result in exp<  0, so clipping them to 0
     // is also handled by this condition, avoids explicit check for sign bit.
     if (exp <= 127 + 7 - 24) // we would shift out all bits anyway
@@ -751,7 +760,8 @@ static int piz_uncompress(EXRContext *s, const uint8_t *src, int ssize,
     uint16_t maxval, min_non_zero, max_non_zero;
     uint16_t *ptr;
     uint16_t *tmp = (uint16_t *)td->tmp;
-    uint8_t *out;
+    uint16_t *out;
+    uint16_t *in;
     int ret, i, j;
     int pixel_half_size;/* 1 for half, 2 for float and uint32 */
     EXRChannel *channel;
@@ -803,12 +813,11 @@ static int piz_uncompress(EXRContext *s, const uint8_t *src, int ssize,
 
     apply_lut(td->lut, tmp, dsize / sizeof(uint16_t));
 
-    out = td->uncompressed_data;
+    out = (uint16_t *)td->uncompressed_data;
     for (i = 0; i < td->ysize; i++) {
         tmp_offset = 0;
         for (j = 0; j < s->nb_channels; j++) {
-            uint16_t *in;
-            EXRChannel *channel = &s->channels[j];
+            channel = &s->channels[j];
             if (channel->pixel_type == EXR_HALF)
                 pixel_half_size = 1;
             else
@@ -816,8 +825,13 @@ static int piz_uncompress(EXRContext *s, const uint8_t *src, int ssize,
 
             in = tmp + tmp_offset * td->xsize * td->ysize + i * td->xsize * pixel_half_size;
             tmp_offset += pixel_half_size;
+
+#if HAVE_BIGENDIAN
+            s->bbdsp.bswap16_buf(out, in, td->xsize * pixel_half_size);
+#else
             memcpy(out, in, td->xsize * 2 * pixel_half_size);
-            out += td->xsize * 2 * pixel_half_size;
+#endif
+            out += td->xsize * pixel_half_size;
         }
     }
 
@@ -1630,7 +1644,7 @@ static int decode_header(EXRContext *s, AVFrame *frame)
         return AVERROR_INVALIDDATA;
     }
 
-    av_frame_set_metadata(frame, metadata);
+    frame->metadata = metadata;
 
     // aaand we are done
     bytestream2_skip(&s->gb, 1);
@@ -1793,6 +1807,10 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     s->avctx              = avctx;
 
+#if HAVE_BIGENDIAN
+    ff_bswapdsp_init(&s->bbdsp);
+#endif
+
     trc_func = avpriv_get_trc_function_from_trc(s->apply_trc_type);
     if (trc_func) {
         for (i = 0; i < 65536; ++i) {