⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spcadecoder.c

📁 spca5xx video for linux (v4l) driver
💻 C
📖 第 1 页 / 共 5 页
字号:
	    } else if (var_7 == 1) {		multiplier = 2;	    } else if (dC + dL >= 11 || var_7 == 2) {		multiplier = 8;	    }	    if (i_hits[index] < 7) {		bitfill -= nbits_A[cur_byte];		gkw = tab_A[cur_byte];		if (gkw == 0xfe)		    gkw = fun_A(&bitfill);	    } else if (i_hits[index] >= accum[index]) {		bitfill -= nbits_B[cur_byte];		gkw = tab_B[cur_byte];		if (cur_byte == 0)		    gkw = fun_B(&bitfill);	    } else if (i_hits[index] * 2 >= accum[index]) {		bitfill -= nbits_C[cur_byte];		gkw = tab_C[cur_byte];		if (cur_byte < 2)		    gkw = fun_C(&bitfill, gkw);	    } else if (i_hits[index] * 4 >= accum[index]) {		bitfill -= nbits_D[cur_byte];		gkw = tab_D[cur_byte];		if (cur_byte < 4)		    gkw = fun_D(&bitfill, gkw);	    } else if (i_hits[index] * 8 >= accum[index]) {		gkw = fun_E(cur_byte, &bitfill);	    } else {		gkw = fun_F(cur_byte, &bitfill);	    }	    if (gkw == 0xff)		return -3;	    {		int tmp1, tmp2;		tmp1 = (pixel_U + pixel_L) * 3 - pixel_UL * 2;		tmp1 += (tmp1 < 0) ? 3 : 0;		tmp2 = a_curve[19 + gkw] * multiplier;		tmp2 += (tmp2 < 0) ? 1 : 0;		*(output_ptr++) =		    clamp0_255[0x100 + (tmp1 >> 2) - (tmp2 >> 1)];	    }	    pixel_U = saved_pixel_UR;	    saved_pixel_UR = pixel_UR;	    if (++pixel_x == width) {		output_ptr += 6;		pixel_x = 0;		pixel_y++;	    }	    accum[index] += abs_clamp15[19 + gkw];	    if (i_hits[index]++ == 15) {		i_hits[index] = 8;		accum[index] /= 2;	    }	}    }    return 0;}void decode_spca561(unsigned char *inbuf, char *outbuf, int width,		    int height){    int i;    static char tmpbuf[650 * 490];    if (internal_spca561_decode(width, height, inbuf, tmpbuf) == 0) {	for (i = 0; i < height; i++)	    memcpy(outbuf + i * width,		   tmpbuf + (i + 2) * (width + 6) + 3, width);    }}/****************************************************************//**************       huffman decoder             ***************//****************************************************************//*need to be on init jpeg */static struct comp comp_template[MAXCOMP] = {    {0x01, 0x22, 0x00},    {0x02, 0x11, 0x01},    {0x03, 0x11, 0x01},    {0x00, 0x00, 0x00}};/* deprecated set by webcam now in spca50x *///static struct scan dscans[MAXCOMP];//static unsigned char quant[3][64];//static struct in in;//int dquant[3][64];//static struct jpginfo info;/* table de Huffman global for all */static struct dec_hufftbl dhuff[4];#define dec_huffdc (dhuff + 0)#define dec_huffac (dhuff + 2)#define M_RST0	0xd0static int fillbits(struct in *, int, unsigned int);static int dec_rec2(struct in *, struct dec_hufftbl *, int *, int, int);static int fillbits(struct in *in, int le, unsigned int bi){    int b;    int m;    if (in->marker) {	if (le <= 16)	    in->bits = bi << 16, le += 16;	return le;    }    while (le <= 24) {	b = *in->p++;	if (in->omitescape) {	    if (b == 0xff && (m = *in->p++) != 0) {		in->marker = m;		if (le <= 16)		    bi = bi << 16, le += 16;		break;	    }	}	bi = bi << 8 | b;	le += 8;    }    in->bits = bi;		/* tmp... 2 return values needed */    return le;}#define LEBI_GET(in)	(le = in->left, bi = in->bits)#define LEBI_PUT(in)	(in->left = le, in->bits = bi)#define GETBITS(in, n) (					\  (le < (n) ? le = fillbits(in, le, bi), bi = in->bits : 0),	\  (le -= (n)),							\  bi >> le & ((1 << (n)) - 1)					\)#define UNGETBITS(in, n) (	\  le += (n)			\)static void dec_initscans(struct dec_data *decode){    struct jpginfo *info = &decode->info;    struct scan *dscans = decode->dscans;    int i;    info->ns = 3;		// HARDCODED  here    info->nm = info->dri + 1;	// macroblock count    info->rm = M_RST0;    for (i = 0; i < info->ns; i++)	dscans[i].dc = 0;}static int dec_readmarker(struct in *in){    int m;    in->left = fillbits(in, in->left, in->bits);    if ((m = in->marker) == 0)	return 0;    in->left = 0;    in->marker = 0;    return m;}static int dec_checkmarker(struct dec_data *decode){    struct jpginfo *info = &decode->info;    struct scan *dscans = decode->dscans;    struct in *in = &decode->in;    int i;    if (dec_readmarker(in) != info->rm)	return -1;    info->nm = info->dri;    info->rm = (info->rm + 1) & ~0x08;    for (i = 0; i < info->ns; i++)	dscans[i].dc = 0;    return 0;}voidjpeg_reset_input_context(struct dec_data *decode, unsigned char *buf,			 int oescap){    /* set input context */    struct in *in = &decode->in;    in->p = buf;    in->omitescape = oescap;    in->left = 0;    in->bits = 0;    in->marker = 0;}static intdec_rec2(struct in *in, struct dec_hufftbl *hu, int *runp, int c, int i){    int le, bi;    le = in->left;    bi = in->bits;    if (i) {	UNGETBITS(in, i & 127);	*runp = i >> 8 & 15;	i >>= 16;    } else {	for (i = DECBITS;	     (c = ((c << 1) | GETBITS(in, 1))) >= (hu->maxcode[i]); i++);	if (i >= 16) {	    in->marker = M_BADHUFF;	    return 0;	}	i = hu->vals[hu->valptr[i] + c - hu->maxcode[i - 1] * 2];	*runp = i >> 4;	i &= 15;    }    if (i == 0) {		/* sigh, 0xf0 is 11 bit */	LEBI_PUT(in);	return 0;    }    /* receive part */    c = GETBITS(in, i);    if (c < (1 << (i - 1)))	c += (-1 << i) + 1;    LEBI_PUT(in);    return c;}#define DEC_REC(in, hu, r, i)	 (	\  r = GETBITS(in, DECBITS),		\  i = hu->llvals[r],			\  i & 128 ?				\    (					\      UNGETBITS(in, i & 127),		\      r = i >> 8 & 15,			\      i >> 16				\    )					\  :					\    (					\      LEBI_PUT(in),			\      i = dec_rec2(in, hu, &r, r, i),	\      LEBI_GET(in),			\      i					\    )					\)inline static voiddecode_mcus(struct in *in, int *dct, int n, struct scan *sc, int *maxp){    struct dec_hufftbl *hu;    int i, r, t;    int le, bi;    memset(dct, 0, n * 64 * sizeof(*dct));    le = in->left;    bi = in->bits;    while (n-- > 0) {	hu = sc->hudc.dhuff;	*dct++ = (sc->dc += DEC_REC(in, hu, r, t));	hu = sc->huac.dhuff;	i = 63;	while (i > 0) {	    t = DEC_REC(in, hu, r, t);	    if (t == 0 && r == 0) {		dct += i;		break;	    }	    dct += r;	    *dct++ = t;	    i -= r + 1;	}	*maxp++ = 64 - i;	if (n == sc->next)	    sc++;    }    LEBI_PUT(in);}static voiddec_makehuff(struct dec_hufftbl *hu, int *hufflen, unsigned char *huffvals){    int code, k, i, j, d, x, c, v;    for (i = 0; i < (1 << DECBITS); i++)	hu->llvals[i] = 0;/* * llvals layout: * * value v already known, run r, backup u bits: *  vvvvvvvvvvvvvvvv 0000 rrrr 1 uuuuuuu * value unknown, size b bits, run r, backup u bits: *  000000000000bbbb 0000 rrrr 0 uuuuuuu * value and size unknown: *  0000000000000000 0000 0000 0 0000000 */    code = 0;    k = 0;    for (i = 0; i < 16; i++, code <<= 1) {	/* sizes */	hu->valptr[i] = k;	for (j = 0; j < hufflen[i]; j++) {	    hu->vals[k] = *huffvals++;	    if (i < DECBITS) {		c = code << (DECBITS - 1 - i);		v = hu->vals[k] & 0x0f;	/* size */		for (d = 1 << (DECBITS - 1 - i); --d >= 0;) {		    if (v + i < DECBITS) {	/* both fit in table */			x = d >> (DECBITS - 1 - v - i);			if (v && x < (1 << (v - 1)))			    x += (-1 << v) + 1;			x = x << 16 | (hu->vals[k] & 0xf0)			    << 4 | (DECBITS - (i + 1 + v)) | 128;		    } else			x = v << 16 | (hu->vals[k] & 0xf0)			    << 4 | (DECBITS - (i + 1));		    hu->llvals[c | d] = x;		}	    }	    code++;	    k++;	}	hu->maxcode[i] = code;    }    hu->maxcode[16] = 0x20000;	/* always terminate decode */}/****************************************************************//**************             idct                  ***************//****************************************************************/#define S22 ((long)IFIX(2 * 0.382683432))#define C22 ((long)IFIX(2 * 0.923879532))#define IC4 ((long)IFIX(1 / 0.707106781))static unsigned char zig2[64] = {    0, 2, 3, 9, 10, 20, 21, 35,    14, 16, 25, 31, 39, 46, 50, 57,    5, 7, 12, 18, 23, 33, 37, 48,    27, 29, 41, 44, 52, 55, 59, 62,    15, 26, 30, 40, 45, 51, 56, 58,    1, 4, 8, 11, 19, 22, 34, 36,    28, 42, 43, 53, 54, 60, 61, 63,    6, 13, 17, 24, 32, 38, 47, 49};inline static void idct(int *in, int *out, int *quant, long off, int max){    long t0, t1, t2, t3, t4, t5, t6, t7;	// t ;    long tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;    long tmp[64], *tmpp;    int i, j, te;    unsigned char *zig2p;    t0 = off;    if (max == 1) {	t0 += in[0] * quant[0];	for (i = 0; i < 64; i++)	    out[i] = ITOINT(t0);	return;    }    zig2p = zig2;    tmpp = tmp;    for (i = 0; i < 8; i++) {	j = *zig2p++;	t0 += in[j] * (long) quant[j];	j = *zig2p++;	t5 = in[j] * (long) quant[j];	j = *zig2p++;	t2 = in[j] * (long) quant[j];	j = *zig2p++;	t7 = in[j] * (long) quant[j];	j = *zig2p++;	t1 = in[j] * (long) quant[j];	j = *zig2p++;	t4 = in[j] * (long) quant[j];	j = *zig2p++;	t3 = in[j] * (long) quant[j];	j = *zig2p++;	t6 = in[j] * (long) quant[j];	if ((t1 | t2 | t3 | t4 | t5 | t6 | t7) == 0) {	    tmpp[0 * 8] = t0;	    tmpp[1 * 8] = t0;	    tmpp[2 * 8] = t0;	    tmpp[3 * 8] = t0;	    tmpp[4 * 8] = t0;	    tmpp[5 * 8] = t0;	    tmpp[6 * 8] = t0;	    tmpp[7 * 8] = t0;	    tmpp++;	    t0 = 0;	    continue;	}	//IDCT;	tmp0 = t0 + t1;	t1 = t0 - t1;	tmp2 = t2 - t3;	t3 = t2 + t3;	tmp2 = IMULT(tmp2, IC4) - t3;	tmp3 = tmp0 + t3;	t3 = tmp0 - t3;	tmp1 = t1 + tmp2;	tmp2 = t1 - tmp2;	tmp4 = t4 - t7;	t7 = t4 + t7;	tmp5 = t5 + t6;	t6 = t5 - t6;	tmp6 = tmp5 - t7;	t7 = tmp5 + t7;	tmp5 = IMULT(tmp6, IC4);	tmp6 = IMULT((tmp4 + t6), S22);	tmp4 = IMULT(tmp4, (C22 - S22)) + tmp6;	t6 = IMULT(t6, (C22 + S22)) - tmp6;	t6 = t6 - t7;	t5 = tmp5 - t6;	t4 = tmp4 - t5;	tmpp[0 * 8] = tmp3 + t7;	//t0;	tmpp[1 * 8] = tmp1 + t6;	//t1;	tmpp[2 * 8] = tmp2 + t5;	//t2;	tmpp[3 * 8] = t3 + t4;	//t3;	tmpp[4 * 8] = t3 - t4;	//t4;	tmpp[5 * 8] = tmp2 - t5;	//t5;	tmpp[6 * 8] = tmp1 - t6;	//t6;	tmpp[7 * 8] = tmp3 - t7;	//t7;	tmpp++;	t0 = 0;    }    for (i = 0, j = 0; i < 8; i++) {	t0 = tmp[j + 0];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -