FFmpeg
Data Structures | Macros | Functions
elbg.c File Reference
#include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/lfg.h"
#include "elbg.h"

Go to the source code of this file.

Data Structures

struct  cell_s
 In the ELBG jargon, a cell is the set of points that are closest to a codebook entry. More...
 
struct  ELBGContext
 ELBG internal data. More...
 

Macros

#define DELTA_ERR_MAX   0.1
 Precision of the ELBG algorithm (as percentage error) More...
 
#define BIG_PRIME   433494437LL
 
#define ALLOCATE_IF_NECESSARY(field, new_elements, multiplicator)
 

Functions

static int distance_limited (int *a, int *b, int dim, int limit)
 
static void vect_division (int *res, int *vect, int div, int dim)
 
static int eval_error_cell (ELBGContext *elbg, int *centroid, cell *cells)
 
static int get_closest_codebook (ELBGContext *elbg, int index)
 
static int get_high_utility_cell (ELBGContext *elbg)
 
static int simple_lbg (ELBGContext *elbg, int dim, int *centroid[3], int newutility[3], int *points, cell *cells)
 Implementation of the simple LBG algorithm for just two codebooks. More...
 
static void get_new_centroids (ELBGContext *elbg, int huc, int *newcentroid_i, int *newcentroid_p)
 
static void shift_codebook (ELBGContext *elbg, int *indexes, int *newcentroid[3])
 Add the points in the low utility cell to its closest cell. More...
 
static void evaluate_utility_inc (ELBGContext *elbg)
 
static void update_utility_and_n_cb (ELBGContext *elbg, int idx, int newutility)
 
static void try_shift_candidate (ELBGContext *elbg, int idx[3])
 Evaluate if a shift lower the error. More...
 
static void do_shiftings (ELBGContext *elbg)
 Implementation of the ELBG block. More...
 
static void do_elbg (ELBGContext *av_restrict elbg, int *points, int numpoints, int max_steps)
 
static void init_elbg (ELBGContext *av_restrict elbg, int *points, int *temp_points, int numpoints, int max_steps)
 Initialize the codebook vector for the elbg algorithm. More...
 
int avpriv_elbg_do (ELBGContext **elbgp, int *points, int dim, int numpoints, int *codebook, int num_cb, int max_steps, int *closest_cb, AVLFG *rand_state, uintptr_t flags)
 Implementation of the Enhanced LBG Algorithm Based on the paper "Neural Networks 14:1219-1237" that can be found in http://citeseer.ist.psu.edu/patan01enhanced.html . More...
 
av_cold void avpriv_elbg_free (ELBGContext **elbgp)
 Free an ELBGContext and reset the pointer to it. More...
 

Detailed Description

Codebook Generator using the ELBG algorithm

Definition in file elbg.c.

Macro Definition Documentation

◆ DELTA_ERR_MAX

#define DELTA_ERR_MAX   0.1

Precision of the ELBG algorithm (as percentage error)

Definition at line 33 of file elbg.c.

◆ BIG_PRIME

#define BIG_PRIME   433494437LL

Definition at line 414 of file elbg.c.

◆ ALLOCATE_IF_NECESSARY

#define ALLOCATE_IF_NECESSARY (   field,
  new_elements,
  multiplicator 
)
Value:
if (elbg->field ## _allocated < new_elements) { \
av_freep(&elbg->field); \
elbg->field = av_malloc_array(new_elements, \
multiplicator * sizeof(*elbg->field)); \
if (!elbg->field) { \
elbg->field ## _allocated = 0; \
return AVERROR(ENOMEM); \
} \
elbg->field ## _allocated = new_elements; \
}

Function Documentation

◆ distance_limited()

static int distance_limited ( int a,
int b,
int  dim,
int  limit 
)
inlinestatic

Definition at line 74 of file elbg.c.

Referenced by do_elbg(), eval_error_cell(), get_closest_codebook(), shift_codebook(), and simple_lbg().

◆ vect_division()

static void vect_division ( int res,
int vect,
int  div,
int  dim 
)
inlinestatic

Definition at line 86 of file elbg.c.

Referenced by do_elbg(), simple_lbg(), and try_shift_candidate().

◆ eval_error_cell()

static int eval_error_cell ( ELBGContext elbg,
int centroid,
cell *  cells 
)
static

Definition at line 97 of file elbg.c.

Referenced by try_shift_candidate().

◆ get_closest_codebook()

static int get_closest_codebook ( ELBGContext elbg,
int  index 
)
static

Definition at line 106 of file elbg.c.

Referenced by do_shiftings().

◆ get_high_utility_cell()

static int get_high_utility_cell ( ELBGContext elbg)
static

Definition at line 121 of file elbg.c.

Referenced by do_shiftings().

◆ simple_lbg()

static int simple_lbg ( ELBGContext elbg,
int  dim,
int centroid[3],
int  newutility[3],
int points,
cell *  cells 
)
static

Implementation of the simple LBG algorithm for just two codebooks.

Definition at line 146 of file elbg.c.

Referenced by try_shift_candidate().

◆ get_new_centroids()

static void get_new_centroids ( ELBGContext elbg,
int  huc,
int newcentroid_i,
int newcentroid_p 
)
static

Definition at line 187 of file elbg.c.

Referenced by try_shift_candidate().

◆ shift_codebook()

static void shift_codebook ( ELBGContext elbg,
int indexes,
int newcentroid[3] 
)
static

Add the points in the low utility cell to its closest cell.

Split the high utility cell, putting the separated points in the (now empty) low utility cell.

Parameters
elbgInternal elbg data
indexes{luc, huc, cluc}
newcentroidA vector with the position of the new centroids

Definition at line 223 of file elbg.c.

Referenced by try_shift_candidate().

◆ evaluate_utility_inc()

static void evaluate_utility_inc ( ELBGContext elbg)
static

Definition at line 251 of file elbg.c.

Referenced by do_shiftings(), and try_shift_candidate().

◆ update_utility_and_n_cb()

static void update_utility_and_n_cb ( ELBGContext elbg,
int  idx,
int  newutility 
)
static

Definition at line 263 of file elbg.c.

Referenced by try_shift_candidate().

◆ try_shift_candidate()

static void try_shift_candidate ( ELBGContext elbg,
int  idx[3] 
)
static

Evaluate if a shift lower the error.

If it does, call shift_codebooks and update elbg->error, elbg->utility and elbg->nearest_cb.

Parameters
elbgInternal elbg data
idx{luc (low utility cell, huc (high utility cell), cluc (closest cell to low utility cell)}

Definition at line 279 of file elbg.c.

Referenced by do_shiftings().

◆ do_shiftings()

static void do_shiftings ( ELBGContext elbg)
static

Implementation of the ELBG block.

Definition at line 330 of file elbg.c.

Referenced by do_elbg().

◆ do_elbg()

static void do_elbg ( ELBGContext *av_restrict  elbg,
int points,
int  numpoints,
int  max_steps 
)
static

Definition at line 349 of file elbg.c.

Referenced by avpriv_elbg_do(), and init_elbg().

◆ init_elbg()

static void init_elbg ( ELBGContext *av_restrict  elbg,
int points,
int temp_points,
int  numpoints,
int  max_steps 
)
static

Initialize the codebook vector for the elbg algorithm.

If numpoints <= 24 * num_cb this function fills codebook with random numbers. If not, it calls do_elbg for a (smaller) random sample of the points in points.

Definition at line 422 of file elbg.c.

Referenced by avpriv_elbg_do().

◆ avpriv_elbg_do()

int avpriv_elbg_do ( struct ELBGContext **  ctx,
int points,
int  dim,
int  numpoints,
int codebook,
int  num_cb,
int  num_steps,
int closest_cb,
AVLFG rand_state,
uintptr_t  flags 
)

Implementation of the Enhanced LBG Algorithm Based on the paper "Neural Networks 14:1219-1237" that can be found in http://citeseer.ist.psu.edu/patan01enhanced.html .

Parameters
ctxA pointer to a pointer to an already allocated ELBGContext or a pointer to NULL. In the latter case, this function will allocate an ELBGContext and put a pointer to it in *ctx.
pointsInput points.
dimDimension of the points.
numpointsNum of points in **points.
codebookPointer to the output codebook. Must be allocated.
num_cbNumber of points in the codebook.
num_stepsThe maximum number of steps. One step is already a good compromise between time and quality.
closest_cbReturn the closest codebook to each point. Must be allocated.
rand_stateA random number generator state. Should be already initialized by av_lfg_init().
flagsCurrently unused; must be set to 0.
Returns
< 0 in case of error, 0 otherwise

Definition at line 446 of file elbg.c.

Referenced by a64multi_encode_frame(), encode_frame(), filter_frame(), generate_codebook(), and quantize().

◆ avpriv_elbg_free()

av_cold void avpriv_elbg_free ( ELBGContext **  elbgp)

Free an ELBGContext and reset the pointer to it.

Definition at line 499 of file elbg.c.

Referenced by a64multi_close_encoder(), cinepak_encode_end(), encode_end(), roq_encode_end(), and uninit().

AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31