avpicture_get_size() returns the size of buffer required for avpicture_layout.
For pseudo-paletted formats (gray8...) this size does not include the palette.
However, avpicture_layout doesn't know this and still writes the palette. Consequently,
avpicture_layout writes passed the length of the buffer. This fixes it
by fixing avpicture_layout so that it doesn't write the palette for these formats.
Signed-off-by: Matthew Einhorn <moiein2000@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
| ... | ... |
@@ -337,6 +337,16 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, |
| 337 | 337 |
} |
| 338 | 338 |
} |
| 339 | 339 |
|
| 340 |
+ switch (pix_fmt) {
|
|
| 341 |
+ case PIX_FMT_RGB8: |
|
| 342 |
+ case PIX_FMT_BGR8: |
|
| 343 |
+ case PIX_FMT_RGB4_BYTE: |
|
| 344 |
+ case PIX_FMT_BGR4_BYTE: |
|
| 345 |
+ case PIX_FMT_GRAY8: |
|
| 346 |
+ // do not include palette for these pseudo-paletted formats |
|
| 347 |
+ return size; |
|
| 348 |
+ } |
|
| 349 |
+ |
|
| 340 | 350 |
if (desc->flags & PIX_FMT_PAL) |
| 341 | 351 |
memcpy((unsigned char *)(((size_t)dest + 3) & ~3), src->data[1], 256 * 4); |
| 342 | 352 |
|