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

📄 qc-mjpeg.c

📁 在Linux下用于webeye的摄像头的驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* fourth stage */	block[0] = (x7 + x1) >> 8;	block[1] = (x3 + x2) >> 8;	block[2] = (x0 + x4) >> 8;	block[3] = (x8 + x6) >> 8;	block[4] = (x8 - x6) >> 8;	block[5] = (x0 - x4) >> 8;	block[6] = (x3 - x2) >> 8;	block[7] = (x7 - x1) >> 8;}/* }}} *//* {{{ [fold] qc_mjpeg_idct_col(s16 *block) *//* column (vertical) IDCT * * 7 pi 1 * dst[8*k] = sum c[l] * src[8*l] * cos ( -- * ( k + - ) * l ) * l=0 8 2 * * where: c[0] = 1/1024 * c[1..7] = (1/1024)*sqrt (2) */static void inline qc_mjpeg_idct_col(s16 *block){	int x0, x1, x2, x3, x4, x5, x6, x7, x8;	/* shortcut */	x1 = block [8*4] << 8;	x2 = block [8*6];	x3 = block [8*2];	x4 = block [8*1];	x5 = block [8*7];	x6 = block [8*5];	x7 = block [8*3];#if 0	if (! (x1 | x2 | x3 | x4 | x5 | x6 | x7 )) {		block[8*0] = block[8*1] = block[8*2] = block[8*3] = block[8*4] =			block[8*5] = block[8*6] = block[8*7] = (block[8*0] + 32) >> 6;		return;	}#endif	x0 = (block[8*0] << 8) + 8192;	/* first stage */	x8 = W7 * (x4 + x5) + 4;	x4 = (x8 + (W1 - W7) * x4) >> 3;	x5 = (x8 - (W1 + W7) * x5) >> 3;	x8 = W3 * (x6 + x7) + 4;	x6 = (x8 - (W3 - W5) * x6) >> 3;	x7 = (x8 - (W3 + W5) * x7) >> 3;	/* second stage */	x8 = x0 + x1;	x0 -= x1;	x1 = W6 * (x3 + x2) + 4;	x2 = (x1 - (W2 + W6) * x2) >> 3;	x3 = (x1 + (W2 - W6) * x3) >> 3;	x1 = x4 + x6;	x4 -= x6;	x6 = x5 + x7;	x5 -= x7;	/* third stage */	x7 = x8 + x3;	x8 -= x3;	x3 = x0 + x2;	x0 -= x2;	x2 = (181 * (x4 + x5) + 128) >> 8;	x4 = (181 * (x4 - x5) + 128) >> 8;	/* fourth stage */	block[8*0] = (x7 + x1) >> 14;	block[8*1] = (x3 + x2) >> 14;	block[8*2] = (x0 + x4) >> 14;	block[8*3] = (x8 + x6) >> 14;	block[8*4] = (x8 - x6) >> 14;	block[8*5] = (x0 - x4) >> 14;	block[8*6] = (x3 - x2) >> 14;	block[8*7] = (x7 - x1) >> 14;}/* }}} *//* {{{ [fold] qc_mjpeg_idct(s16 *block, u8 *dest, int stride) *//* Inverse discrete cosine transform block, store result to dest */static void qc_mjpeg_idct(s16 *block, u8 *dest, int stride){	int i;	if (qcdebug&QC_DEBUGLOGIC) PDEBUG("qc_mjpeg_idct(block=%p,dest=%p,stride=%i)",block,dest,stride);	for (i=0; i<8; i++) qc_mjpeg_idct_row(block + 8*i);	for (i=0; i<8; i++) qc_mjpeg_idct_col(block + i);	i = 8;	do {		/* The original code used lookup-tables instead of explicit		 * comparisons (as CLIP is doing here). However, sometimes		 * the values pointed outside the LUT which caused problems		 * in the kernel driver. Thus, the LUTs are removed here. */		dest[0] = CLIP(block[0],0,255);		dest[1] = CLIP(block[1],0,255);		dest[2] = CLIP(block[2],0,255);		dest[3] = CLIP(block[3],0,255);		dest[4] = CLIP(block[4],0,255);		dest[5] = CLIP(block[5],0,255);		dest[6] = CLIP(block[6],0,255);		dest[7] = CLIP(block[7],0,255);		dest += stride;		block += 8;	} while (--i);}/* }}} *//* }}} *//* {{{ [fold] **** MJPEG decoding: bitstream processing (structures and macros) * *//* the idea is taken from zlib, but the bits are ordered the other way, so * I modified the code. * Variables: * p points to next unread byte in stream. * k number of bits read but not processed. * b contains the read but not processed bits in the k most significant bits. */struct bitstream {	u32 b;	u8 *p;	u8 *end;	int k;};#define GETWORD(p) ((p)[0] << 8 | (p)[1])#define NEEDBITS(b,k,p) \  do { \    if ((k) > 0) { \      (b) |= GETWORD(p) << (k); \      (p) += 2; \      (k) -= 16; \    } \  } while(0)#define DUMPBITS(b,k,j) do { (k) += (j); (b) <<= (j); } while (0)#define BITVALUE(b,j) ((b)>>(32-(j)))/* }}} *//* {{{ [fold] **** qc_mjpeg_lvc:     MJPEG decoding: variable length code decoding **************** *//* {{{ [fold] u8 shiftTables[18][64] */static const u8 shiftTables[18][64] = {	{2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,	 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },	{2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,	 1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 },	{2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,	 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 },	{2,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,	 2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 },	{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,	 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 },	{2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,	 3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 },	{2,3,3,3,3,3,3,3,3,3,3,3,3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4,4,4,4,4,4 },	{2,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,	 4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5 },	{2,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,	 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5 },	{2,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,	 5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6 },	{2,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,	 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 },};/* }}} *//* {{{ [fold] u8 shiftTblIndex[] */static const u8 shiftTblIndex[] = {	8, 17, 8, 16, 7, 16, 7, 15, 	6, 15, 6, 14, 5, 14, 5, 13,	4, 13, 4, 12, 3, 12, 3, 11,	2, 11, 2, 10, 1,  9, 0,  9};/* }}} *//* {{{ [fold] s16 scaleTable[64] */static const s16 scaleTable[64] = {	 8192, 16704, 16704, 17733, 17032, 17733, 18204, 18081,	18081, 18204, 18724, 18561, 19195, 18561, 18724, 19265,	19091, 19704, 19704, 19091, 19265, 21406, 19642, 20267,	20228, 20267, 19642, 21406, 22725, 21826, 20852, 20805,	20805, 20852, 21826, 22725, 23170, 23170, 21406, 21399,	21406, 23170, 23170, 24597, 23785, 22017, 22017, 23785,	24597, 25250, 24464, 22653, 24464, 25250, 25971, 25171,	25171, 25971, 26722, 27969, 26722, 29691, 29691, 31520};/* }}} *//* {{{ [fold] u8 scan_norm[64] */static const u8 scan_norm[64] = {	/* Octals */	000, 001, 010, 020, 011, 002, 003, 012, 	021, 030, 040, 031, 022, 013, 004, 005, 	014, 023, 032, 041, 050, 060, 051, 042,	033, 024, 015, 006, 007, 016, 025, 034, 	043, 052, 061, 070, 071, 062, 053, 044,	035, 026, 017, 027, 036, 045, 054, 063, 	072, 073, 064, 055, 046, 037, 047, 056, 	065, 074, 075, 066, 057, 067, 076, 077};/* }}} *//* {{{ [fold] hufftable[960] */struct hufftable_entry {	s16 value;	u8  bits;	u8  skip;};static const struct hufftable_entry hufftable[960] = {	/* first level entries */	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{     1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{    -1,  3,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{     2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{    -2,  4,   1 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{ 32767,  4, 255 },	{     1,  5,   2 },	{     1,  5,   2 },	{     1,  5,   2 },	{     1,  5,   2 },	{     1,  5,   2 },	{     1,  5,   2 },	{     1,  5,   2 },	{     1,  5,   2 },	{    -1,  5,   2 },	{    -1,  5,   2 },	{    -1,  5,   2 },	{    -1,  5,   2 },	{    -1,  5,   2 },	{    -1,  5,   2 },	{    -1,  5,   2 },	{    -1,  5,   2 },	{     3,  5,   1 },	{     3,  5,   1 },	{     3,  5,   1 },	{     3,  5,   1 },	{     3,  5,   1 },	{     3,  5,   1 },	{     3,  5,   1 },	{     3,  5,   1 },	{    -3,  5,   1 },	{    -3,  5,   1 },	{    -3,  5,   1 },	{    -3,  5,   1 },	{    -3,  5,   1 },	{    -3,  5,   1 },	{    -3,  5,   1 },	{    -3,  5,   1 },	{     4,  5,   1 },	{     4,  5,   1 },	{     4,  5,   1 },	{     4,  5,   1 },	{     4,  5,   1 },	{     4,  5,   1 },	{     4,  5,   1 },	{     4,  5,   1 },	{    -4,  5,   1 },	{    -4,  5,   1 },	{    -4,  5,   1 },	{    -4,  5,   1 },	{    -4,  5,   1 },	{    -4,  5,   1 },	{    -4,  5,   1 },	{    -4,  5,   1 },	{     1,  6,   3 },	{     1,  6,   3 },	{     1,  6,   3 },	{     1,  6,   3 },	{    -1,  6,   3 },	{    -1,  6,   3 },	{    -1,  6,   3 },	{    -1,  6,   3 },	{     2,  6,   2 },	{     2,  6,   2 },	{     2,  6,   2 },	{     2,  6,   2 },	{    -2,  6,   2 },	{    -2,  6,   2 },	{    -2,  6,   2 },	{    -2,  6,   2 },	{     5,  6,   1 },	{     5,  6,   1 },	{     5,  6,   1 },	{     5,  6,   1 },	{    -5,  6,   1 },	{    -5,  6,   1 },	{    -5,  6,   1 },	{    -5,  6,   1 },	{     6,  6,   1 },	{     6,  6,   1 },	{     6,  6,   1 },	{     6,  6,   1 },	{    -6,  6,   1 },	{    -6,  6,   1 },	{    -6,  6,   1 },	{    -6,  6,   1 },	{     1,  7,   4 },	{     1,  7,   4 },	{    -1,  7,   4 },	{    -1,  7,   4 },	{     1,  7,   5 },	{     1,  7,   5 },	{    -1,  7,   5 },	{    -1,  7,   5 },	{     7,  7,   1 },	{     7,  7,   1 },	{    -7,  7,   1 },	{    -7,  7,   1 },	{     8,  7,   1 },	{     8,  7,   1 },	{    -8,  7,   1 },	{    -8,  7,   1 },	{     1,  8,   6 },	{    -1,  8,   6 },	{     1,  8,   7 },	{    -1,  8,   7 },	{     2,  8,   3 },	{    -2,  8,   3 },	{     3,  8,   2 },	{    -3,  8,   2 },	{     4,  8,   2 },	{    -4,  8,   2 },	{     9,  8,   1 },	{    -9,  8,   1 },	{    10,  8,   1 },	{   -10,  8,   1 },	{    11,  8,   1 },	{   -11,  8,   1 },	{   256,  9,  99 },	{   258,  9,  99 },	{   260,  9,  99 },	{   262,  9,  99 },	{   264,  9,  99 },	{   266,  9,  99 },	{   268,  9,  99 },	{   270,  9,  99 },	{   272,  9,  99 },	{   274,  9,  99 },	{   276,  9,  99 },	{   278,  9,  99 },	{   280,  9,  99 },	{   282,  9,  99 },	{   284,  9,  99 },	{   286,  9,  99 },	{   288, 10,  99 },	{   292, 10,  99 },	{   296, 10,  99 },	{   300, 10,  99 },	{   304, 10,  99 },	{   308, 10,  99 },	{   312, 10,  99 },	{   316, 10,  99 },	{   320, 11,  99 },	{   328, 11,  99 },	{   336, 12,  99 },	{   352, 13,  99 },	{   384, 13,  99 },	{   416, 13,  99 },	{   448, 16,  99 },	{   704, 16,  99 },	/* indirect entries */	{     1,  9,   8 },	{    -1,  9,   8 },	{     1,  9,   9 },	{    -1,  9,   9 },	{     1,  9,  10 },	{    -1,  9,  10 },	{     1,  9,  11 },	{    -1,  9,  11 },	{     2,  9,   4 },

⌨️ 快捷键说明

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