39#define ZMBV_KEYFRAME 1
40#define ZMBV_DELTAPAL 2
87 const uint8_t *
src2,
int stride2,
int bw,
int bh,
92 uint16_t histogram[256] = {0};
93 int bw_bytes = bw *
c->bypp;
96 for(j = 0; j < bh; j++){
97 for(
i = 0;
i < bw_bytes;
i++){
106 *xored = (histogram[0] < bw_bytes * bh);
109 if (!*xored)
return 0;
112 for(
i = 0;
i < 256;
i++)
113 sum +=
c->score_tab[histogram[
i]];
122 int pstride,
int x,
int y,
int *
mx,
int *
my,
int *xored)
124 int dx, dy, txored, tv, bv, bw, bh;
133 bv =
block_cmp(
c,
src, sstride, prev, pstride, bw, bh, xored);
139 tv =
block_cmp(
c,
src, sstride, prev + mx0 *
c->bypp + my0 * pstride, pstride, bw, bh, &txored);
150 for(dy = -
c->lrange; dy <= c->urange; dy++){
151 for(dx = -
c->lrange; dx <= c->urange; dx++){
152 if(!dx && !dy)
continue;
153 if(dx == mx0 && dy == my0)
continue;
154 tv =
block_cmp(
c,
src, sstride, prev + dx *
c->bypp + dy * pstride, pstride, bw, bh, &txored);
168 const AVFrame *pict,
int *got_packet)
171 z_stream *
const zstream = &
c->zstream.zstream;
172 const AVFrame *
const p = pict;
178 int work_size = 0, pkt_size;
182 keyframe = !
c->curfrm;
184 if(
c->curfrm ==
c->keyint)
188 chpal = !keyframe && palptr && memcmp(palptr,
c->pal2, 1024);
194 for(
i = 0;
i < 256;
i++){
196 c->work_buf[work_size++] = tpal[0] ^
c->pal[
i * 3 + 0];
197 c->work_buf[work_size++] = tpal[1] ^
c->pal[
i * 3 + 1];
198 c->work_buf[work_size++] = tpal[2] ^
c->pal[
i * 3 + 2];
199 c->pal[
i * 3 + 0] = tpal[0];
200 c->pal[
i * 3 + 1] = tpal[1];
201 c->pal[
i * 3 + 2] = tpal[2];
203 memcpy(
c->pal2, palptr, 1024);
207 for(
i = 0;
i < 256;
i++){
210 memcpy(
c->work_buf,
c->pal, 768);
211 memcpy(
c->pal2, palptr, 1024);
215 memcpy(
c->work_buf + work_size,
src, avctx->
width *
c->bypp);
216 src += p->linesize[0];
217 work_size += avctx->
width *
c->bypp;
220 int x, y, bh2, bw2, xored;
221 const uint8_t *tsrc, *tprev;
227 mv =
c->work_buf + work_size;
228 memset(
c->work_buf + work_size, 0, (bw * bh * 2 + 3) & ~3);
229 work_size += (bw * bh * 2 + 3) & ~3;
236 tsrc =
src + x *
c->bypp;
237 tprev = prev + x *
c->bypp;
239 zmbv_me(
c, tsrc, p->linesize[0], tprev,
c->pstride, x, y, &
mx, &
my, &xored);
240 mv[0] = (
mx * 2) | !!xored;
242 tprev +=
mx *
c->bypp +
my *
c->pstride;
244 for(j = 0; j < bh2; j++){
245 for(
i = 0;
i < bw2 *
c->bypp;
i++)
246 c->work_buf[work_size++] = tsrc[
i] ^ tprev[
i];
247 tsrc += p->linesize[0];
260 memcpy(prev,
src, avctx->
width *
c->bypp);
262 src += p->linesize[0];
266 deflateReset(zstream);
268 zstream->next_in =
c->work_buf;
269 zstream->avail_in = work_size;
270 zstream->total_in = 0;
272 zstream->next_out =
c->comp_buf;
273 zstream->avail_out =
c->comp_size;
274 zstream->total_out = 0;
275 if (
deflate(zstream, Z_SYNC_FLUSH) != Z_OK) {
280 pkt_size = zstream->total_out + 1 + 6 * keyframe;
296 memcpy(buf,
c->comp_buf, zstream->total_out);
324 int prev_size, prev_offset;
339#ifdef ZMBV_ENABLE_24BPP
364 c->lrange =
c->urange = 8;
372 if(lvl < 0 || lvl > 9){
377 c->comp_size = avctx->
width *
c->bypp * avctx->
height + 1024 +
384 c->comp_size =
c->comp_size + ((
c->comp_size + 7) >> 3) +
385 ((
c->comp_size + 63) >> 6) + 11;
402 prev_size =
FFALIGN(
c->lrange *
c->bypp, 16) +
c->pstride * (
c->lrange + avctx->
height +
c->urange);
403 prev_offset =
FFALIGN(
c->lrange *
c->bypp, 16) +
c->pstride *
c->lrange;
408 c->prev =
c->prev_buf + prev_offset;
417#ifdef ZMBV_ENABLE_24BPP
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
const FFCodec ff_zmbv_encoder
static av_cold int encode_init(AVCodecContext *avctx)
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS_ARRAY(array)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int encode_end(AVCodecContext *avctx)
static const int8_t mv[256][2]
Memory handling functions.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int keyint_min
minimum GOP size
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int score_tab[ZMBV_BLOCK *ZMBV_BLOCK *4+1]
static void deflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
int ff_deflate_init(FFZStream *zstream, int level, void *logctx)
Wrapper around deflateInit().
void ff_deflate_end(FFZStream *zstream)
Wrapper around deflateEnd().
static av_cold int encode_init(AVCodecContext *avctx)
Init zmbv encoder.
static int zmbv_me(ZmbvEncContext *c, const uint8_t *src, int sstride, const uint8_t *prev, int pstride, int x, int y, int *mx, int *my, int *xored)
Motion estimation function TODO make better ME decisions.
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static enum AVPixelFormat zmbv_pixfmts_list[]
static av_cold int encode_end(AVCodecContext *avctx)
static int block_cmp(ZmbvEncContext *c, const uint8_t *src, int stride, const uint8_t *src2, int stride2, int bw, int bh, int *xored)
Block comparing function XXX should be optimized and moved to DSPContext.