static int encode_hq_slice(AVCodecContext *avctx, void *arg)

{

    SliceArgs *slice_dat = arg;

    VC2EncContext *s = slice_dat->ctx;

    PutBitContext *pb = &slice_dat->pb;

    const int slice_x = slice_dat->x;

    const int slice_y = slice_dat->y;

    const int quant_idx = slice_dat->quant_idx;

    const int slice_bytes_max = slice_dat->bytes;

    uint8_t quants[MAX_DWT_LEVELS][4];

    int p, level, orientation;



    /* The reference decoder ignores it, and its typical length is 0 */

    memset(put_bits_ptr(pb), 0, s->prefix_bytes);

    skip_put_bytes(pb, s->prefix_bytes);



    put_bits(pb, 8, quant_idx);



    /* Slice quantization (slice_quantizers() in the specs) */

    for (level = 0; level < s->wavelet_depth; level++)

        for (orientation = !!level; orientation < 4; orientation++)

            quants[level][orientation] = FFMAX(quant_idx - s->quant[level][orientation], 0);



    /* Luma + 2 Chroma planes */

    for (p = 0; p < 3; p++) {

        int bytes_start, bytes_len, pad_s, pad_c;

        bytes_start = put_bits_count(pb) >> 3;

        put_bits(pb, 8, 0);

        for (level = 0; level < s->wavelet_depth; level++) {

            for (orientation = !!level; orientation < 4; orientation++) {

                encode_subband(s, pb, slice_x, slice_y,

                               &s->plane[p].band[level][orientation],

                               quants[level][orientation]);

            }

        }

        avpriv_align_put_bits(pb);

        bytes_len = (put_bits_count(pb) >> 3) - bytes_start - 1;

        if (p == 2) {

            int len_diff = slice_bytes_max - (put_bits_count(pb) >> 3);

            pad_s = FFALIGN((bytes_len + len_diff), s->size_scaler)/s->size_scaler;

            pad_c = (pad_s*s->size_scaler) - bytes_len;

        } else {

            pad_s = FFALIGN(bytes_len, s->size_scaler)/s->size_scaler;

            pad_c = (pad_s*s->size_scaler) - bytes_len;

        }

        pb->buf[bytes_start] = pad_s;

        flush_put_bits(pb);



        skip_put_bytes(pb, pad_c);

    }



    return 0;

}
static int encode_hq_slice(AVCodecContext *avctx, void *arg)

{

    SliceArgs *slice_dat = arg;

    VC2EncContext *s = slice_dat->ctx;

    PutBitContext *pb = &slice_dat->pb;

    const int slice_x = slice_dat->x;

    const int slice_y = slice_dat->y;

    const int quant_idx = slice_dat->quant_idx;

    const int slice_bytes_max = slice_dat->bytes;

    uint8_t quants[MAX_DWT_LEVELS][4];

    int p, level, orientation;



    

    memset(put_bits_ptr(pb), 0, s->prefix_bytes);

    skip_put_bytes(pb, s->prefix_bytes);



    put_bits(pb, 8, quant_idx);



    

    for (level = 0; level < s->wavelet_depth; level++)

        for (orientation = !!level; orientation < 4; orientation++)

            quants[level][orientation] = FFMAX(quant_idx - s->quant[level][orientation], 0);



    

    for (p = 0; p < 3; p++) {

        int bytes_start, bytes_len, pad_s, pad_c;

        bytes_start = put_bits_count(pb) >> 3;

        put_bits(pb, 8, 0);

        for (level = 0; level < s->wavelet_depth; level++) {

            for (orientation = !!level; orientation < 4; orientation++) {

                encode_subband(s, pb, slice_x, slice_y,

                               &s->plane[p].band[level][orientation],

                               quants[level][orientation]);

            }

        }

        avpriv_align_put_bits(pb);

        bytes_len = (put_bits_count(pb) >> 3) - bytes_start - 1;

        if (p == 2) {

            int len_diff = slice_bytes_max - (put_bits_count(pb) >> 3);

            pad_s = FFALIGN((bytes_len + len_diff), s->size_scaler)/s->size_scaler;

            pad_c = (pad_s*s->size_scaler) - bytes_len;

        } else {

            pad_s = FFALIGN(bytes_len, s->size_scaler)/s->size_scaler;

            pad_c = (pad_s*s->size_scaler) - bytes_len;

        }

        pb->buf[bytes_start] = pad_s;

        flush_put_bits(pb);



        skip_put_bytes(pb, pad_c);

    }



    return 0;

}
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1)

{

    SliceArgs *slice_dat = VAR_1;

    VC2EncContext *s = slice_dat->ctx;

    PutBitContext *pb = &slice_dat->pb;

    const int VAR_2 = slice_dat->x;

    const int VAR_3 = slice_dat->y;

    const int VAR_4 = slice_dat->VAR_4;

    const int VAR_5 = slice_dat->bytes;

    uint8_t quants[MAX_DWT_LEVELS][4];

    int VAR_6, VAR_7, VAR_8;



    

    memset(put_bits_ptr(pb), 0, s->prefix_bytes);

    skip_put_bytes(pb, s->prefix_bytes);



    put_bits(pb, 8, VAR_4);



    

    for (VAR_7 = 0; VAR_7 < s->wavelet_depth; VAR_7++)

        for (VAR_8 = !!VAR_7; VAR_8 < 4; VAR_8++)

            quants[VAR_7][VAR_8] = FFMAX(VAR_4 - s->quant[VAR_7][VAR_8], 0);



    

    for (VAR_6 = 0; VAR_6 < 3; VAR_6++) {

        int VAR_9, VAR_10, VAR_11, VAR_12;

        VAR_9 = put_bits_count(pb) >> 3;

        put_bits(pb, 8, 0);

        for (VAR_7 = 0; VAR_7 < s->wavelet_depth; VAR_7++) {

            for (VAR_8 = !!VAR_7; VAR_8 < 4; VAR_8++) {

                encode_subband(s, pb, VAR_2, VAR_3,

                               &s->plane[VAR_6].band[VAR_7][VAR_8],

                               quants[VAR_7][VAR_8]);

            }

        }

        avpriv_align_put_bits(pb);

        VAR_10 = (put_bits_count(pb) >> 3) - VAR_9 - 1;

        if (VAR_6 == 2) {

            int VAR_13 = VAR_5 - (put_bits_count(pb) >> 3);

            VAR_11 = FFALIGN((VAR_10 + VAR_13), s->size_scaler)/s->size_scaler;

            VAR_12 = (VAR_11*s->size_scaler) - VAR_10;

        } else {

            VAR_11 = FFALIGN(VAR_10, s->size_scaler)/s->size_scaler;

            VAR_12 = (VAR_11*s->size_scaler) - VAR_10;

        }

        pb->buf[VAR_9] = VAR_11;

        flush_put_bits(pb);



        skip_put_bytes(pb, VAR_12);

    }



    return 0;

}
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1)
{ SliceArgs *slice_dat = VAR_1; VC2EncContext *s = slice_dat->ctx; PutBitContext *pb = &slice_dat->pb; const int VAR_2 = slice_dat->x; const int VAR_3 = slice_dat->y; const int VAR_4 = slice_dat->VAR_4; const int VAR_5 = slice_dat->bytes; uint8_t quants[MAX_DWT_LEVELS][4]; int VAR_6, VAR_7, VAR_8; memset(put_bits_ptr(pb), 0, s->prefix_bytes); skip_put_bytes(pb, s->prefix_bytes); put_bits(pb, 8, VAR_4); for (VAR_7 = 0; VAR_7 < s->wavelet_depth; VAR_7++) for (VAR_8 = !!VAR_7; VAR_8 < 4; VAR_8++) quants[VAR_7][VAR_8] = FFMAX(VAR_4 - s->quant[VAR_7][VAR_8], 0); for (VAR_6 = 0; VAR_6 < 3; VAR_6++) { int VAR_9, VAR_10, VAR_11, VAR_12; VAR_9 = put_bits_count(pb) >> 3; put_bits(pb, 8, 0); for (VAR_7 = 0; VAR_7 < s->wavelet_depth; VAR_7++) { for (VAR_8 = !!VAR_7; VAR_8 < 4; VAR_8++) { encode_subband(s, pb, VAR_2, VAR_3,
&s->plane[VAR_6].band[VAR_7][VAR_8],
quants[VAR_7][VAR_8]); } } avpriv_align_put_bits(pb); VAR_10 = (put_bits_count(pb) >> 3) - VAR_9 - 1; if (VAR_6 == 2) { int VAR_13 = VAR_5 - (put_bits_count(pb) >> 3); VAR_11 = FFALIGN((VAR_10 + VAR_13), s->size_scaler)/s->size_scaler; VAR_12 = (VAR_11*s->size_scaler) - VAR_10; } else { VAR_11 = FFALIGN(VAR_10, s->size_scaler)/s->size_scaler; VAR_12 = (VAR_11*s->size_scaler) - VAR_10; } pb->buf[VAR_9] = VAR_11; flush_put_bits(pb); skip_put_bytes(pb, VAR_12); } return 0; }