Atmel Software Framework

jquant2.c File Reference
#include "jinclude.h"
#include "jpeglib.h"

Data Structures

struct  box
 
struct  my_cquantizer
 

Macros

#define B_SCALE   1 /* and B by this much */
 
#define BOX_C0_ELEMS   (1<<BOX_C0_LOG) /* # of hist cells in update box */
 
#define BOX_C0_LOG   (HIST_C0_BITS-3)
 
#define BOX_C0_SHIFT   (C0_SHIFT + BOX_C0_LOG)
 
#define BOX_C1_ELEMS   (1<<BOX_C1_LOG)
 
#define BOX_C1_LOG   (HIST_C1_BITS-3)
 
#define BOX_C1_SHIFT   (C1_SHIFT + BOX_C1_LOG)
 
#define BOX_C2_ELEMS   (1<<BOX_C2_LOG)
 
#define BOX_C2_LOG   (HIST_C2_BITS-3)
 
#define BOX_C2_SHIFT   (C2_SHIFT + BOX_C2_LOG)
 
#define C0_SCALE   B_SCALE
 
#define C0_SHIFT   (BITS_IN_JSAMPLE-HIST_C0_BITS)
 
#define C1_SCALE   G_SCALE
 
#define C1_SHIFT   (BITS_IN_JSAMPLE-HIST_C1_BITS)
 
#define C2_SCALE   R_SCALE
 
#define C2_SHIFT   (BITS_IN_JSAMPLE-HIST_C2_BITS)
 
#define G_SCALE   3 /* scale G distances by this much */
 
#define HIST_C0_BITS   5 /* bits of precision in R/B histogram */
 
#define HIST_C0_ELEMS   (1<<HIST_C0_BITS)
 
#define HIST_C1_BITS   6 /* bits of precision in G histogram */
 
#define HIST_C1_ELEMS   (1<<HIST_C1_BITS)
 
#define HIST_C2_BITS   5 /* bits of precision in B/R histogram */
 
#define HIST_C2_ELEMS   (1<<HIST_C2_BITS)
 
#define JPEG_INTERNALS
 
#define MAXNUMCOLORS   (MAXJSAMPLE+1) /* maximum size of colormap */
 
#define R_SCALE   2 /* scale R distances by this much */
 
#define STEP_C0   ((1 << C0_SHIFT) * C0_SCALE)
 
#define STEP_C1   ((1 << C1_SHIFT) * C1_SCALE)
 
#define STEP_C2   ((1 << C2_SHIFT) * C2_SCALE)
 
#define STEPSIZE   ((MAXJSAMPLE+1)/16)
 

Typedefs

typedef boxboxptr
 
typedef INT16 FSERROR
 
typedef FSERROR FARFSERRPTR
 
typedef histcell hist1d [HIST_C2_ELEMS]
 
typedef hist1d FARhist2d
 
typedef hist2dhist3d
 
typedef UINT16 histcell
 
typedef histcell FARhistptr
 
typedef int LOCFSERROR
 
typedef my_cquantizermy_cquantize_ptr
 

Functions

 compute_color (cinfo,&boxlist[i], i)
 
 find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2, int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
 
 find_best_colors (cinfo, minc0, minc1, minc2, numcolors, colorlist, bestcolor)
 
 find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2, JSAMPLE colorlist[])
 
 finish_pass1 (j_decompress_ptr cinfo)
 
 finish_pass2 (j_decompress_ptr cinfo)
 
 for (i=0, boxp=boxlist;i< numboxes;i++, boxp++)
 
 for (c1=c1min;c1<=c1max;c1++)
 
 for (row=0;row< num_rows;row++)
 
 for (;in<=MAXJSAMPLE;in++)
 
 jinit_2pass_quantizer (j_decompress_ptr cinfo)
 
 median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes, int desired_colors)
 
 new_color_map_2_quant (j_decompress_ptr cinfo)
 
 pass2_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
 
 prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
 
 start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
 
 TRACEMS1 (cinfo, 1, JTRC_QUANT_SELECTED, numboxes)
 
 update_box (cinfo,&boxlist[0])
 

Variables

have_c0min __pad0__
 
have_c0max __pad1__
 
have_c1min __pad2__
 
have_c1max __pad3__
 
have_c2min __pad4__
 
have_c2max __pad5__
 
cinfo actual_number_of_colors = numboxes
 
JSAMPLE bestcolor [BOX_C0_ELEMS *BOX_C1_ELEMS *BOX_C2_ELEMS]
 
 boxlist
 
int c0 = BOX_C0_LOG
 
int c0max = boxp->c0max
 
int c0min = boxp->c0min
 
long c0total = 0
 
int c1 = BOX_C1_LOG
 
int c1max = boxp->c1max
 
int c1min = boxp->c1min
 
long c1total = 0
 
int c2 = BOX_C2_LOG
 
int c2max = boxp->c2max
 
int c2min = boxp->c2min
 
long c2total = 0
 
register histptr cachep
 
long ccount = 0
 
JDIMENSION col
 
boxp colorcount = ccount
 
JSAMPLE colorlist [MAXNUMCOLORS]
 
cinfo colormap [0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total)
 
long count
 
register JSAMPLEcptr
 
c0<<=BOX_C0_LOG;c1
<<=BOX_C1_LOG;c2<<=BOX_C2_LOG;cptr=bestcolor;for(ic0=0;ic0
< BOX_C0_ELEMS;ic0++){for(ic1=0;ic1
< BOX_C1_ELEMS;ic1++){cachep=&histogram[c0+ic0][c1+ic1][c2];for(ic2=0;ic2
< BOX_C2_ELEMS;ic2++){*cachep++=(histcell)(GETJSAMPLE(*cptr++)+1);}}}}pass2_no_dither(j_decompress_ptr
cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int
num_rows){my_cquantize_ptr
cquantize=(my_cquantize_ptr)
cinfo-> 
cquantize
 
INT32 dist0
 
INT32 dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE
 
INT32 dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE
 
cquantize error_limiter = table
 
goto have_c0max
 
goto have_c1max
 
goto have_c1min
 
goto have_c2max
 
goto have_c2min
 
hist3d histogram = cquantize->histogram
 
histptr histp
 
register int i
 
int ic0
 
int ic1
 
int ic2
 
int in
 
register JSAMPROW inptr
 
register long maxc = 0
 
register INT32 maxv = 0
 
int minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1)
 
int minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1)
 
int minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1)
 
int numboxes
 
int numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist)
 
int out = 0
 
register JSAMPROW outptr
 
int row
 
int * table
 
long total = 0
 
boxp volume = dist0*dist0 + dist1*dist1 + dist2*dist2
 
boxptr which = NULL
 
JDIMENSION width = cinfo->output_width
 

#define B_SCALE   1 /* and B by this much */
#define BOX_C0_ELEMS   (1<<BOX_C0_LOG) /* # of hist cells in update box */

Referenced by find_best_colors().

#define BOX_C0_LOG   (HIST_C0_BITS-3)
#define BOX_C0_SHIFT   (C0_SHIFT + BOX_C0_LOG)

Referenced by find_nearby_colors().

#define BOX_C1_ELEMS   (1<<BOX_C1_LOG)

Referenced by find_best_colors().

#define BOX_C1_LOG   (HIST_C1_BITS-3)
#define BOX_C1_SHIFT   (C1_SHIFT + BOX_C1_LOG)

Referenced by find_nearby_colors().

#define BOX_C2_ELEMS   (1<<BOX_C2_LOG)

Referenced by find_best_colors().

#define BOX_C2_LOG   (HIST_C2_BITS-3)
#define BOX_C2_SHIFT   (C2_SHIFT + BOX_C2_LOG)

Referenced by find_nearby_colors().

#define C0_SCALE   B_SCALE
#define C0_SHIFT   (BITS_IN_JSAMPLE-HIST_C0_BITS)
#define C1_SCALE   G_SCALE
#define C1_SHIFT   (BITS_IN_JSAMPLE-HIST_C1_BITS)
#define C2_SCALE   R_SCALE
#define C2_SHIFT   (BITS_IN_JSAMPLE-HIST_C2_BITS)
#define G_SCALE   3 /* scale G distances by this much */
#define HIST_C0_BITS   5 /* bits of precision in R/B histogram */
#define HIST_C0_ELEMS   (1<<HIST_C0_BITS)
#define HIST_C1_BITS   6 /* bits of precision in G histogram */
#define HIST_C1_ELEMS   (1<<HIST_C1_BITS)
#define HIST_C2_BITS   5 /* bits of precision in B/R histogram */
#define HIST_C2_ELEMS   (1<<HIST_C2_BITS)
#define JPEG_INTERNALS
#define MAXNUMCOLORS   (MAXJSAMPLE+1) /* maximum size of colormap */
#define R_SCALE   2 /* scale R distances by this much */
#define STEP_C0   ((1 << C0_SHIFT) * C0_SCALE)

Referenced by find_best_colors().

#define STEP_C1   ((1 << C1_SHIFT) * C1_SCALE)

Referenced by find_best_colors().

#define STEP_C2   ((1 << C2_SHIFT) * C2_SCALE)

Referenced by find_best_colors().

#define STEPSIZE   ((MAXJSAMPLE+1)/16)

typedef box* boxptr
typedef INT16 FSERROR
typedef FSERROR FAR* FSERRPTR
typedef histcell hist1d[HIST_C2_ELEMS]
typedef hist1d FAR* hist2d
typedef hist2d* hist3d
typedef UINT16 histcell
typedef histcell FAR* histptr
typedef int LOCFSERROR

compute_color ( cinfo  ,
boxlist[i],
i   
)
find_best_colors ( j_decompress_ptr  cinfo,
int  minc0,
int  minc1,
int  minc2,
int  numcolors,
JSAMPLE  colorlist[],
JSAMPLE  bestcolor[] 
)
find_best_colors ( cinfo  ,
minc0  ,
minc1  ,
minc2  ,
numcolors  ,
colorlist  ,
bestcolor   
)
find_nearby_colors ( j_decompress_ptr  cinfo,
int  minc0,
int  minc1,
int  minc2,
JSAMPLE  colorlist[] 
)
finish_pass2 ( j_decompress_ptr  cinfo)

Referenced by start_pass_2_quant().

for ( i  = 0)

References box::colorcount, and box::volume.

for ( c1  = c1minc1 <= c1maxc1++)

References c0, c1, c2, c2max, c2min, histogram, and histp.

for ( )
for ( ;in<=MAXJSAMPLE;in++  )

References in, out, and table.

median_cut ( j_decompress_ptr  cinfo,
boxptr  boxlist,
int  numboxes,
int  desired_colors 
)
new_color_map_2_quant ( j_decompress_ptr  cinfo)

References my_cquantizer::needs_zeroed, and TRUE.

Referenced by jinit_2pass_quantizer().

prescan_quantize ( j_decompress_ptr  cinfo,
JSAMPARRAY  input_buf,
JSAMPARRAY  output_buf,
int  num_rows 
)
TRACEMS1 ( cinfo  ,
,
JTRC_QUANT_SELECTED  ,
numboxes   
)
update_box ( cinfo  ,
boxlist[0] 
)

Referenced by median_cut().

have_c0min __pad0__
have_c0max __pad1__
have_c1min __pad2__
have_c1max __pad3__
have_c2min __pad4__
have_c2max __pad5__
cinfo actual_number_of_colors = numboxes
boxlist
Initial value:
= (boxptr) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box))
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:262
#define SIZEOF(object)
Definition: jinclude.h:80
box * boxptr
Definition: jquant2.c:269
#define JPOOL_IMAGE
Definition: jpeglib.h:750
(* cinfo)(cinfo,(long) length)
Definition: jdmarker.c:730
Definition: jquant2.c:258
int c0max = boxp->c0max
int c0min = boxp->c0min
long c0total = 0
int c1max = boxp->c1max
int c1min = boxp->c1min
long c1total = 0
int c2max = boxp->c2max

Referenced by for().

int c2min = boxp->c2min

Referenced by for().

long c2total = 0
register histptr cachep

Referenced by for(), and pass2_fs_dither().

ccount = 0
boxp colorcount = ccount
JSAMPLE colorlist[MAXNUMCOLORS]
cinfo colormap = (JSAMPLE) ((c0total + (total>>1)) / total)

Referenced by create_colormap().

register JSAMPLE* cptr

Referenced by find_best_colors().

INT32 dist0

Referenced by find_best_colors().

dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE

Referenced by find_best_colors().

dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE

Referenced by find_best_colors().

cquantize error_limiter = table
goto have_c0max
goto have_c1max
goto have_c1min
goto have_c2max
goto have_c2min
hist3d histogram = cquantize->histogram
histptr histp

Referenced by for(), and prescan_quantize().

int i
Initial value:
{
register boxptr boxp
Definition: jquant2.c:258
int ic0

Referenced by find_best_colors().

int ic1

Referenced by find_best_colors().

int ic2

Referenced by find_best_colors().

int in

Referenced by dsp_adpcm_ima_decode(), and for().

register long maxc = 0
register INT32 maxv = 0
minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1)

Referenced by find_nearby_colors().

minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1)

Referenced by find_nearby_colors().

minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1)

Referenced by find_nearby_colors().

numboxes
Initial value:
{
boxlist
Definition: jquant2.c:547
Definition: jquant2.c:258

Referenced by median_cut().

table
Initial value:
{
c0<<=BOX_C0_LOG;c1<<=BOX_C1_LOG;c2<<=BOX_C2_LOG;cptr=bestcolor;for(ic0=0;ic0< BOX_C0_ELEMS;ic0++){for(ic1=0;ic1< BOX_C1_ELEMS;ic1++){cachep=&histogram[c0+ic0][c1+ic1][c2];for(ic2=0;ic2< BOX_C2_ELEMS;ic2++){*cachep++=(histcell)(GETJSAMPLE(*cptr++)+1);}}}}pass2_no_dither(j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows){my_cquantize_ptr cquantize=(my_cquantize_ptr) cinfo-> cquantize
Definition: jquant2.c:919
my_cquantizer * my_cquantize_ptr
Definition: jquant2.c:211
(* cinfo)(cinfo,(long) length)
Definition: jdmarker.c:730
Definition: jquant2.c:193

Referenced by for().

long total = 0
boxp volume = dist0*dist0 + dist1*dist1 + dist2*dist2
return which = NULL