1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avcodec/elbg: Merge avpriv_init_elbg() into avpriv_do_elbg()

These functions are always called directly after another with
the exact same arguments. This avoids exporting a symbol;
it also avoids having to perform two calls for every caller.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2021-09-15 22:38:28 +02:00
parent d046e76515
commit 05ccfcb7b0
7 changed files with 25 additions and 31 deletions

View File

@ -333,10 +333,6 @@ static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
buf = pkt->data;
/* calc optimal new charset + charmaps */
ret = avpriv_init_elbg(meta, 32, 1000 * c->mc_lifetime, best_cb,
CHARSET_CHARS, 50, charmap, &c->randctx);
if (ret < 0)
return ret;
ret = avpriv_do_elbg(meta, 32, 1000 * c->mc_lifetime, best_cb,
CHARSET_CHARS, 50, charmap, &c->randctx);
if (ret < 0)

View File

@ -761,7 +761,6 @@ static int quantize(CinepakEncContext *s, int h, uint8_t *data[4],
if (i < size)
size = i;
avpriv_init_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);
avpriv_do_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);
// set up vq_data, which contains a single MB

View File

@ -332,7 +332,7 @@ static void do_shiftings(elbg_data *elbg)
}
}
int avpriv_do_elbg(int *points, int dim, int numpoints, int *codebook,
static int do_elbg(int *points, int dim, int numpoints, int *codebook,
int numCB, int max_steps, int *closest_cb,
AVLFG *rand_state)
{
@ -426,7 +426,14 @@ out:
#define BIG_PRIME 433494437LL
int avpriv_init_elbg(int *points, int dim, int numpoints, int *codebook,
/**
* Initialize the codebook vector for the elbg algorithm.
* If numpoints < 8*numCB this function fills codebook with random numbers.
* If not, it calls do_elbg for a (smaller) random sample of the points in
* points.
* @return < 0 in case of error, 0 otherwise
*/
static int init_elbg(int *points, int dim, int numpoints, int *codebook,
int num_cb, int max_steps, int *closest_cb,
AVLFG *rand_state)
{
@ -443,13 +450,13 @@ int avpriv_init_elbg(int *points, int dim, int numpoints, int *codebook,
memcpy(temp_points + i*dim, points + k*dim, dim * sizeof(*temp_points));
}
ret = avpriv_init_elbg(temp_points, dim, numpoints / 8, codebook,
ret = init_elbg(temp_points, dim, numpoints / 8, codebook,
num_cb, 2 * max_steps, closest_cb, rand_state);
if (ret < 0) {
av_freep(&temp_points);
return ret;
}
ret = avpriv_do_elbg(temp_points, dim, numpoints / 8, codebook,
ret = do_elbg (temp_points, dim, numpoints / 8, codebook,
num_cb, 2 * max_steps, closest_cb, rand_state);
av_free(temp_points);
} else // If not, initialize the codebook with random positions
@ -458,3 +465,17 @@ int avpriv_init_elbg(int *points, int dim, int numpoints, int *codebook,
dim * sizeof(*codebook));
return ret;
}
int avpriv_do_elbg(int *points, int dim, int numpoints,
int *codebook, int num_cb, int max_steps,
int *closest_cb, AVLFG *rand_state)
{
int ret;
ret = init_elbg(points, dim, numpoints, codebook,
num_cb, max_steps, closest_cb, rand_state);
if (ret < 0)
return ret;
return do_elbg (points, dim, numpoints, codebook,
num_cb, max_steps, closest_cb, rand_state);
}

View File

@ -42,16 +42,4 @@ int avpriv_do_elbg(int *points, int dim, int numpoints, int *codebook,
int numCB, int num_steps, int *closest_cb,
AVLFG *rand_state);
/**
* Initialize the **codebook vector for the elbg algorithm. If you have already
* a codebook and you want to refine it, you shouldn't call this function.
* If numpoints < 8*numCB this function fills **codebook with random numbers.
* If not, it calls avpriv_do_elbg for a (smaller) random sample of the points in
* **points. Get the same parameters as avpriv_do_elbg.
* @return < 0 in case of error, 0 otherwise
*/
int avpriv_init_elbg(int *points, int dim, int numpoints, int *codebook,
int numCB, int num_steps, int *closest_cb,
AVLFG *rand_state);
#endif /* AVCODEC_ELBG_H */

View File

@ -117,7 +117,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
// try to find optimal value to fill whole 4x4 block
score = 0;
avpriv_init_elbg(c->block, 3, 16, c->avg, 1, 1, c->output, &c->rnd);
avpriv_do_elbg (c->block, 3, 16, c->avg, 1, 1, c->output, &c->rnd);
if(c->avg[0] == 1) // red component = 1 will be written as skip code
c->avg[0] = 0;
@ -137,7 +136,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
// search for optimal filling of 2-color block
score = 0;
avpriv_init_elbg(c->block, 3, 16, c->codebook, 2, 1, c->output, &c->rnd);
avpriv_do_elbg (c->block, 3, 16, c->codebook, 2, 1, c->output, &c->rnd);
// last output value should be always 1, swap codebooks if needed
if(!c->output[15]){
@ -163,7 +161,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
// search for optimal filling of 2-color 2x2 subblocks
score = 0;
for(i = 0; i < 4; i++){
avpriv_init_elbg(c->block2 + i*4*3, 3, 4, c->codebook2 + i*2*3, 2, 1, c->output2 + i*4, &c->rnd);
avpriv_do_elbg (c->block2 + i*4*3, 3, 4, c->codebook2 + i*2*3, 2, 1, c->output2 + i*4, &c->rnd);
}
// last value should be always 1, swap codebooks if needed

View File

@ -824,10 +824,6 @@ static int generate_codebook(RoqEncContext *enc,
int *codebook = enc->tmp_codebook_buf;
int *closest_cb = enc->closest_cb;
ret = avpriv_init_elbg(points, 6 * c_size, inputCount, codebook,
cbsize, 1, closest_cb, &enc->randctx);
if (ret < 0)
return ret;
ret = avpriv_do_elbg(points, 6 * c_size, inputCount, codebook,
cbsize, 1, closest_cb, &enc->randctx);
if (ret < 0)

View File

@ -163,9 +163,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
}
/* compute the codebook */
avpriv_init_elbg(elbg->codeword, NB_COMPONENTS, elbg->codeword_length,
elbg->codebook, elbg->codebook_length, elbg->max_steps_nb,
elbg->codeword_closest_codebook_idxs, &elbg->lfg);
avpriv_do_elbg(elbg->codeword, NB_COMPONENTS, elbg->codeword_length,
elbg->codebook, elbg->codebook_length, elbg->max_steps_nb,
elbg->codeword_closest_codebook_idxs, &elbg->lfg);