diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2009-02-06 12:59:50 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2009-02-06 12:59:50 +0000 |
commit | 6337178b4f5c80e4dde5fda2b9a278ee1368b93a (patch) | |
tree | 74a2f1036123aa221a27c1365820eb5464ee69e0 /libavcodec/imgconvert.c | |
parent | 9a77d59a89fd73d8ad1027da3b40b434a0708e6a (diff) | |
download | ffmpeg-6337178b4f5c80e4dde5fda2b9a278ee1368b93a.tar.gz |
Ensure that the palette is set in data[1] for all 8bit formats.
Also document it.
Originally committed as revision 17018 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/imgconvert.c')
-rw-r--r-- | libavcodec/imgconvert.c | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c index a78b454a67..7e52ea384d 100644 --- a/libavcodec/imgconvert.c +++ b/libavcodec/imgconvert.c @@ -443,6 +443,43 @@ void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt) } } +int ff_set_systematic_pal(uint32_t pal[256], enum PixelFormat pix_fmt){ + int i; + + for(i=0; i<256; i++){ + int r,g,b; + + switch(pix_fmt) { + case PIX_FMT_RGB8: + r= (i>>5 )*36; + g= ((i>>2)&7)*36; + b= (i&3 )*85; + break; + case PIX_FMT_BGR8: + b= (i>>6 )*85; + g= ((i>>3)&7)*36; + r= (i&7 )*36; + break; + case PIX_FMT_RGB4_BYTE: + r= (i>>3 )*255; + g= ((i>>1)&3)*85; + b= (i&1 )*255; + break; + case PIX_FMT_BGR4_BYTE: + b= (i>>3 )*255; + g= ((i>>1)&3)*85; + r= (i&1 )*255; + break; + case PIX_FMT_GRAY8: + r=b=g= i; + break; + } + pal[i] = b + (g<<8) + (r<<16); + } + + return 0; +} + int ff_fill_linesize(AVPicture *picture, int pix_fmt, int width) { int w2; @@ -505,13 +542,6 @@ int ff_fill_linesize(AVPicture *picture, int pix_fmt, int width) case PIX_FMT_UYYVYY411: picture->linesize[0] = width + width/2; break; - case PIX_FMT_RGB8: - case PIX_FMT_BGR8: - case PIX_FMT_RGB4_BYTE: - case PIX_FMT_BGR4_BYTE: - case PIX_FMT_GRAY8: - picture->linesize[0] = width; - break; case PIX_FMT_RGB4: case PIX_FMT_BGR4: picture->linesize[0] = width / 2; @@ -521,6 +551,11 @@ int ff_fill_linesize(AVPicture *picture, int pix_fmt, int width) picture->linesize[0] = (width + 7) >> 3; break; case PIX_FMT_PAL8: + case PIX_FMT_RGB8: + case PIX_FMT_BGR8: + case PIX_FMT_RGB4_BYTE: + case PIX_FMT_BGR4_BYTE: + case PIX_FMT_GRAY8: picture->linesize[0] = width; picture->linesize[1] = 4; break; @@ -588,11 +623,6 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, int pix_fmt, case PIX_FMT_YUYV422: case PIX_FMT_UYVY422: case PIX_FMT_UYYVYY411: - case PIX_FMT_RGB8: - case PIX_FMT_BGR8: - case PIX_FMT_RGB4_BYTE: - case PIX_FMT_BGR4_BYTE: - case PIX_FMT_GRAY8: case PIX_FMT_RGB4: case PIX_FMT_BGR4: case PIX_FMT_MONOWHITE: @@ -603,6 +633,11 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, int pix_fmt, picture->data[3] = NULL; return size; case PIX_FMT_PAL8: + case PIX_FMT_RGB8: + case PIX_FMT_BGR8: + case PIX_FMT_RGB4_BYTE: + case PIX_FMT_BGR4_BYTE: + case PIX_FMT_GRAY8: size2 = (size + 3) & ~3; picture->data[0] = ptr; picture->data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */ @@ -2000,6 +2035,9 @@ int avpicture_alloc(AVPicture *picture, if (!ptr) goto fail; avpicture_fill(picture, ptr, pix_fmt, width, height); + if(picture->data[1] && !picture->data[2]) + ff_set_systematic_pal((uint32_t*)picture->data[1], pix_fmt); + return 0; fail: memset(picture, 0, sizeof(AVPicture)); |