-static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- 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;
- uint8_t *ptr;
- unsigned char* buf0 = buf;
- *p = *pict;
- p->pict_type= FF_I_TYPE;
- p->key_frame= 1;
- n_bytes_per_row = (avctx->width*3 + 3) & ~3;
- n_bytes_image = avctx->height*n_bytes_per_row;
+static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+ const AVFrame *pict, int *got_packet)
+{
+ const AVFrame * const p = pict;
+ int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize, ret;
+ const uint32_t *pal = NULL;
+ int pad_bytes_per_row, pal_entries = 0, compression = BMP_RGB;
+ int bit_count = avctx->bits_per_coded_sample;
+ uint8_t *ptr, *buf;
+
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
+ avctx->coded_frame->key_frame = 1;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ switch (avctx->pix_fmt) {
+ case AV_PIX_FMT_RGB444:
+ compression = BMP_BITFIELDS;
+ pal = rgb444_masks; // abuse pal to hold color masks
+ pal_entries = 3;
+ break;
+ case AV_PIX_FMT_RGB565:
+ compression = BMP_BITFIELDS;
+ pal = rgb565_masks; // abuse pal to hold color masks
+ pal_entries = 3;
+ break;
+ case AV_PIX_FMT_RGB8:
+ case AV_PIX_FMT_BGR8:
+ case AV_PIX_FMT_RGB4_BYTE:
+ case AV_PIX_FMT_BGR4_BYTE:
+ case AV_PIX_FMT_GRAY8:
+ avpriv_set_systematic_pal2((uint32_t*)p->data[1], avctx->pix_fmt);
+ case AV_PIX_FMT_PAL8:
+ pal = (uint32_t *)p->data[1];
+ break;
+ case AV_PIX_FMT_MONOBLACK:
+ pal = monoblack_pal;
+ break;
+ }
+ if (pal && !pal_entries) pal_entries = 1 << bit_count;
+ n_bytes_per_row = ((int64_t)avctx->width * (int64_t)bit_count + 7LL) >> 3LL;
+ pad_bytes_per_row = (4 - n_bytes_per_row) & 3;
+ n_bytes_image = avctx->height * (n_bytes_per_row + pad_bytes_per_row);