~ubuntu-branches/debian/squeeze/gstreamer0.10-ffmpeg/squeeze

« back to all changes in this revision

Viewing changes to gst-libs/ext/ffmpeg/libavcodec/elbg.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2010-02-19 18:14:59 UTC
  • mfrom: (4.1.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20100219181459-mect96st3px2jfsi
Tags: 0.10.9.2-1
* New upstream pre-release:
  + debian/patches/03_restricted-caps.patch,
    debian/patches/04_ignore-vdpau.patch:
    - Dropped, merged upstream.
* debian/patches/03_too-new-codec-ids.patch:
  + Disable some ffmpeg codec IDs because Debian's
    ffmpeg is once again too old...

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include <string.h>
27
27
 
28
 
#include "libavutil/random.h"
 
28
#include "libavutil/lfg.h"
29
29
#include "elbg.h"
30
30
#include "avcodec.h"
31
31
 
52
52
    int *utility_inc;
53
53
    int *nearest_cb;
54
54
    int *points;
55
 
    AVRandomState *rand_state;
 
55
    AVLFG *rand_state;
56
56
} elbg_data;
57
57
 
58
58
static inline int distance_limited(int *a, int *b, int dim, int limit)
105
105
{
106
106
    int i=0;
107
107
    /* Using linear search, do binary if it ever turns to be speed critical */
108
 
    int r = av_random(elbg->rand_state)%(elbg->utility_inc[elbg->numCB-1]-1) + 1;
 
108
    int r = av_lfg_get(elbg->rand_state)%elbg->utility_inc[elbg->numCB-1] + 1;
109
109
    while (elbg->utility_inc[i] < r)
110
110
        i++;
111
111
 
318
318
 
319
319
void ff_init_elbg(int *points, int dim, int numpoints, int *codebook,
320
320
                  int numCB, int max_steps, int *closest_cb,
321
 
                  AVRandomState *rand_state)
 
321
                  AVLFG *rand_state)
322
322
{
323
323
    int i, k;
324
324
 
345
345
 
346
346
void ff_do_elbg(int *points, int dim, int numpoints, int *codebook,
347
347
                int numCB, int max_steps, int *closest_cb,
348
 
                AVRandomState *rand_state)
 
348
                AVLFG *rand_state)
349
349
{
350
350
    int dist;
351
351
    elbg_data elbg_d;
355
355
    int *size_part = av_malloc(numCB*sizeof(int));
356
356
    cell *list_buffer = av_malloc(numpoints*sizeof(cell));
357
357
    cell *free_cells;
 
358
    int best_dist, best_idx = 0;
358
359
 
359
360
    elbg->error = INT_MAX;
360
361
    elbg->dim = dim;
380
381
        /* This loop evaluate the actual Voronoi partition. It is the most
381
382
           costly part of the algorithm. */
382
383
        for (i=0; i < numpoints; i++) {
383
 
            dist_cb[i] = INT_MAX;
 
384
            best_dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + best_idx*elbg->dim, dim, INT_MAX);
384
385
            for (k=0; k < elbg->numCB; k++) {
385
 
                dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, dist_cb[i]);
386
 
                if (dist < dist_cb[i]) {
387
 
                    dist_cb[i] = dist;
388
 
                    elbg->nearest_cb[i] = k;
 
386
                dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, best_dist);
 
387
                if (dist < best_dist) {
 
388
                    best_dist = dist;
 
389
                    best_idx = k;
389
390
                }
390
391
            }
 
392
            elbg->nearest_cb[i] = best_idx;
 
393
            dist_cb[i] = best_dist;
391
394
            elbg->error += dist_cb[i];
392
395
            elbg->utility[elbg->nearest_cb[i]] += dist_cb[i];
393
396
            free_cells->index = i;