]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/bmpenc.c
Fix compilation with --disable-everything --enable-demuxer=flac (--disable-yasm).
[ffmpeg] / libavcodec / bmpenc.c
index 0bbbb613154e722279e088a99d578b22cd745ba8..11455cd18e49686ece230a1ce84c3f355714c40b 100644 (file)
@@ -3,20 +3,20 @@
  * 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
  */
 
@@ -24,6 +24,7 @@
 #include "avcodec.h"
 #include "bytestream.h"
 #include "bmp.h"
+#include <assert.h>
 #include "internal.h"
 
 static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF };
@@ -37,6 +38,9 @@ static av_cold int bmp_encode_init(AVCodecContext *avctx){
     avctx->coded_frame = &s->picture;
 
     switch (avctx->pix_fmt) {
+    case PIX_FMT_BGRA:
+        avctx->bits_per_coded_sample = 32;
+        break;
     case 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 PIX_FMT_RGB4_BYTE:
     case PIX_FMT_BGR4_BYTE:
     case PIX_FMT_GRAY8:
-        ff_set_systematic_pal2((uint32_t*)p->data[1], avctx->pix_fmt);
+        assert(bit_count == 8);
+        ff_set_systematic_pal2(palette256, avctx->pix_fmt);
+        pal = palette256;
+        break;
     case 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.
@@ -166,11 +172,12 @@ AVCodec ff_bmp_encoder = {
     .priv_data_size = sizeof(BMPContext),
     .init           = bmp_encode_init,
     .encode2        = bmp_encode_frame,
-    .pix_fmts = (const enum PixelFormat[]){
-        PIX_FMT_BGR24,
-        PIX_FMT_RGB555, PIX_FMT_RGB444, PIX_FMT_RGB565,
+    .pix_fmts       = (const enum PixelFormat[]){
+        PIX_FMT_BGRA, PIX_FMT_BGR24,
+        PIX_FMT_RGB565, PIX_FMT_RGB555, PIX_FMT_RGB444,
         PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8,
         PIX_FMT_MONOBLACK,
-        PIX_FMT_NONE},
-    .long_name = NULL_IF_CONFIG_SMALL("BMP image"),
+        PIX_FMT_NONE
+    },
+    .long_name      = NULL_IF_CONFIG_SMALL("BMP image"),
 };