Go to the documentation of this file.
39 #define ZMBV_KEYFRAME 1
40 #define ZMBV_DELTAPAL 2
88 uint8_t *src2,
int stride2,
int bw,
int bh,
93 uint16_t histogram[256] = {0};
94 int bw_bytes = bw *
c->bypp;
97 for(j = 0; j < bh; j++){
98 for(
i = 0;
i < bw_bytes;
i++){
99 int t =
src[
i] ^ src2[
i];
107 *xored = (histogram[0] < bw_bytes * bh);
110 if (!*xored)
return 0;
113 for(
i = 0;
i < 256;
i++)
114 sum +=
c->score_tab[histogram[
i]];
123 int pstride,
int x,
int y,
int *mx,
int *my,
int *xored)
125 int dx, dy, txored, tv, bv, bw, bh;
134 bv =
block_cmp(
c,
src, sstride, prev, pstride, bw, bh, xored);
140 tv =
block_cmp(
c,
src, sstride, prev + mx0 *
c->bypp + my0 * pstride, pstride, bw, bh, &txored);
151 for(dy = -
c->lrange; dy <= c->urange; dy++){
152 for(dx = -
c->lrange; dx <= c->urange; dx++){
153 if(!dx && !dy)
continue;
154 if(dx == mx0 && dy == my0)
continue;
155 tv =
block_cmp(
c,
src, sstride, prev + dx *
c->bypp + dy * pstride, pstride, bw, bh, &txored);
169 const AVFrame *pict,
int *got_packet)
172 const AVFrame *
const p = pict;
173 uint8_t *
src, *prev, *buf;
177 int work_size = 0, pkt_size;
181 keyframe = !
c->curfrm;
183 if(
c->curfrm ==
c->keyint)
187 chpal = !keyframe && palptr && memcmp(palptr,
c->pal2, 1024);
193 for(
i = 0;
i < 256;
i++){
195 c->work_buf[work_size++] = tpal[0] ^
c->pal[
i * 3 + 0];
196 c->work_buf[work_size++] = tpal[1] ^
c->pal[
i * 3 + 1];
197 c->work_buf[work_size++] = tpal[2] ^
c->pal[
i * 3 + 2];
198 c->pal[
i * 3 + 0] = tpal[0];
199 c->pal[
i * 3 + 1] = tpal[1];
200 c->pal[
i * 3 + 2] = tpal[2];
202 memcpy(
c->pal2, palptr, 1024);
206 for(
i = 0;
i < 256;
i++){
209 memcpy(
c->work_buf,
c->pal, 768);
210 memcpy(
c->pal2, palptr, 1024);
214 memcpy(
c->work_buf + work_size,
src, avctx->
width *
c->bypp);
216 work_size += avctx->
width *
c->bypp;
219 int x, y, bh2, bw2, xored;
220 uint8_t *tsrc, *tprev;
226 mv =
c->work_buf + work_size;
227 memset(
c->work_buf + work_size, 0, (bw * bh * 2 + 3) & ~3);
228 work_size += (bw * bh * 2 + 3) & ~3;
235 tsrc =
src + x *
c->bypp;
236 tprev = prev + x *
c->bypp;
239 mv[0] = (mx * 2) | !!xored;
241 tprev += mx *
c->bypp + my *
c->pstride;
243 for(j = 0; j < bh2; j++){
244 for(
i = 0;
i < bw2 *
c->bypp;
i++)
245 c->work_buf[work_size++] = tsrc[
i] ^ tprev[
i];
259 memcpy(prev,
src, avctx->
width *
c->bypp);
265 deflateReset(&
c->zstream);
267 c->zstream.next_in =
c->work_buf;
268 c->zstream.avail_in = work_size;
269 c->zstream.total_in = 0;
271 c->zstream.next_out =
c->comp_buf;
272 c->zstream.avail_out =
c->comp_size;
273 c->zstream.total_out = 0;
274 if(
deflate(&
c->zstream, Z_SYNC_FLUSH) != Z_OK){
279 pkt_size =
c->zstream.total_out + 1 + 6*keyframe;
295 memcpy(buf,
c->comp_buf,
c->zstream.total_out);
311 deflateEnd(&
c->zstream);
325 int prev_size, prev_offset;
340 #ifdef ZMBV_ENABLE_24BPP
345 #endif //ZMBV_ENABLE_24BPP
365 c->lrange =
c->urange = 8;
373 if(lvl < 0 || lvl > 9){
378 c->comp_size = avctx->
width *
c->bypp * avctx->
height + 1024 +
385 c->comp_size =
c->comp_size + ((
c->comp_size + 7) >> 3) +
386 ((
c->comp_size + 63) >> 6) + 11;
403 prev_size =
FFALIGN(
c->lrange *
c->bypp, 16) +
c->pstride * (
c->lrange + avctx->
height +
c->urange);
404 prev_offset =
FFALIGN(
c->lrange *
c->bypp, 16) +
c->pstride *
c->lrange;
409 c->prev =
c->prev_buf + prev_offset;
411 c->zstream.zalloc = Z_NULL;
412 c->zstream.zfree = Z_NULL;
413 c->zstream.opaque = Z_NULL;
414 zret = deflateInit(&
c->zstream, lvl);
437 #ifdef ZMBV_ENABLE_24BPP
439 #endif //ZMBV_ENABLE_24BPP
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
AVPixelFormat
Pixel format.
const AVCodec ff_zmbv_encoder
int keyint_min
minimum GOP size
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static const int8_t mv[256][2]
This structure describes decoded (raw) audio or video data.
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static av_cold int encode_end(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int encode_init(AVCodecContext *avctx)
Init zmbv encoder.
static enum AVPixelFormat pix_fmts[]
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
static void deflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
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.
int flags
A combination of AV_PKT_FLAG values.
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
#define i(width, name, range_min, range_max)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
main external API structure.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
This structure stores compressed data.
int width
picture width / height.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
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.
int score_tab[ZMBV_BLOCK *ZMBV_BLOCK *4+1]