Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-04-25 02:43:26 +0300
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-05-05 13:31:09 +0300
commit6c69251b038944b4deee4e5fa7dd32b78492ae60 (patch)
tree5d85a676bd001745166881b24b967256c4b09e47 /libavcodec/bmpenc.c
parent1106f206453b8ab29f5b6972522def49d08e6288 (diff)
avcodec/bmpenc: Avoid copying packet data, allow user-supplied buffers
When the packet size is known in advance like here, one can avoid an intermediate buffer for the packet data; this also makes it easy to allow user-supplied buffers. Only one thing needed to be changed: One can no longer use a pointer to uint16_t for the destination buffer because its alignment is unknown. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/bmpenc.c')
-rw-r--r--libavcodec/bmpenc.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/libavcodec/bmpenc.c b/libavcodec/bmpenc.c
index 139ceb3844..557e0be285 100644
--- a/libavcodec/bmpenc.c
+++ b/libavcodec/bmpenc.c
@@ -25,6 +25,7 @@
#include "avcodec.h"
#include "bytestream.h"
#include "bmp.h"
+#include "encode.h"
#include "internal.h"
static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF };
@@ -112,7 +113,7 @@ 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_packet2(avctx, pkt, n_bytes, 0)) < 0)
+ if ((ret = ff_get_encode_buffer(avctx, pkt, n_bytes, 0)) < 0)
return ret;
buf = pkt->data;
bytestream_put_byte(&buf, 'B'); // BITMAPFILEHEADER.bfType
@@ -140,9 +141,8 @@ static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
for(i = 0; i < avctx->height; i++) {
if (bit_count == 16) {
const uint16_t *src = (const uint16_t *) ptr;
- uint16_t *dst = (uint16_t *) buf;
for(n = 0; n < avctx->width; n++)
- AV_WL16(dst + n, src[n]);
+ AV_WL16(buf + 2 * n, src[n]);
} else {
memcpy(buf, ptr, n_bytes_per_row);
}
@@ -162,6 +162,7 @@ const AVCodec ff_bmp_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("BMP (Windows and OS/2 bitmap)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_BMP,
+ .capabilities = AV_CODEC_CAP_DR1,
.init = bmp_encode_init,
.encode2 = bmp_encode_frame,
.pix_fmts = (const enum AVPixelFormat[]){