Browse code

avutil/imgutils: remove special case for aligning the palette

This was suggested by wm4 and stefano.
After this patch using align=1 the size used by various functions would not
contain padding, while the palette would be aligned at align>1

This patch makes it required to use align>=4 if the palette is to be accessed
as uint32

As a side-effect It fixes storing pal8 in nut with odd with&height

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Michael Niedermayer authored on 2016/02/14 23:22:47
Showing 2 changed files
... ...
@@ -125,7 +125,6 @@ int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int hei
125 125
 
126 126
     if (desc->flags & AV_PIX_FMT_FLAG_PAL ||
127 127
         desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
128
-        size[0] = (size[0] + 3) & ~3;
129 128
         data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */
130 129
         return size[0] + 256 * 4;
131 130
     }
... ...
@@ -216,8 +215,13 @@ int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
216 216
         av_free(buf);
217 217
         return ret;
218 218
     }
219
-    if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL)
219
+    if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
220 220
         avpriv_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt);
221
+        if (align < 4) {
222
+            av_log(NULL, AV_LOG_ERROR, "Formats with a palette require a minimum alignment of 4\n");
223
+            return AVERROR(EINVAL);
224
+        }
225
+    }
221 226
 
222 227
     if ((desc->flags & AV_PIX_FMT_FLAG_PAL ||
223 228
          desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) &&
... ...
@@ -385,7 +389,6 @@ int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
385 385
     int i, j, nb_planes = 0, linesize[4];
386 386
     int size = av_image_get_buffer_size(pix_fmt, width, height, align);
387 387
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
388
-    uint8_t *orig_dst = dst;
389 388
 
390 389
     if (size > dst_size || size < 0 || !desc)
391 390
         return AVERROR(EINVAL);
... ...
@@ -409,10 +412,7 @@ int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
409 409
     }
410 410
 
411 411
     if (desc->flags & AV_PIX_FMT_FLAG_PAL) {
412
-        uint32_t *d32 = (uint32_t *)(((size_t)dst + 3) & ~3);
413
-
414
-        if (dst_size - 1024 < (uint8_t*)d32 - orig_dst)
415
-            d32 = (uint32_t *)dst;
412
+        uint32_t *d32 = (uint32_t *)dst;
416 413
 
417 414
         for (i = 0; i<256; i++)
418 415
             AV_WL32(d32 + i, AV_RN32(src_data[1] + 4*i));
... ...
@@ -65,7 +65,7 @@
65 65
 
66 66
 #define LIBAVUTIL_VERSION_MAJOR  55
67 67
 #define LIBAVUTIL_VERSION_MINOR  17
68
-#define LIBAVUTIL_VERSION_MICRO 102
68
+#define LIBAVUTIL_VERSION_MICRO 103
69 69
 
70 70
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
71 71
                                                LIBAVUTIL_VERSION_MINOR, \