38 #define ZMBV_KEYFRAME 1
39 #define ZMBV_DELTAPAL 2
86 uint8_t *src2,
int stride2,
int bw,
int bh,
91 uint16_t histogram[256] = {0};
92 int bw_bytes = bw *
c->bypp;
95 for(j = 0; j < bh; j++){
96 for(
i = 0;
i < bw_bytes;
i++){
97 int t =
src[
i] ^ src2[
i];
105 *xored = (histogram[0] < bw_bytes * bh);
108 if (!*xored)
return 0;
111 for(
i = 0;
i < 256;
i++)
112 sum +=
c->score_tab[histogram[
i]];
121 int pstride,
int x,
int y,
int *mx,
int *my,
int *xored)
123 int dx, dy, txored, tv,
bv, bw, bh;
138 tv =
block_cmp(
c,
src, sstride, prev + mx0 *
c->bypp + my0 * pstride, pstride, bw, bh, &txored);
149 for(dy = -
c->lrange; dy <= c->urange; dy++){
150 for(dx = -
c->lrange; dx <= c->urange; dx++){
151 if(!dx && !dy)
continue;
152 if(dx == mx0 && dy == my0)
continue;
153 tv =
block_cmp(
c,
src, sstride, prev + dx *
c->bypp + dy * pstride, pstride, bw, bh, &txored);
167 const AVFrame *pict,
int *got_packet)
170 const AVFrame *
const p = pict;
175 int work_size = 0, pkt_size;
179 keyframe = !
c->curfrm;
181 if(
c->curfrm ==
c->keyint)
183 #if FF_API_CODED_FRAME
191 chpal = !keyframe && palptr && memcmp(palptr,
c->pal2, 1024);
197 for(
i = 0;
i < 256;
i++){
199 c->work_buf[work_size++] = tpal[0] ^
c->pal[
i * 3 + 0];
200 c->work_buf[work_size++] = tpal[1] ^
c->pal[
i * 3 + 1];
201 c->work_buf[work_size++] = tpal[2] ^
c->pal[
i * 3 + 2];
202 c->pal[
i * 3 + 0] = tpal[0];
203 c->pal[
i * 3 + 1] = tpal[1];
204 c->pal[
i * 3 + 2] = tpal[2];
206 memcpy(
c->pal2, palptr, 1024);
210 for(
i = 0;
i < 256;
i++){
213 memcpy(
c->work_buf,
c->pal, 768);
214 memcpy(
c->pal2, palptr, 1024);
218 memcpy(
c->work_buf + work_size,
src, avctx->
width *
c->bypp);
220 work_size += avctx->
width *
c->bypp;
223 int x, y, bh2, bw2, xored;
230 mv =
c->work_buf + work_size;
231 memset(
c->work_buf + work_size, 0, (bw * bh * 2 + 3) & ~3);
232 work_size += (bw * bh * 2 + 3) & ~3;
239 tsrc =
src + x *
c->bypp;
240 tprev = prev + x *
c->bypp;
243 mv[0] = (mx * 2) | !!xored;
245 tprev += mx *
c->bypp + my *
c->pstride;
247 for(j = 0; j < bh2; j++){
248 for(
i = 0;
i < bw2 *
c->bypp;
i++)
249 c->work_buf[work_size++] = tsrc[
i] ^ tprev[
i];
263 memcpy(prev,
src, avctx->
width *
c->bypp);
269 deflateReset(&
c->zstream);
271 c->zstream.next_in =
c->work_buf;
272 c->zstream.avail_in = work_size;
273 c->zstream.total_in = 0;
275 c->zstream.next_out =
c->comp_buf;
276 c->zstream.avail_out =
c->comp_size;
277 c->zstream.total_out = 0;
278 if(
deflate(&
c->zstream, Z_SYNC_FLUSH) != Z_OK){
283 pkt_size =
c->zstream.total_out + 1 + 6*keyframe;
298 memcpy(buf,
c->comp_buf,
c->zstream.total_out);
313 deflateEnd(&
c->zstream);
328 int prev_size, prev_offset;
343 #ifdef ZMBV_ENABLE_24BPP
371 c->lrange =
c->urange = 8;
379 if(lvl < 0 || lvl > 9){
385 memset(&
c->zstream, 0,
sizeof(z_stream));
386 c->comp_size = avctx->
width *
c->bypp * avctx->
height + 1024 +
393 c->comp_size =
c->comp_size + ((
c->comp_size + 7) >> 3) +
394 ((
c->comp_size + 63) >> 6) + 11;
411 prev_size =
FFALIGN(
c->lrange *
c->bypp, 16) +
c->pstride * (
c->lrange + avctx->
height +
c->urange);
412 prev_offset =
FFALIGN(
c->lrange *
c->bypp, 16) +
c->pstride *
c->lrange;
417 c->prev =
c->prev_buf + prev_offset;
419 c->zstream.zalloc = Z_NULL;
420 c->zstream.zfree = Z_NULL;
421 c->zstream.opaque = Z_NULL;
422 zret = deflateInit(&
c->zstream, lvl);
443 #ifdef ZMBV_ENABLE_24BPP
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
common internal and external API header
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
static const int8_t mv[256][2]
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
static enum AVPixelFormat pix_fmts[]
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
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
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)
static av_cold int encode_init(AVCodecContext *avctx)
Init zmbv encoder.
static int block_cmp(ZmbvEncContext *c, uint8_t *src, int stride, uint8_t *src2, int stride2, int bw, int bh, int *xored)
Block comparing function XXX should be optimized and moved to DSPContext.
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static av_cold int encode_end(AVCodecContext *avctx)
static int zmbv_me(ZmbvEncContext *c, uint8_t *src, int sstride, uint8_t *prev, int pstride, int x, int y, int *mx, int *my, int *xored)
Motion estimation function TODO make better ME decisions.