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

📄 spcadecoder.c

📁 用于LINUX摄像头的相关程序
💻 C
📖 第 1 页 / 共 3 页
字号:
							      max[0]);							idct (dcts + 64,							      out + 64,							      dquant[0],							      IFIX (128.5),							      max[1]);							idct (dcts + 128,							      out + 128,							      dquant[0],							      IFIX (128.5),							      max[2]);							idct (dcts + 192,							      out + 192,							      dquant[0],							      IFIX (128.5),							      max[3]);							idct (dcts + 256,							      out + 256,							      dquant[1],							      IFIX (0.5),							      max[4]);							idct (dcts + 320,							      out + 320,							      dquant[2],							      IFIX (0.5),							      max[5]);							pix1 = (__u16 *)(pic + picx + picy);							pix2 = pix1 + nextnewline;							outy = out;							outy1 = 0;							outy2 = 8;							inv = out + 64 * 4;							inu = out + 64 * 5;							for (j = 0; j < 8; j++) {								for (k = 0;								     k < 8;								     k++) {									if (k ==									    4) {										outy1 += 56;										outy2 += 56;									}									/* outup 4 pixels */									/* get the UV colors need to change UV order for force rgb? */									if ( force_rgb){										u = *inv++;										v = *inu++;									} else {										v = *inv++;										u = *inu++;									}									/* MX color space why not? */									v1 = ((v << 10) + (v << 9)) >> 10;									u1 = ((u << 8) + (u << 7) + (v << 9) + (v << 4)) >> 10;									u2 = ((u << 11) + (u << 4)) >> 10;									/* top pixel Right */									y1 = outy[outy1++];									*pix1++ = ((GTable[7][CLIP((y1 + v1))] & 0xF8) >> 3 |									 	  ((GTable[8][CLIP((y1 - u1))] & 0xFC) << 3) |									  	  ((GTable[9][CLIP((y1 + u2))] & 0xF8) << 8)) ;									/* top pixel Left */									y1 = outy[outy1++];	  									*pix1++ = ((GTable[7][CLIP((y1 + v1))] & 0xF8) >> 3 | 										  ((GTable[8][CLIP((y1 - u1))] & 0xFC) << 3) | 										  ((GTable[9][CLIP((y1 + u2))] & 0xF8) << 8)) ;																		/* bottom pixel Right */									y1 = outy[outy2++];									*pix2++ = ((GTable[7][CLIP((y1 + v1))] & 0xF8) >> 3 |									          ((GTable[8][CLIP((y1 - u1))] & 0xFC) << 3) | 										  ((GTable[9][CLIP((y1 + u2))] & 0xF8) << 8)) ;									/* bottom pixel Left */									y1 = outy[outy2++];	  									*pix2++ = ((GTable[7][CLIP((y1 + v1))] & 0xF8) >> 3| 									          ((GTable[8][CLIP((y1 - u1))] & 0xFC) << 3) | 										  ((GTable[9][CLIP((y1 + u2))] & 0xF8) << 8)) ;									}								if (j == 3) {									outy = out + 128;								} else {									outy += 16;								}								outy1 = 0;								outy2 = 8;								pix1 += nextline;								pix2 += nextline;							}							picx += 16 * bpp;						} 					}					if (my >= cropy1)						picy += nextblk;				}						}			break;		case VIDEO_PALETTE_RGB32:		case VIDEO_PALETTE_RGB24:			{	bpp = (format == VIDEO_PALETTE_RGB32) ? 4 : 3;				nextline = bpp * ((softwidth << 1) - 16);				nextblk = bpp * (softwidth << 4);				nextnewline = bpp * softwidth;				for (my = 0, picy = 0; my < mcusy; my++) {					for (mx = 0, picx = 0; mx < mcusx; mx++) {						decode_mcus (&in, dcts, 6,							     dscans, max);						if ((my >= cropy1)						    && (my < mcusy - cropy2)						    && (mx >= cropx1)						    && (mx < mcusx - cropx2)) {							idct (dcts, out,							      dquant[0],							      IFIX (128.5),							      max[0]);							idct (dcts + 64,							      out + 64,							      dquant[0],							      IFIX (128.5),							      max[1]);							idct (dcts + 128,							      out + 128,							      dquant[0],							      IFIX (128.5),							      max[2]);							idct (dcts + 192,							      out + 192,							      dquant[0],							      IFIX (128.5),							      max[3]);							idct (dcts + 256,							      out + 256,							      dquant[1],							      IFIX (0.5),							      max[4]);							idct (dcts + 320,							      out + 320,							      dquant[2],							      IFIX (0.5),							      max[5]);							pic0 = pic + picx +								picy;							pic1 = pic0 + nextnewline;							outy = out;							outy1 = 0;							outy2 = 8;							inv = out + 64 * 4;							inu = out + 64 * 5;							for (j = 0; j < 8; j++) {								for (k = 0;								     k < 8;								     k++) {									if (k ==									    4) {										outy1 += 56;										outy2 += 56;									}									/* outup 4 pixels */									/* get the UV colors need to change UV order for force rgb? */									v = *inv++;									u = *inu++;									/* MX color space why not? */									v1 = ((v << 10) + (v << 9)) >> 10;									u1 = ((u << 8) + (u << 7) + (v << 9) + (v << 4)) >> 10;									u2 = ((u << 11) + (u << 4)) >> 10;									/* top pixel Right */									y1 = outy[outy1++];									pic0[r_offset] = GTable[7][CLIP ((y1 + v1))];									pic0[g_offset] = GTable[8][CLIP ((y1 - u1))];									pic0[b_offset] = GTable[9][CLIP ((y1 + u2))];									pic0 += bpp;									/* top pixel Left */									y1 = outy[outy1++];									pic0[r_offset] = GTable[7][CLIP ((y1 + v1))];									pic0[g_offset] = GTable[8][CLIP ((y1 - u1))];									pic0[b_offset] = GTable[9][CLIP ((y1 + u2))];									pic0 += bpp;									/* bottom pixel Right */									y1 = outy[outy2++];									pic1[r_offset] = GTable[7][CLIP ((y1 + v1))];									pic1[g_offset] = GTable[8][CLIP ((y1 - u1))];									pic1[b_offset] = GTable[9][CLIP ((y1 + u2))];									pic1 += bpp;									/* bottom pixel Left */									y1 = outy[outy2++];									pic1[r_offset] = GTable[7][CLIP ((y1 + v1))];									pic1[g_offset] = GTable[8][CLIP ((y1 - u1))];									pic1[b_offset] = GTable[9][CLIP ((y1 + u2))];									pic1 += bpp;								}								if (j == 3) {									outy = out + 128;								} else {									outy += 16;								}								outy1 = 0;								outy2 = 8;								pic0 += nextline;								pic1 += nextline;							}							picx += 16 * bpp;						} 					}					if (my >= cropy1)						picy += nextblk;				}			}			break;		case VIDEO_PALETTE_YUV420P:			{				nextline = (softwidth << 1) - 16;				nextuv = (softwidth >> 1) - 8;				nextblk = softwidth << 4;				nextnewline = softwidth << 2;				for (my = 0, picy = 0, pocy = 0; my < mcusy;				     my++) {					for (mx = 0, picx = 0, pocx = 0;					     mx < mcusx; mx++) {						decode_mcus (&in, dcts, 6,							     dscans, max);						if ((my >= cropy1)						    && (my < mcusy - cropy2)						    && (mx >= cropx1)						    && (mx < mcusx - cropx2)) {							idct (dcts, out,							      dquant[0],							      IFIX (128.5),							      max[0]);							idct (dcts + 64,							      out + 64,							      dquant[0],							      IFIX (128.5),							      max[1]);							idct (dcts + 128,							      out + 128,							      dquant[0],							      IFIX (128.5),							      max[2]);							idct (dcts + 192,							      out + 192,							      dquant[0],							      IFIX (128.5),							      max[3]);							idct (dcts + 256,							      out + 256,							      dquant[1],							      IFIX (0.5),							      max[4]);							idct (dcts + 320,							      out + 320,							      dquant[2],							      IFIX (0.5),							      max[5]);							pic0 = pic + picx +								picy;							pic1 = pic0 + softwidth;							outv = V + (pocx +								    pocy);							outu = U + (pocx +								    pocy);							outy = out;							outy1 = 0;							outy2 = 8;							inv = out + 64 * 4;							inu = out + 64 * 5;							for (j = 0; j < 8; j++) {								for (k = 0;								     k < 8;								     k++) {									if (k ==									    4) {										outy1 += 56;										outy2 += 56;									}									/* outup 4 pixels */									*pic0++ = outy[outy1++];									*pic0++ = outy[outy1++];									*pic1++ = outy[outy2++];									*pic1++ = outy[outy2++];									*outv++ = 128 + *inv++;									*outu++ = 128 + *inu++;								}								if (j == 3) {									outy = out + 128;								} else {									outy += 16;								}								outy1 = 0;								outy2 = 8;								pic0 += nextline;								pic1 += nextline;								outv += nextuv;								outu += nextuv;							}							picx += 16;							pocx += 8;						} 					}					if (my >= cropy1) {						picy += nextblk;						pocy += nextnewline;					}				}			}			break;		default:			break;	}			// end case	return 0;}static int bayer_decode(struct spca50x_frame *myframe, int force_rgb ){	int cropx1,cropx2,cropy1,cropy2;	int r_offset, g_offset, b_offset;	int my , mx; /* scan input surface */	unsigned char *pic, *pic1; /* output surface */	__u16 *pix1,*pix2; /* same for 16 bits output */	unsigned char *buf; /* input surface */	unsigned char *U, *V; /* chroma output pointer */	unsigned char inr, ing1, ing2, inb, ing; /* srgb input */	int inl,inl1; /* offset line input */	int nextinline, nextoutline;	unsigned char r,b,y1,y2,y3,y4;	int u,v;	int width; 	int height;	int softwidth;	int softheight;	int method;	int format;	int bpp;	int framesize, frameUsize;	/* init usefull data */	pic = myframe->data;	buf = myframe->tmpbuffer;	width = myframe->hdrwidth;	height = myframe->hdrheight;	softwidth = myframe->width;	softheight = myframe->height;	method = myframe->method;	format = myframe->format;	cropx1 = myframe->cropx1;	cropx2 = myframe->cropx2;	cropy1 = myframe->cropy1;	cropy2 = myframe->cropy2;	framesize = softwidth * softheight;	frameUsize = framesize >> 2;	/* rgb or bgr like U or V that's the question */	if (force_rgb) {		U = pic + framesize;		V = U + frameUsize;				r_offset = 2;		g_offset = 1;		b_offset = 0;	} else {		V = pic + framesize;		U = V + frameUsize;				r_offset = 0;		g_offset = 1;		b_offset = 2;	}	/* initialize input pointer */	inl = 0;	inl1 = width ;	nextinline = width << 1;	/* Decode to the correct format. */	switch (format) {		case VIDEO_PALETTE_RGB565:			{	bpp = 2;			/* initialize */								pix1 = (__u16*) pic;				pix2 = pix1 + softwidth;								for ( my =0; my < height; my += 2){					for ( mx = 0 ; mx < width ; mx += 2 ){					/* test if we need to decode */					  if ((my >= cropy1)						    && (my < height - cropy2)						    && (mx >= cropx1)						    && (mx < width - cropx2)) {						    /* yes decode */						    ing1 = buf [inl + mx] ;						if(force_rgb){						    						    inr = buf [inl + 1 + mx] ;						    inb = buf [inl1 + mx];						    } else {						    inb = buf [inl + 1 + mx] ;						    inr = buf [inl1 + mx];						    }						    ing2 = buf [inl1 + 1 + mx];						    ing = (ing1 + ing2) >> 1;						   						    /* top pixel Right */						    									*pix1++ = ((GTable[7][inr] & 0xF8) >> 3 |								  ((GTable[8][ing1] & 0xFC) << 3) |								  ((GTable[9][inb] & 0xF8) << 8)) ;								    /* top pixel Left */						    							*pix1++ = ((GTable[7][inr] & 0xF8) >> 3 |								  ((GTable[8][ing] & 0xFC) << 3) |								  ((GTable[9][inb] & 0xF8) << 8)) ;								    /* bottom pixel Right */						   							*pix2++ = ((GTable[7][inr] & 0xF8) >> 3 |								  ((GTable[8][ing] & 0xFC) << 3) |								  ((GTable[9][inb] & 0xF8) << 8)) ;								    /* bottom pixel Left */						    							*pix2++ = ((GTable[7][inr] & 0xF8) >> 3 |								  ((GTable[8][ing2] & 0xFC) << 3) |								  ((GTable[9][inb] & 0xF8) << 8)) ;								    						    					  } // end test decode					} // end mx loop					inl += nextinline;					inl1 += nextinline ;										if (my >= cropy1){						/* are we in a decode surface move the output pointer */						pix1 += (softwidth);						pix2 += (softwidth);					}									} // end my loop						}			break;		case VIDEO_PALETTE_RGB32:		case VIDEO_PALETTE_RGB24:			{	bpp = (format == VIDEO_PALETTE_RGB32) ? 4 : 3;				/* initialize */				nextoutline  = bpp * softwidth;				pic1 = pic + nextoutline;								for ( my =0; my < height; my += 2){					for ( mx = 0 ; mx < width ; mx += 2 ){					/* test if we need to decode */					  if ((my >= cropy1)						    && (my < height - cropy2)						    && (mx >= cropx1)						    && (mx < width - cropx2)) {						    						    						    /* yes decode GBRG */						    ing1 = buf [inl + mx] ;						    inb = buf [inl+ 1 + mx] ;						    inr = buf [inl1 + mx];						    ing2 = buf [inl1 +1 + mx];						    ing = (ing1 + ing2) >> 1;						   						   /* yes decode RGGB 						    inr = buf [inl + mx] ;						    ing1 = buf [inl+ 1 + mx] ;						    ing2 = buf [inl1 + mx];						    inb = buf [inl1 +1 + mx];						    ing = (ing1 + ing2) >> 1;						   */						   /* yes decode GGBR 						    ing1 = buf [inl + mx] ;						    ing2 = buf [inl+ 1 + mx] ;						    inb = buf [inl1 + mx];						    inr = buf [inl1 +1 + mx];						    ing = (ing1 + ing2) >> 1;						   */						   /* yes decode BRGG 						    inr = buf [inl + mx] ;						    inb = buf [inl+ 1 + mx] ;						    ing1 = buf [inl1 + mx];						    ing2 = buf [inl1 +1 + mx];						    ing = (ing1 + ing2) >> 1;						   */				    						    /* top pixel Right */																		pic[r_offset] = GTable[7][inr];									pic[g_offset] = GTable[8][ing1];									pic[b_offset] = GTable[9][inb];									pic += bpp;						    /* top pixel Left */						   									pic[r_offset] = GTable[7][inr];									pic[g_offset] = GTable[8][ing];									pic[b_offset] = GTable[9][inb];									pic += bpp;						    /* bottom pixel Right */						    									pic1[r_offset] = GTable[7][inr];									pic1[g_offset] = GTable[8][ing];									pic1[b_offset] = GTable[9][inb];									pic1 += bpp;						    /* bottom pixel Left */						    									pic1[r_offset] = GTable[7][inr];									pic1[g_offset] = GTable[8][ing2];									pic1[b_offset] = GTable[9][inb];									pic1 += bpp;						    						    					  } // end test decode					} // end mx loop					inl += nextinline;					inl1 += nextinline ;										if (my >= cropy1){						/* are we in a decode surface move the output pointer */						pic += (nextoutline);						pic1 += (nextoutline);					}									} // end my loop			}			break;		case VIDEO_PALETTE_YUV420P:			{ /* Not yet implemented */				nextoutline  = softwidth;				pic1 = pic + nextoutline;				for ( my =0; my < height; my += 2){					for ( mx = 0; mx < width ; mx +=2 ){					/* test if we need to decode */					  if ((my >= cropy1)						    && (my < height - cropy2)						    && (mx >= cropx1)						    && (mx < width - cropx2)) {						    /* yes decode */						    ing1 = buf [inl + mx] ;

⌨️ 快捷键说明

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