diff options
Diffstat (limited to 'libavcodec/bmpenc.c')
-rw-r--r-- | libavcodec/bmpenc.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/libavcodec/bmpenc.c b/libavcodec/bmpenc.c index a798f34..fc36028 100644 --- a/libavcodec/bmpenc.c +++ b/libavcodec/bmpenc.c @@ -3,24 +3,25 @@ * Copyright (c) 2006, 2007 Michel Bardiaux * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "libavutil/imgutils.h" +#include "libavutil/avassert.h" #include "avcodec.h" #include "bytestream.h" #include "bmp.h" @@ -37,6 +38,9 @@ static av_cold int bmp_encode_init(AVCodecContext *avctx){ avctx->coded_frame = &s->picture; switch (avctx->pix_fmt) { + case AV_PIX_FMT_BGRA: + avctx->bits_per_coded_sample = 32; + break; case AV_PIX_FMT_BGR24: avctx->bits_per_coded_sample = 24; break; @@ -71,6 +75,7 @@ static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, AVFrame * const p = &s->picture; int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize, ret; const uint32_t *pal = NULL; + uint32_t palette256[256]; int pad_bytes_per_row, pal_entries = 0, compression = BMP_RGB; int bit_count = avctx->bits_per_coded_sample; uint8_t *ptr, *buf; @@ -93,7 +98,10 @@ static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, case AV_PIX_FMT_RGB4_BYTE: case AV_PIX_FMT_BGR4_BYTE: case AV_PIX_FMT_GRAY8: - ff_set_systematic_pal2((uint32_t*)p->data[1], avctx->pix_fmt); + av_assert1(bit_count == 8); + ff_set_systematic_pal2(palette256, avctx->pix_fmt); + pal = palette256; + break; case AV_PIX_FMT_PAL8: pal = (uint32_t *)p->data[1]; break; @@ -112,10 +120,8 @@ static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, #define SIZE_BITMAPINFOHEADER 40 hsize = SIZE_BITMAPFILEHEADER + SIZE_BITMAPINFOHEADER + (pal_entries << 2); n_bytes = n_bytes_image + hsize; - if ((ret = ff_alloc_packet(pkt, n_bytes)) < 0) { - av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); + if ((ret = ff_alloc_packet2(avctx, pkt, n_bytes)) < 0) return ret; - } buf = pkt->data; bytestream_put_byte(&buf, 'B'); // BITMAPFILEHEADER.bfType bytestream_put_byte(&buf, 'M'); // do. @@ -167,8 +173,8 @@ AVCodec ff_bmp_encoder = { .init = bmp_encode_init, .encode2 = bmp_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ - AV_PIX_FMT_BGR24, - AV_PIX_FMT_RGB555, AV_PIX_FMT_RGB444, AV_PIX_FMT_RGB565, + AV_PIX_FMT_BGRA, AV_PIX_FMT_BGR24, + AV_PIX_FMT_RGB565, AV_PIX_FMT_RGB555, AV_PIX_FMT_RGB444, AV_PIX_FMT_RGB8, AV_PIX_FMT_BGR8, AV_PIX_FMT_RGB4_BYTE, AV_PIX_FMT_BGR4_BYTE, AV_PIX_FMT_GRAY8, AV_PIX_FMT_PAL8, AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_NONE |