MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / encode_slice

Function encode_slice

libavcodec/ffv1enc.c:1563–1684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1561
1562
1563static int encode_slice(AVCodecContext *c, void *arg)
1564{
1565 FFV1SliceContext *sc = arg;
1566 FFV1Context *f = c->priv_data;
1567 int width = sc->slice_width;
1568 int height = sc->slice_height;
1569 int x = sc->slice_x;
1570 int y = sc->slice_y;
1571 const AVFrame *const p = f->cur_enc_frame;
1572 const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
1573 int ret;
1574 RangeCoder c_bak = sc->c;
1575 const int chroma_width = AV_CEIL_RSHIFT(width, f->chroma_h_shift);
1576 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
1577 const uint8_t *planes[4] = {p->data[0] + ps*x + y*p->linesize[0],
1578 p->data[1] ? p->data[1] + ps*x + y*p->linesize[1] : NULL,
1579 p->data[2] ? p->data[2] + ps*x + y*p->linesize[2] : NULL,
1580 p->data[3] ? p->data[3] + ps*x + y*p->linesize[3] : NULL};
1581 int ac = f->ac;
1582
1583 sc->slice_coding_mode = 0;
1584 if (f->version > 3 && f->colorspace == 1) {
1585 choose_rct_params(f, sc, planes, p->linesize, width, height);
1586 } else {
1587 sc->slice_rct_by_coef = 1;
1588 sc->slice_rct_ry_coef = 1;
1589 }
1590
1591retry:
1592 if (f->key_frame)
1593 ff_ffv1_clear_slice_state(f, sc);
1594 if (f->version > 2) {
1595 encode_slice_header(f, sc);
1596 }
1597
1598 if (sc->remap) {
1599 //Both the 16bit and 32bit remap do exactly the same thing but with 16bits we can
1600 //Implement this using a "histogram" while for 32bit that would be gb sized, thus a more
1601 //complex implementation sorting pairs is used.
1602 if (f->bits_per_raw_sample != 32) {
1603 if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8 && c->pix_fmt != AV_PIX_FMT_YAF16) {
1604 const int cx = x >> f->chroma_h_shift;
1605 const int cy = y >> f->chroma_v_shift;
1606
1607 //TODO decide on the order for the encoded remaps and loads. with golomb rice it
1608 // easier to have all range coded ones together, otherwise it may be nicer to handle each plane as a whole?
1609
1610 load_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1);
1611
1612 if (f->chroma_planes) {
1613 load_plane(f, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
1614 load_plane(f, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 2, 1);
1615 }
1616 if (f->transparency)
1617 load_plane(f, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 3, 1);
1618 } else if (c->pix_fmt == AV_PIX_FMT_YA8 || c->pix_fmt == AV_PIX_FMT_YAF16) {
1619 load_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2);
1620 load_plane(f, sc, p->data[0] + (ps>>1) + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2);

Callers

nothing calls this directly

Calls 15

av_pix_fmt_desc_getFunction · 0.85
choose_rct_paramsFunction · 0.85
encode_slice_headerFunction · 0.85
load_planeFunction · 0.85
encode_histogram_remapFunction · 0.85
load_rgb_float32_frameFunction · 0.85
encode_float32_remapFunction · 0.85
ff_rac_terminateFunction · 0.85
init_put_bitsFunction · 0.85
encode_float32_rgb_frameFunction · 0.85
flush_put_bitsFunction · 0.85

Tested by

no test coverage detected