Skip to content

Commit

Permalink
Use precomputed table
Browse files Browse the repository at this point in the history
From jpeglib-turbo r1221:
Integrate a slightly modified version of Mozilla's patch for
precomputing the bit-counting LUT.  This is useful if the table needs
to be shared among multiple processes, although the primary reason for
doing that is reduced footprint on mobile devices, which are probably
already covered by the clz intrinsic code.
  • Loading branch information
fbossen committed Jul 24, 2014
1 parent 3adc64a commit 1aa50b7
Show file tree
Hide file tree
Showing 3 changed files with 4,100 additions and 23 deletions.
13 changes: 1 addition & 12 deletions jcdctmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,7 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
#endif /* DCT_FLOAT_SUPPORTED */

#include "jchuff.h"

static unsigned char jpeg_nbits_table[65536];
static int jpeg_nbits_table_init = 0;
#include "jpeg_nbits_table.h"

static const float jpeg_lambda_weights_flat[64] = {
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
Expand Down Expand Up @@ -660,15 +658,6 @@ quantize_trellis(j_compress_ptr cinfo, c_derived_tbl *actbl, JBLOCKROW coef_bloc
requires_eob[0] = 0;
}

if(!jpeg_nbits_table_init) {
for(i = 0; i < 65536; i++) {
int nbits = 0, temp = i;
while (temp) {temp >>= 1; nbits++;}
jpeg_nbits_table[i] = nbits;
}
jpeg_nbits_table_init = 1;
}

norm = 0.0;
for (i = 1; i < DCTSIZE2; i++) {
norm += qtbl->quantval[i] * qtbl->quantval[i];
Expand Down
12 changes: 1 addition & 11 deletions jchuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include "jchuff.h" /* Declarations shared with jcphuff.c */
#include <limits.h>

static unsigned char jpeg_nbits_table[65536];
static int jpeg_nbits_table_init = 0;
#include "jpeg_nbits_table.h"

#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
Expand Down Expand Up @@ -271,15 +270,6 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
dtbl->ehufco[i] = huffcode[p];
dtbl->ehufsi[i] = huffsize[p];
}

if(!jpeg_nbits_table_init) {
for(i = 0; i < 65536; i++) {
int nbits = 0, temp = i;
while (temp) {temp >>= 1; nbits++;}
jpeg_nbits_table[i] = nbits;
}
jpeg_nbits_table_init = 1;
}
}


Expand Down
Loading

0 comments on commit 1aa50b7

Please sign in to comment.