aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/bmpenc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-02-13 01:39:11 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-02-13 02:06:44 +0100
commit4e04e1b81e4e31b7a11b3b5033ac97d2da3b866d (patch)
treec12bd6d0b08e93cecc67993391c0ff0c6caed991 /libavcodec/bmpenc.c
parentf51a0721604deb9aea230522e618b2c4769cad77 (diff)
parent3e23badd83edc021e8a830db109a08c5553988b0 (diff)
downloadffmpeg-4e04e1b81e4e31b7a11b3b5033ac97d2da3b866d.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: swscale: convert yuv2yuvX() to using named arguments. swscale: rename "dstw" to "w" to prevent name collisions. swscale: use named registers in yuv2yuv1_plane() place. lavf: fix aspect ratio mismatch message. avconv: set AVFormatContext.duration from '-t' cljr: implement encode2. cljr: set the properties of the coded_frame, not input frame. dnxhdenc: switch to encode2. bmpenc: switch to encode2(). Conflicts: libavcodec/bmpenc.c libavcodec/cljr.c libavformat/utils.c tests/ref/vsynth1/cljr tests/ref/vsynth2/cljr Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/bmpenc.c')
-rw-r--r--libavcodec/bmpenc.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/libavcodec/bmpenc.c b/libavcodec/bmpenc.c
index b457445321..4455af7d8c 100644
--- a/libavcodec/bmpenc.c
+++ b/libavcodec/bmpenc.c
@@ -25,6 +25,7 @@
#include "bytestream.h"
#include "bmp.h"
#include <assert.h>
+#include "internal.h"
static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF };
static const uint32_t rgb565_masks[] = { 0xF800, 0x07E0, 0x001F };
@@ -67,17 +68,17 @@ static av_cold int bmp_encode_init(AVCodecContext *avctx){
return 0;
}
-static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
+static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+ const AVFrame *pict, int *got_packet)
+{
BMPContext *s = avctx->priv_data;
- AVFrame *pict = data;
AVFrame * const p= (AVFrame*)&s->picture;
- int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize;
+ 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;
- unsigned char* buf0 = buf;
+ uint8_t *ptr, *buf;
*p = *pict;
p->pict_type= AV_PICTURE_TYPE_I;
p->key_frame= 1;
@@ -119,10 +120,11 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s
#define SIZE_BITMAPINFOHEADER 40
hsize = SIZE_BITMAPFILEHEADER + SIZE_BITMAPINFOHEADER + (pal_entries << 2);
n_bytes = n_bytes_image + hsize;
- if(n_bytes>buf_size) {
- av_log(avctx, AV_LOG_ERROR, "buf size too small (need %d, got %d)\n", n_bytes, buf_size);
- return -1;
+ if ((ret = ff_alloc_packet(pkt, n_bytes)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
+ return ret;
}
+ buf = pkt->data;
bytestream_put_byte(&buf, 'B'); // BITMAPFILEHEADER.bfType
bytestream_put_byte(&buf, 'M'); // do.
bytestream_put_le32(&buf, n_bytes); // BITMAPFILEHEADER.bfSize
@@ -144,7 +146,7 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s
bytestream_put_le32(&buf, pal[i] & 0xFFFFFF);
// BMP files are bottom-to-top so we start from the end...
ptr = p->data[0] + (avctx->height - 1) * p->linesize[0];
- buf = buf0 + hsize;
+ buf = pkt->data + hsize;
for(i = 0; i < avctx->height; i++) {
if (bit_count == 16) {
const uint16_t *src = (const uint16_t *) ptr;
@@ -159,7 +161,10 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s
buf += pad_bytes_per_row;
ptr -= p->linesize[0]; // ... and go back
}
- return n_bytes;
+
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ *got_packet = 1;
+ return 0;
}
AVCodec ff_bmp_encoder = {
@@ -168,7 +173,7 @@ AVCodec ff_bmp_encoder = {
.id = CODEC_ID_BMP,
.priv_data_size = sizeof(BMPContext),
.init = bmp_encode_init,
- .encode = bmp_encode_frame,
+ .encode2 = bmp_encode_frame,
.pix_fmts = (const enum PixelFormat[]){
PIX_FMT_BGRA, PIX_FMT_BGR24,
PIX_FMT_RGB565, PIX_FMT_RGB555, PIX_FMT_RGB444,