#include "avcodec.h"
#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 };
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;
.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_BGR24,
- PIX_FMT_RGB555, PIX_FMT_RGB444, PIX_FMT_RGB565,
+ 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},
*/
#include "avcodec.h"
+#include "libavutil/opt.h"
#include "get_bits.h"
+ #include "internal.h"
#include "put_bits.h"
typedef struct CLJRContext {
#endif
#if CONFIG_CLJR_ENCODER
- static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
- int buf_size, void *data)
+ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+ const AVFrame *p, int *got_packet)
{
+ CLJRContext *a = avctx->priv_data;
PutBitContext pb;
- AVFrame *p = data;
- int x, y;
+ int x, y, ret;
+ uint32_t dither= avctx->frame_number;
+ static const uint32_t ordered_dither[2][2] =
+ {
+ { 0x10400000, 0x104F0000 },
+ { 0xCB2A0000, 0xCB250000 },
+ };
- p->pict_type = AV_PICTURE_TYPE_I;
- p->key_frame = 1;
+ if ((ret = ff_alloc_packet(pkt, 32*avctx->height*avctx->width/4)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
+ return ret;
+ }
+
+ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
+ avctx->coded_frame->key_frame = 1;
- init_put_bits(&pb, buf, buf_size / 8);
+ init_put_bits(&pb, pkt->data, pkt->size);
for (y = 0; y < avctx->height; y++) {
uint8_t *luma = &p->data[0][y * p->linesize[0]];
flush_put_bits(&pb);
- return put_bits_count(&pb) / 8;
+ pkt->size = put_bits_count(&pb) / 8;
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ *got_packet = 1;
+ return 0;
}
+#define OFFSET(x) offsetof(CLJRContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "dither_type", "Dither type", OFFSET(dither_type), AV_OPT_TYPE_INT, { .dbl=1 }, 0, 2, VE},
+ { NULL },
+};
+
+static const AVClass class = {
+ .class_name = "cljr encoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_cljr_encoder = {
.name = "cljr",
.type = AVMEDIA_TYPE_VIDEO,