?? ftmcp100.c
字號:
GLOBAL(void) ftmcp100_dump_yuv (j_decompress_ptr cinfo)
{
#ifdef VPE_OUTPUT
#ifdef VPE_DUMP_YUV
int ci;
jpeg_component_info *compptr;
FTMCP100_CODEC *pCodec=(FTMCP100_CODEC *)cinfo->pCodec;
RTL_DEBUG_OUT(0x60000000) // instruct the hardware to open a YUV file for dumping
//for (ci = 0; ci < cinfo->comps_in_scan; ci++)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;ci++, compptr++)
{
int m; // total words count in one component
unsigned int *p=(unsigned int *)pCodec->outdata[ci];
//compptr = cinfo->cur_comp_info[ci];
// calculate the total blocks = blocks per MCU * total MCU count
if(jpeg_has_multiple_scans(cinfo))
m=compptr->MCU_blocks*compptr->width_in_blocks*compptr->height_in_blocks;
else
m=compptr->MCU_blocks*cinfo->MCUs_per_row*cinfo->MCU_rows_in_scan;
// calculate total words , 16 words for each block
m=m<<4;
while(m--)
{
RTL_DEBUG_OUT(0x70000000 | (unsigned int)p)
p++;
}
}
RTL_DEBUG_OUT(0x60000001) // instruct the hardware to close a YUV file previously opened by 'RTL_DEBUG_OUT(0x60000000)' operation
#endif
#endif
}
// copied from GZIP source codes
/*
Huffman code decoding is performed using a multi-level table lookup.
The fastest way to decode is to simply build a lookup table whose
size is determined by the longest code. However, the time it takes
to build this table can also be a factor if the data being decoded
is not very long. The most common codes are necessarily the
shortest codes, so those codes dominate the decoding time, and hence
the speed. The idea is you can have a shorter table that decodes the
shorter, more probable codes, and then point to subsidiary tables for
the longer codes. The time it costs to decode the longer codes is
then traded against the time it takes to make longer tables.
This results of this trade are in the variables lbits and dbits
below. lbits is the number of bits the first level table for literal/
length codes can decode in one step, and dbits is the same thing for
the distance codes. Subsequent tables are also less than or equal to
those sizes. These values may be adjusted either when all of the
codes are shorter than that, in which case the longest code length in
bits is used, or when the shortest code is *longer* than the requested
table size, in which case the length of the shortest code in bits is
used.
There are two different values for the two tables, since they code a
different number of possibilities each. The literal/length table
codes 286 possible values, or in a flat code, a little over eight
bits. The distance table codes 30 possible values, or a little less
than five bits, flat. The optimum values for speed end up being
about one bit more than those, so lbits is 8+1 and dbits is 5+1.
The optimum values may differ though from machine to machine, and
possibly even between compilers. Your mileage may vary.
*/
//int huft_build(b, n, s, d, e, t, m)
//unsigned *b; /* code lengths in bits (all assumed <= BMAX) */
//unsigned n; /* number of codes (assumed <= N_MAX) */
//unsigned s; /* number of simple-valued codes (0..s-1) */
//unsigned *v; /* added by Leo, the array of huffman value */
//unsigned *ct; /* added by Leo, the table of huffman codeword */
//ush *d; /* list of base values for non-simple codes */
//ush *e; /* list of extra bits for non-simple codes */
//struct huft **t; /* result: starting table */
//int *m; /* maximum lookup bits, returns actual */
GLOBAL(int) huft_build(j_decompress_ptr cinfo,unsigned *b,unsigned n,unsigned s,unsigned int *v,unsigned *ct,unsigned short *d, unsigned short *e, struct huft **t, int *m)
/* Given a list of code lengths and a maximum table size, make a set of
tables to decode that set of codes. Return zero on success, one if
the given code set is incomplete (the tables are still built in this
case), two if the input is invalid (all zero length codes or an
oversubscribed set of lengths), and three if not enough memory. */
{
unsigned a; /* counter for codes of length k */
unsigned c[BMAX+1]; /* bit length count table */
unsigned f; /* i repeats in table every f entries */
int g; /* maximum code length */
int h; /* table level */
register unsigned i; /* counter, current code */
register unsigned j; /* counter */
register int k; /* number of bits in current code */
int l; /* bits per table (returned in m) */
register unsigned *p; /* pointer into c[], b[], or v[] */
register struct huft *q; /* points to current table */
struct huft r; /* table entry for structure assignment */
struct huft *u[BMAX]; /* table stack */
//unsigned v[N_MAX]; /* values in order of bit length */
register int w; /* bits before this table == (l * h) */
unsigned x[BMAX+1]; /* bit offsets, then code stack */
unsigned *xp; /* pointer into x */
//int y; /* number of dummy codes added */
unsigned z; /* number of entries in current table */
unsigned int ii,cc=0; // added by Leo for another counter
unsigned int mask; // added by Leo for mask
unsigned int hufts=0; // add by Leo, number of valid struct huft entry allocated so far
unsigned int hufts_stk[BMAX]; // added by Leo, start offset of each table's stack
/* Generate counts for each bit length */
//memzero(c, sizeof(c));
memset ((char *)(c), 0, sizeof(c));
p = b; i = n;
do {
c[*p]++; /* assume all entries <= BMAX */
p++; /* Can't combine with above line (Solaris bug) */
} while (--i);
if (c[0] == n) /* null input--all zero length codes */
{
*t = (struct huft *)NULL;
*m = 0;
return 0;
}
/* Find minimum and maximum length, bound *m by those */
l = *m;
for (j = 1; j <= BMAX; j++)
if (c[j])
break;
k = j; /* minimum code length */
if ((unsigned)l < j)
l = j;
for (i = BMAX; i; i--)
if (c[i])
break;
g = i; /* maximum code length */
if ((unsigned)l > i)
l = i;
*m = l;
/* Adjust last length count to fill out codes, if needed */
//for (y = 1 << j; j < i; j++, y <<= 1)
//if ((y -= c[j]) < 0)
//return 2; /* bad input: more codes than bits */
//if ((y -= c[i]) < 0)
//return 2;
//c[i] += y;
/* Generate starting offsets into the value table for each length */
x[1] = j = 0;
p = c + 1; xp = x + 2;
while (--i) { /* note that i == g from above */
*xp++ = (j += *p++);
}
/* Make a table of values in order of bit lengths */
//p = b; i = 0;
//do {
// if ((j = *p++) != 0)
// v[x[j]++] = i;
//} while (++i < n);
/* Generate the Huffman codes and for each, make the table entries */
x[0] = i = 0; /* first Huffman code is zero */
i=*ct; // added by Leo
p = v; /* grab values in bit order */
h = -1; /* no tables yet--level -1 */
w = -l; /* bits decoded == (l * h) */
u[0] = (struct huft *)NULL; /* just to keep compilers happy */
q = (struct huft *)NULL; /* ditto */
z = 0; /* ditto */
/* go through the bit lengths (k already is bits in shortest code) */
for (; k <= g; k++)
{
a = c[k];
while (a--)
{
/* here i is the Huffman code of length k bits for value *p */
/* make tables up to required level */
while (k > w + l)
{
h++;
w += l; /* previous table always l bits */
/* compute minimum size table less than or equal to l bits */
z = (z = g - w) > (unsigned)l ? l : z; /* upper limit on table size */
if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
{ /* too few codes for k-w bit table */
f -= a + 1; /* deduct codes from patterns left */
xp = c + k;
while (++j < z) /* try smaller tables up to z bits */
{
if ((f <<= 1) <= *++xp)
break; /* enough codes to use up j bits */
f -= *xp; /* else deduct codes from patterns */
}
}
j=(j>z)?z:j; // added by Leo for limiting the maximum upper limit for working around ConvGrid.jpg and huffman table2 jpg test patterns
z = 1 << j; /* table entries for j-bit table */
//z = 1 << ((j>z)?z:j); /* table entries for j-bit table */ // modified by Leo
/* allocate and link in new table */
//if ((q = (struct huft *)malloc((z + 1)*sizeof(struct huft))) ==
// (struct huft *)NULL)
if ((q = (struct huft *) ((*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,(z + 1)*sizeof(struct huft)))) == NULL)
{
//if (h) huft_free(u[0]);
return 3; /* not enough memory */
}
// added by Leo , we clean the allocated memory
//MEMZERO(q,(z + 1)*sizeof(struct huft)); let's don't clean this memory for hardware simulation purpose
*t = q + 1; /* link to list for huft_free() */
*(t = &(q->nextpt)) = (struct huft *)NULL;
q->tblsize=z; // record the size of table in halfword size
//u[h] = ++q; // table starts after link
hufts=(hufts%z)?(hufts+z-(hufts%z)):hufts;
hufts_stk[h]=hufts;
q->data.offset=hufts; // record the offset of this table
hufts += z;
u[h] = ++q; // table starts after link
/* connect to last table, if there is one */
if (h)
{
x[h] = i>> (k-w); /* save pattern for backing up */
//r.b = (unsigned char)l; /* bits to dump before this table */
//r.e = (unsigned char)(16 + j); /* bits in this table */
//r.v.t = q; /* pointer to this table */
// added by Leo
r.tbl=1;
r.valid=1;
r.codelen=j-1;
r.data.offset=hufts_stk[h];
//j = i >> (w - l); /* (get around Turbo C bug) */
//u[h-1][j] = r; /* connect to last table */
ii = (i&(((1<<l)-1)<<(k-w))) >> (k-w);
u[h-1][ii] = r; /* connect to last table */
}
}
/* set up table entry in r */
//r.b = (unsigned char)(k - w);
//if (p >= v + n)
// r.e = 99; /* out of values--invalid code */
//else if (*p < s)
//{
// r.e = (unsigned char)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
// r.v.n = (unsigned char)(*p); /* simple code is just the value */
// p++; /* one compiler does not like *p++ */
//}
//else
//{
// r.e = (unsigned char)e[*p - s]; /* non-simple--look up in lists */
// r.v.n = d[*p++ - s];
//}
// added by Leo
r.tbl=0;
r.valid=1;
r.codelen=(k-w)-1;
r.data.value=*p++;
/* fill code-like entries with r */
//f = 1 << (k - w);
//for (j = i >> w; j < z; j += f)
// q[j] = r;
f = (j-(k-w));
mask = (1<<(k-w))-1; // to be used as mask
i = (i&mask) << f;
for (ii = 0 ; ii < (unsigned)(1<<f); ii++,i++)
q[i] = r;
/* backwards increment the k-bit code i */
//for (j = 1 << (k - 1); i & j; j >>= 1)
// i ^= j;
//i ^= j;
i=*(++ct); // modified by Leo. get next huffman code
cc++;
/* backup over finished tables */
//while ((i & ((1 << w) - 1)) != x[h])
f=b[cc]-w; // get the next symbol's code length
while ( ((i&(((1<<w)-1)<<f))>>f) != x[h] )
{
h--; /* don't need to update q */
w -= l;
}
}
}
/* Return true (1) if we were given an incomplete table */
//return y != 0 && g != 1;
return 0; // modified by Leo
}
/*
GLOBAL(int) huft_free(struct huft *t) // table to free
// Free the malloc'ed tables built by huft_build(), which makes a linked
// list of the tables it made, with the links in a dummy first entry of
// each table.
{
register struct huft *p, *q;
// Go through linked list, freeing from the malloced (t[-1]) address.
p = t;
while (p != (struct huft *)NULL)
{
q = (--p)->v.t;
free((char*)p);
p = q;
}
return 0;
}
*/
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -