static void generate_new_codebooks(RoqContext *enc, RoqTempdata *tempData)

{

    int i,j;

    RoqCodebooks *codebooks = &tempData->codebooks;

    int max = enc->width*enc->height/16;

    uint8_t mb2[3*4];

    roq_cell *results4 = av_malloc(sizeof(roq_cell)*MAX_CBS_4x4*4);

    uint8_t *yuvClusters=av_malloc(sizeof(int)*max*6*4);

    int *points = av_malloc(max*6*4*sizeof(int));

    int bias;



    /* Subsample YUV data */

    create_clusters(enc->frame_to_enc, enc->width, enc->height, yuvClusters);



    /* Cast to integer and apply chroma bias */

    for (i=0; i<max*24; i++) {

        bias = ((i%6)<4) ? 1 : CHROMA_BIAS;

        points[i] = bias*yuvClusters[i];

    }



    /* Create 4x4 codebooks */

    generate_codebook(enc, tempData, points, max, results4, 4, MAX_CBS_4x4);



    codebooks->numCB4 = MAX_CBS_4x4;



    tempData->closest_cb2 = av_malloc(max*4*sizeof(int));



    /* Create 2x2 codebooks */

    generate_codebook(enc, tempData, points, max*4, enc->cb2x2, 2, MAX_CBS_2x2);



    codebooks->numCB2 = MAX_CBS_2x2;



    /* Unpack 2x2 codebook clusters */

    for (i=0; i<codebooks->numCB2; i++)

        unpack_roq_cell(enc->cb2x2 + i, codebooks->unpacked_cb2 + i*2*2*3);



    /* Index all 4x4 entries to the 2x2 entries, unpack, and enlarge */

    for (i=0; i<codebooks->numCB4; i++) {

        for (j=0; j<4; j++) {

            unpack_roq_cell(&results4[4*i + j], mb2);

            index_mb(mb2, codebooks->unpacked_cb2, codebooks->numCB2,

                     &enc->cb4x4[i].idx[j], 2);

        }

        unpack_roq_qcell(codebooks->unpacked_cb2, enc->cb4x4 + i,

                         codebooks->unpacked_cb4 + i*4*4*3);

        enlarge_roq_mb4(codebooks->unpacked_cb4 + i*4*4*3,

                        codebooks->unpacked_cb4_enlarged + i*8*8*3);

    }



    av_free(yuvClusters);

    av_free(points);

    av_free(results4);

}

static void generate_new_codebooks(RoqContext *enc, RoqTempdata *tempData)

{

    int i,j;

    RoqCodebooks *codebooks = &tempData->codebooks;

    int max = enc->width*enc->height/16;

    uint8_t mb2[3*4];

    roq_cell *results4 = av_malloc(sizeof(roq_cell)*MAX_CBS_4x4*4);

    uint8_t *yuvClusters=av_malloc(sizeof(int)*max*6*4);

    int *points = av_malloc(max*6*4*sizeof(int));

    int bias;



    

    create_clusters(enc->frame_to_enc, enc->width, enc->height, yuvClusters);



    

    for (i=0; i<max*24; i++) {

        bias = ((i%6)<4) ? 1 : CHROMA_BIAS;

        points[i] = bias*yuvClusters[i];

    }



    

    generate_codebook(enc, tempData, points, max, results4, 4, MAX_CBS_4x4);



    codebooks->numCB4 = MAX_CBS_4x4;



    tempData->closest_cb2 = av_malloc(max*4*sizeof(int));



    

    generate_codebook(enc, tempData, points, max*4, enc->cb2x2, 2, MAX_CBS_2x2);



    codebooks->numCB2 = MAX_CBS_2x2;



    

    for (i=0; i<codebooks->numCB2; i++)

        unpack_roq_cell(enc->cb2x2 + i, codebooks->unpacked_cb2 + i*2*2*3);



    

    for (i=0; i<codebooks->numCB4; i++) {

        for (j=0; j<4; j++) {

            unpack_roq_cell(&results4[4*i + j], mb2);

            index_mb(mb2, codebooks->unpacked_cb2, codebooks->numCB2,

                     &enc->cb4x4[i].idx[j], 2);

        }

        unpack_roq_qcell(codebooks->unpacked_cb2, enc->cb4x4 + i,

                         codebooks->unpacked_cb4 + i*4*4*3);

        enlarge_roq_mb4(codebooks->unpacked_cb4 + i*4*4*3,

                        codebooks->unpacked_cb4_enlarged + i*8*8*3);

    }



    av_free(yuvClusters);

    av_free(points);

    av_free(results4);

}

static void FUNC_0(RoqContext *VAR_0, RoqTempdata *VAR_1)

{

    int VAR_2,VAR_3;

    RoqCodebooks *codebooks = &VAR_1->codebooks;

    int VAR_4 = VAR_0->width*VAR_0->height/16;

    uint8_t mb2[3*4];

    roq_cell *results4 = av_malloc(sizeof(roq_cell)*MAX_CBS_4x4*4);

    uint8_t *yuvClusters=av_malloc(sizeof(int)*VAR_4*6*4);

    int *VAR_5 = av_malloc(VAR_4*6*4*sizeof(int));

    int VAR_6;



    

    create_clusters(VAR_0->frame_to_enc, VAR_0->width, VAR_0->height, yuvClusters);



    

    for (VAR_2=0; VAR_2<VAR_4*24; VAR_2++) {

        VAR_6 = ((VAR_2%6)<4) ? 1 : CHROMA_BIAS;

        VAR_5[VAR_2] = VAR_6*yuvClusters[VAR_2];

    }



    

    generate_codebook(VAR_0, VAR_1, VAR_5, VAR_4, results4, 4, MAX_CBS_4x4);



    codebooks->numCB4 = MAX_CBS_4x4;



    VAR_1->closest_cb2 = av_malloc(VAR_4*4*sizeof(int));



    

    generate_codebook(VAR_0, VAR_1, VAR_5, VAR_4*4, VAR_0->cb2x2, 2, MAX_CBS_2x2);



    codebooks->numCB2 = MAX_CBS_2x2;



    

    for (VAR_2=0; VAR_2<codebooks->numCB2; VAR_2++)

        unpack_roq_cell(VAR_0->cb2x2 + VAR_2, codebooks->unpacked_cb2 + VAR_2*2*2*3);



    

    for (VAR_2=0; VAR_2<codebooks->numCB4; VAR_2++) {

        for (VAR_3=0; VAR_3<4; VAR_3++) {

            unpack_roq_cell(&results4[4*VAR_2 + VAR_3], mb2);

            index_mb(mb2, codebooks->unpacked_cb2, codebooks->numCB2,

                     &VAR_0->cb4x4[VAR_2].idx[VAR_3], 2);

        }

        unpack_roq_qcell(codebooks->unpacked_cb2, VAR_0->cb4x4 + VAR_2,

                         codebooks->unpacked_cb4 + VAR_2*4*4*3);

        enlarge_roq_mb4(codebooks->unpacked_cb4 + VAR_2*4*4*3,

                        codebooks->unpacked_cb4_enlarged + VAR_2*8*8*3);

    }



    av_free(yuvClusters);

    av_free(VAR_5);

    av_free(results4);

}

static void FUNC_0(RoqContext *VAR_0, RoqTempdata *VAR_1)
{ int VAR_2,VAR_3; RoqCodebooks *codebooks = &VAR_1->codebooks; int VAR_4 = VAR_0->width*VAR_0->height/16; uint8_t mb2[3*4]; roq_cell *results4 = av_malloc(sizeof(roq_cell)*MAX_CBS_4x4*4); uint8_t *yuvClusters=av_malloc(sizeof(int)*VAR_4*6*4); int *VAR_5 = av_malloc(VAR_4*6*4*sizeof(int)); int VAR_6; create_clusters(VAR_0->frame_to_enc, VAR_0->width, VAR_0->height, yuvClusters); for (VAR_2=0; VAR_2<VAR_4*24; VAR_2++) { VAR_6 = ((VAR_2%6)<4) ? 1 : CHROMA_BIAS; VAR_5[VAR_2] = VAR_6*yuvClusters[VAR_2]; } generate_codebook(VAR_0, VAR_1, VAR_5, VAR_4, results4, 4, MAX_CBS_4x4); codebooks->numCB4 = MAX_CBS_4x4; VAR_1->closest_cb2 = av_malloc(VAR_4*4*sizeof(int)); generate_codebook(VAR_0, VAR_1, VAR_5, VAR_4*4, VAR_0->cb2x2, 2, MAX_CBS_2x2); codebooks->numCB2 = MAX_CBS_2x2; for (VAR_2=0; VAR_2<codebooks->numCB2; VAR_2++) unpack_roq_cell(VAR_0->cb2x2 + VAR_2, codebooks->unpacked_cb2 + VAR_2*2*2*3); for (VAR_2=0; VAR_2<codebooks->numCB4; VAR_2++) { for (VAR_3=0; VAR_3<4; VAR_3++) { unpack_roq_cell(&results4[4*VAR_2 + VAR_3], mb2); index_mb(mb2, codebooks->unpacked_cb2, codebooks->numCB2,
&VAR_0->cb4x4[VAR_2].idx[VAR_3], 2); } unpack_roq_qcell(codebooks->unpacked_cb2, VAR_0->cb4x4 + VAR_2,
codebooks->unpacked_cb4 + VAR_2*4*4*3); enlarge_roq_mb4(codebooks->unpacked_cb4 + VAR_2*4*4*3,
codebooks->unpacked_cb4_enlarged + VAR_2*8*8*3); } av_free(yuvClusters); av_free(VAR_5); av_free(results4); }