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

📄 spcadecoder.c

📁 凌阳SPCA5XX解码芯片USB驱动源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	int outy1, outy2;	int v, u, y1, v1, u1, u2;	int r_offset, g_offset, b_offset;		unsigned char *pic = myframe->data; /* output surface */	unsigned char *buf = myframe->tmpbuffer; /* input surface */	int width = myframe->hdrwidth; 	int height = myframe->hdrheight;	int softwidth = myframe->width;	int softheight = myframe->height;	//int method = myframe->method;	int format = myframe->format;	int cropx1 = myframe->cropx1;	int cropx2 = myframe->cropx2;	int cropy1 = myframe->cropy1;	int cropy2 = myframe->cropy2;		if ((height & 15) || (width & 15))		return 1;	if (width < softwidth || height < softheight)		return 1;		mcusx = width >> 4;	mcusy = height >> 4;	framesize = softwidth * softheight;	frameUsize = framesize >> 2;	jpeg_reset_input_context (buf,0);	/* for each component. Reset dc values. */	for (i = 0; i < 3; i++)		dscans[i].dc = 0;	/* 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;	}	/* Decode to the correct format. */	switch (format) {		case VIDEO_PALETTE_RGB565:			{	bpp = 2;				nextline = ((softwidth << 1) - 16);// *bpp;				nextblk = bpp * (softwidth << 4);				nextnewline = softwidth ; // *bpp;				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]);							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;				}						}			myframe->scanlength = (long)(softwidth*softheight*bpp);			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;				}			}			myframe->scanlength = (long)(softwidth*softheight*bpp);			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;					}				}			}			myframe->scanlength = (long)((softwidth*softheight*3)>>1);			break;		default:			break;	}			// end case	return 0;}static intjpeg_decode422 (struct spca50x_frame *myframe, int force_rgb){	int mcusx, mcusy, mx, my;		int *dcts = myframe->dcts;		int *out =myframe->out;	int *max=myframe->max;	int bpp;	int framesize, frameUsize;	int k, j;	int nextline, nextuv, nextblk, nextnewline;	unsigned char *pic0, *pic1, *outv, *outu;	__u16 *pix1,*pix2;	int picy, picx, pocx, pocy;	unsigned char *U, *V;	int *outy, *inv, *inu;	int outy1, outy2;	int v, u, y1, v1, u1, u2;	int r_offset, g_offset, b_offset;		unsigned char *pic = myframe->data; /* output surface */	unsigned char *buf = myframe->tmpbuffer; /* input surface */	int width = myframe->hdrwidth; 	int height = myframe->hdrheight;	int softwidth = myframe->width;	int softheight = myframe->height;	//int method = myframe->method;	int format = myframe->format;	int cropx1 = myframe->cropx1;	int cropx2 = myframe->cropx2;	int cropy1 = myframe->cropy1;	int cropy2 = myframe->cropy2;		if ((height & 15) || (width & 7))		return 1;	if (width < softwidth || height < softheight)		return 1;		mcusx = width >> 4;	mcusy = height >> 3;	framesize = softwidth * softheight;	frameUsize = framesize >> 2;	jpeg_reset_input_context (buf,1);	/* for each component. Reset dc values. */	dec_initscans();	/* 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;	}	/* Decode to the correct format. */	switch (format) {		case VIDEO_PALETTE_RGB565:			{	bpp = 2;				nextline = ((softwidth << 1) - 16);// *bpp;				nextblk = bpp * (softwidth << 3);				nextnewline = softwidth ; // *bpp;				for (my = 0, picy = 0; my < mcusy; my++) {					for (mx = 0, picx = 0; mx < mcusx; mx++) {						if (info.dri && !--info.nm)							if (dec_checkmarker())								return ERR_WRONG_MARKER;						decode_mcus (&in, dcts, 4,							     dscans, max);						if ((my >= cropy1)

⌨️ 快捷键说明

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