static int quantize(CinepakEncContext *s, int h, AVPicture *pict, int v1mode, int size, int v4, strip_info *info)

{

    int x, y, i, j, k, x2, y2, x3, y3, plane, shift;

    int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;

    int *codebook = v1mode ? info->v1_codebook : info->v4_codebook;

    int64_t total_error = 0;

    uint8_t vq_pict_buf[(MB_AREA*3)/2];

    AVPicture sub_pict, vq_pict;



    for(i = y = 0; y < h; y += MB_SIZE) {

        for(x = 0; x < s->w; x += MB_SIZE, i += v1mode ? 1 : 4) {

            int *base = s->codebook_input + i*entry_size;



            if(v1mode) {

                //subsample

                for(j = y2 = 0; y2 < entry_size; y2 += 2) {

                    for(x2 = 0; x2 < 4; x2 += 2, j++) {

                        plane = y2 < 4 ? 0 : 1 + (x2 >> 1);

                        shift = y2 < 4 ? 0 : 1;

                        x3 = shift ? 0 : x2;

                        y3 = shift ? 0 : y2;

                        base[j] = (pict->data[plane][((x+x3) >> shift) +      ((y+y3) >> shift)      * pict->linesize[plane]] +

                                   pict->data[plane][((x+x3) >> shift) + 1 +  ((y+y3) >> shift)      * pict->linesize[plane]] +

                                   pict->data[plane][((x+x3) >> shift) +     (((y+y3) >> shift) + 1) * pict->linesize[plane]] +

                                   pict->data[plane][((x+x3) >> shift) + 1 + (((y+y3) >> shift) + 1) * pict->linesize[plane]]) >> 2;

                    }

                }

            } else {

                //copy

                for(j = y2 = 0; y2 < MB_SIZE; y2 += 2) {

                    for(x2 = 0; x2 < MB_SIZE; x2 += 2) {

                        for(k = 0; k < entry_size; k++, j++) {

                            plane = k >= 4 ? k - 3 : 0;



                            if(k >= 4) {

                                x3 = (x+x2) >> 1;

                                y3 = (y+y2) >> 1;

                            } else {

                                x3 = x + x2 + (k & 1);

                                y3 = y + y2 + (k >> 1);

                            }



                            base[j] = pict->data[plane][x3 + y3*pict->linesize[plane]];

                        }

                    }

                }

            }

        }

    }



    ff_init_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);

    ff_do_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);



    //setup vq_pict, which contains a single MB

    vq_pict.data[0] = vq_pict_buf;

    vq_pict.linesize[0] = MB_SIZE;

    vq_pict.data[1] = &vq_pict_buf[MB_AREA];

    vq_pict.data[2] = vq_pict.data[1] + (MB_AREA >> 2);

    vq_pict.linesize[1] = vq_pict.linesize[2] = MB_SIZE >> 1;



    //copy indices

    for(i = j = y = 0; y < h; y += MB_SIZE) {

        for(x = 0; x < s->w; x += MB_SIZE, j++, i += v1mode ? 1 : 4) {

            mb_info *mb = &s->mb[j];



            //point sub_pict to current MB

            get_sub_picture(s, x, y, pict, &sub_pict);



            if(v1mode) {

                mb->v1_vector = s->codebook_closest[i];



                //fill in vq_pict with V1 data

                decode_v1_vector(s, &vq_pict, mb, info);



                mb->v1_error = compute_mb_distortion(s, &sub_pict, &vq_pict);

                total_error += mb->v1_error;

            } else {

                for(k = 0; k < 4; k++)

                    mb->v4_vector[v4][k] = s->codebook_closest[i+k];



                //fill in vq_pict with V4 data

                decode_v4_vector(s, &vq_pict, mb->v4_vector[v4], info);



                mb->v4_error[v4] = compute_mb_distortion(s, &sub_pict, &vq_pict);

                total_error += mb->v4_error[v4];

            }

        }

    }



    //av_log(s->avctx, AV_LOG_INFO, "mode %i size %i i %i error %li\n", v1mode, size, i, total_error);



    return 0;

}

static int quantize(CinepakEncContext *s, int h, AVPicture *pict, int v1mode, int size, int v4, strip_info *info)

{

    int x, y, i, j, k, x2, y2, x3, y3, plane, shift;

    int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;

    int *codebook = v1mode ? info->v1_codebook : info->v4_codebook;

    int64_t total_error = 0;

    uint8_t vq_pict_buf[(MB_AREA*3)/2];

    AVPicture sub_pict, vq_pict;



    for(i = y = 0; y < h; y += MB_SIZE) {

        for(x = 0; x < s->w; x += MB_SIZE, i += v1mode ? 1 : 4) {

            int *base = s->codebook_input + i*entry_size;



            if(v1mode) {

                

                for(j = y2 = 0; y2 < entry_size; y2 += 2) {

                    for(x2 = 0; x2 < 4; x2 += 2, j++) {

                        plane = y2 < 4 ? 0 : 1 + (x2 >> 1);

                        shift = y2 < 4 ? 0 : 1;

                        x3 = shift ? 0 : x2;

                        y3 = shift ? 0 : y2;

                        base[j] = (pict->data[plane][((x+x3) >> shift) +      ((y+y3) >> shift)      * pict->linesize[plane]] +

                                   pict->data[plane][((x+x3) >> shift) + 1 +  ((y+y3) >> shift)      * pict->linesize[plane]] +

                                   pict->data[plane][((x+x3) >> shift) +     (((y+y3) >> shift) + 1) * pict->linesize[plane]] +

                                   pict->data[plane][((x+x3) >> shift) + 1 + (((y+y3) >> shift) + 1) * pict->linesize[plane]]) >> 2;

                    }

                }

            } else {

                

                for(j = y2 = 0; y2 < MB_SIZE; y2 += 2) {

                    for(x2 = 0; x2 < MB_SIZE; x2 += 2) {

                        for(k = 0; k < entry_size; k++, j++) {

                            plane = k >= 4 ? k - 3 : 0;



                            if(k >= 4) {

                                x3 = (x+x2) >> 1;

                                y3 = (y+y2) >> 1;

                            } else {

                                x3 = x + x2 + (k & 1);

                                y3 = y + y2 + (k >> 1);

                            }



                            base[j] = pict->data[plane][x3 + y3*pict->linesize[plane]];

                        }

                    }

                }

            }

        }

    }



    ff_init_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);

    ff_do_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);



    

    vq_pict.data[0] = vq_pict_buf;

    vq_pict.linesize[0] = MB_SIZE;

    vq_pict.data[1] = &vq_pict_buf[MB_AREA];

    vq_pict.data[2] = vq_pict.data[1] + (MB_AREA >> 2);

    vq_pict.linesize[1] = vq_pict.linesize[2] = MB_SIZE >> 1;



     indices

    for(i = j = y = 0; y < h; y += MB_SIZE) {

        for(x = 0; x < s->w; x += MB_SIZE, j++, i += v1mode ? 1 : 4) {

            mb_info *mb = &s->mb[j];



            

            get_sub_picture(s, x, y, pict, &sub_pict);



            if(v1mode) {

                mb->v1_vector = s->codebook_closest[i];



                

                decode_v1_vector(s, &vq_pict, mb, info);



                mb->v1_error = compute_mb_distortion(s, &sub_pict, &vq_pict);

                total_error += mb->v1_error;

            } else {

                for(k = 0; k < 4; k++)

                    mb->v4_vector[v4][k] = s->codebook_closest[i+k];



                

                decode_v4_vector(s, &vq_pict, mb->v4_vector[v4], info);



                mb->v4_error[v4] = compute_mb_distortion(s, &sub_pict, &vq_pict);

                total_error += mb->v4_error[v4];

            }

        }

    }



    



    return 0;

}

    int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;             } else {             } else {     int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4; static int quantize(CinepakEncContext *s, int h, AVPicture *pict, int v1mode, int size, int v4, strip_info *info)     int x, y, i, j, k, x2, y2, x3, y3, plane, shift;     int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;     for(i = y = 0; y < h; y += MB_SIZE) {         for(x = 0; x < s->w; x += MB_SIZE, i += v1mode ? 1 : 4) {             int *base = s->codebook_input + i*entry_size;         for(x = 0; x < s->w; x += MB_SIZE, j++, i += v1mode ? 1 : 4) {                 decode_v1_vector(s, &vq_pict, mb, info);                     mb->v4_vector[v4][k] = s->codebook_closest[i+k];                 decode_v4_vector(s, &vq_pict, mb->v4_vector[v4], info);                 mb->v4_error[v4] = compute_mb_distortion(s, &sub_pict, &vq_pict);                 total_error += mb->v4_error[v4];     return 0;
static int FUNC_0(CinepakEncContext *VAR_0, int VAR_1, AVPicture *VAR_2, int VAR_3, int VAR_4, int VAR_5, strip_info *VAR_6)

{

    int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13, VAR_14, VAR_15, VAR_16, VAR_17;

    int VAR_18 = VAR_0->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;

    int *VAR_19 = VAR_3 ? VAR_6->v1_codebook : VAR_6->v4_codebook;

    int64_t total_error = 0;

    uint8_t vq_pict_buf[(MB_AREA*3)/2];

    AVPicture sub_pict, vq_pict;



    for(VAR_9 = VAR_8 = 0; VAR_8 < VAR_1; VAR_8 += MB_SIZE) {

        for(VAR_7 = 0; VAR_7 < VAR_0->w; VAR_7 += MB_SIZE, VAR_9 += VAR_3 ? 1 : 4) {

            int *base = VAR_0->codebook_input + VAR_9*VAR_18;



            if(VAR_3) {

                

                for(VAR_10 = VAR_13 = 0; VAR_13 < VAR_18; VAR_13 += 2) {

                    for(VAR_12 = 0; VAR_12 < 4; VAR_12 += 2, VAR_10++) {

                        VAR_16 = VAR_13 < 4 ? 0 : 1 + (VAR_12 >> 1);

                        VAR_17 = VAR_13 < 4 ? 0 : 1;

                        VAR_14 = VAR_17 ? 0 : VAR_12;

                        VAR_15 = VAR_17 ? 0 : VAR_13;

                        base[VAR_10] = (VAR_2->data[VAR_16][((VAR_7+VAR_14) >> VAR_17) +      ((VAR_8+VAR_15) >> VAR_17)      * VAR_2->linesize[VAR_16]] +

                                   VAR_2->data[VAR_16][((VAR_7+VAR_14) >> VAR_17) + 1 +  ((VAR_8+VAR_15) >> VAR_17)      * VAR_2->linesize[VAR_16]] +

                                   VAR_2->data[VAR_16][((VAR_7+VAR_14) >> VAR_17) +     (((VAR_8+VAR_15) >> VAR_17) + 1) * VAR_2->linesize[VAR_16]] +

                                   VAR_2->data[VAR_16][((VAR_7+VAR_14) >> VAR_17) + 1 + (((VAR_8+VAR_15) >> VAR_17) + 1) * VAR_2->linesize[VAR_16]]) >> 2;

                    }

                }

            } else {

                

                for(VAR_10 = VAR_13 = 0; VAR_13 < MB_SIZE; VAR_13 += 2) {

                    for(VAR_12 = 0; VAR_12 < MB_SIZE; VAR_12 += 2) {

                        for(VAR_11 = 0; VAR_11 < VAR_18; VAR_11++, VAR_10++) {

                            VAR_16 = VAR_11 >= 4 ? VAR_11 - 3 : 0;



                            if(VAR_11 >= 4) {

                                VAR_14 = (VAR_7+VAR_12) >> 1;

                                VAR_15 = (VAR_8+VAR_13) >> 1;

                            } else {

                                VAR_14 = VAR_7 + VAR_12 + (VAR_11 & 1);

                                VAR_15 = VAR_8 + VAR_13 + (VAR_11 >> 1);

                            }



                            base[VAR_10] = VAR_2->data[VAR_16][VAR_14 + VAR_15*VAR_2->linesize[VAR_16]];

                        }

                    }

                }

            }

        }

    }



    ff_init_elbg(VAR_0->codebook_input, VAR_18, VAR_9, VAR_19, VAR_4, 1, VAR_0->codebook_closest, &VAR_0->randctx);

    ff_do_elbg(VAR_0->codebook_input, VAR_18, VAR_9, VAR_19, VAR_4, 1, VAR_0->codebook_closest, &VAR_0->randctx);



    

    vq_pict.data[0] = vq_pict_buf;

    vq_pict.linesize[0] = MB_SIZE;

    vq_pict.data[1] = &vq_pict_buf[MB_AREA];

    vq_pict.data[2] = vq_pict.data[1] + (MB_AREA >> 2);

    vq_pict.linesize[1] = vq_pict.linesize[2] = MB_SIZE >> 1;



     indices

    for(VAR_9 = VAR_10 = VAR_8 = 0; VAR_8 < VAR_1; VAR_8 += MB_SIZE) {

        for(VAR_7 = 0; VAR_7 < VAR_0->w; VAR_7 += MB_SIZE, VAR_10++, VAR_9 += VAR_3 ? 1 : 4) {

            mb_info *mb = &VAR_0->mb[VAR_10];



            

            get_sub_picture(VAR_0, VAR_7, VAR_8, VAR_2, &sub_pict);



            if(VAR_3) {

                mb->v1_vector = VAR_0->codebook_closest[VAR_9];



                

                decode_v1_vector(VAR_0, &vq_pict, mb, VAR_6);



                mb->v1_error = compute_mb_distortion(VAR_0, &sub_pict, &vq_pict);

                total_error += mb->v1_error;

            } else {

                for(VAR_11 = 0; VAR_11 < 4; VAR_11++)

                    mb->v4_vector[VAR_5][VAR_11] = VAR_0->codebook_closest[VAR_9+VAR_11];



                

                decode_v4_vector(VAR_0, &vq_pict, mb->v4_vector[VAR_5], VAR_6);



                mb->v4_error[VAR_5] = compute_mb_distortion(VAR_0, &sub_pict, &vq_pict);

                total_error += mb->v4_error[VAR_5];

            }

        }

    }



    



    return 0;

}

static int FUNC_0(CinepakEncContext *VAR_0, int VAR_1, AVPicture *VAR_2, int VAR_3, int VAR_4, int VAR_5, strip_info *VAR_6)
{ int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13, VAR_14, VAR_15, VAR_16, VAR_17; int VAR_18 = VAR_0->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4; int *VAR_19 = VAR_3 ? VAR_6->v1_codebook : VAR_6->v4_codebook; int64_t total_error = 0; uint8_t vq_pict_buf[(MB_AREA*3)/2]; AVPicture sub_pict, vq_pict; for(VAR_9 = VAR_8 = 0; VAR_8 < VAR_1; VAR_8 += MB_SIZE) { for(VAR_7 = 0; VAR_7 < VAR_0->w; VAR_7 += MB_SIZE, VAR_9 += VAR_3 ? 1 : 4) { int *base = VAR_0->codebook_input + VAR_9*VAR_18; if(VAR_3) { for(VAR_10 = VAR_13 = 0; VAR_13 < VAR_18; VAR_13 += 2) { for(VAR_12 = 0; VAR_12 < 4; VAR_12 += 2, VAR_10++) { VAR_16 = VAR_13 < 4 ? 0 : 1 + (VAR_12 >> 1); VAR_17 = VAR_13 < 4 ? 0 : 1; VAR_14 = VAR_17 ? 0 : VAR_12; VAR_15 = VAR_17 ? 0 : VAR_13; base[VAR_10] = (VAR_2->data[VAR_16][((VAR_7+VAR_14) >> VAR_17) +      ((VAR_8+VAR_15) >> VAR_17)      * VAR_2->linesize[VAR_16]] +
VAR_2->data[VAR_16][((VAR_7+VAR_14) >> VAR_17) + 1 +  ((VAR_8+VAR_15) >> VAR_17)      * VAR_2->linesize[VAR_16]] +
VAR_2->data[VAR_16][((VAR_7+VAR_14) >> VAR_17) +     (((VAR_8+VAR_15) >> VAR_17) + 1) * VAR_2->linesize[VAR_16]] +
VAR_2->data[VAR_16][((VAR_7+VAR_14) >> VAR_17) + 1 + (((VAR_8+VAR_15) >> VAR_17) + 1) * VAR_2->linesize[VAR_16]]) >> 2; } } } else { for(VAR_10 = VAR_13 = 0; VAR_13 < MB_SIZE; VAR_13 += 2) { for(VAR_12 = 0; VAR_12 < MB_SIZE; VAR_12 += 2) { for(VAR_11 = 0; VAR_11 < VAR_18; VAR_11++, VAR_10++) { VAR_16 = VAR_11 >= 4 ? VAR_11 - 3 : 0; if(VAR_11 >= 4) { VAR_14 = (VAR_7+VAR_12) >> 1; VAR_15 = (VAR_8+VAR_13) >> 1; } else { VAR_14 = VAR_7 + VAR_12 + (VAR_11 & 1); VAR_15 = VAR_8 + VAR_13 + (VAR_11 >> 1); } base[VAR_10] = VAR_2->data[VAR_16][VAR_14 + VAR_15*VAR_2->linesize[VAR_16]]; } } } } } } ff_init_elbg(VAR_0->codebook_input, VAR_18, VAR_9, VAR_19, VAR_4, 1, VAR_0->codebook_closest, &VAR_0->randctx); ff_do_elbg(VAR_0->codebook_input, VAR_18, VAR_9, VAR_19, VAR_4, 1, VAR_0->codebook_closest, &VAR_0->randctx); vq_pict.data[0] = vq_pict_buf; vq_pict.linesize[0] = MB_SIZE; vq_pict.data[1] = &vq_pict_buf[MB_AREA]; vq_pict.data[2] = vq_pict.data[1] + (MB_AREA >> 2); vq_pict.linesize[1] = vq_pict.linesize[2] = MB_SIZE >> 1; indices
for(VAR_9 = VAR_10 = VAR_8 = 0; VAR_8 < VAR_1; VAR_8 += MB_SIZE) { for(VAR_7 = 0; VAR_7 < VAR_0->w; VAR_7 += MB_SIZE, VAR_10++, VAR_9 += VAR_3 ? 1 : 4) { mb_info *mb = &VAR_0->mb[VAR_10]; get_sub_picture(VAR_0, VAR_7, VAR_8, VAR_2, &sub_pict); if(VAR_3) { mb->v1_vector = VAR_0->codebook_closest[VAR_9]; decode_v1_vector(VAR_0, &vq_pict, mb, VAR_6); mb->v1_error = compute_mb_distortion(VAR_0, &sub_pict, &vq_pict); total_error += mb->v1_error; } else { for(VAR_11 = 0; VAR_11 < 4; VAR_11++) mb->v4_vector[VAR_5][VAR_11] = VAR_0->codebook_closest[VAR_9+VAR_11]; decode_v4_vector(VAR_0, &vq_pict, mb->v4_vector[VAR_5], VAR_6); mb->v4_error[VAR_5] = compute_mb_distortion(VAR_0, &sub_pict, &vq_pict); total_error += mb->v4_error[VAR_5]; } } } return 0; }