📄 spcadecoder.c
字号:
&& (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 + 256, dquant[1], IFIX (0.5), max[2]); idct (dcts + 192, out + 320, dquant[2], IFIX (0.5), max[3]); 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 < 4; j++) { for (k = 0; k < 8; k++) { if (k == 4) { outy1 += 56; outy2 += 56; } /* outup 4 pixels Colors are treated as 411 */ /* 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)) ; } 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 << 3); nextnewline = bpp * softwidth; 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) && (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 + 256, dquant[1], IFIX (0.5), max[2]); idct (dcts + 192, out + 320, dquant[2], IFIX (0.5), max[3]); 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 < 4; j++) { for (k = 0; k < 8; k++) { if (k == 4) { outy1 += 56; outy2 += 56; } /* outup 4 pixels Colors are treated as 411 */ 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; } 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 << 3; nextnewline = softwidth << 1;//2 for (my = 0, picy = 0, pocy = 0; my < mcusy; my++) { for (mx = 0, picx = 0, pocx = 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) && (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 + 256, dquant[1], IFIX (0.5), max[2]); idct (dcts + 192, out + 320, dquant[2], IFIX (0.5), max[3]); 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 < 4; j++) { for (k = 0; k < 8; k++) { if (k == 4) { outy1 += 56; outy2 += 56; } /* outup 4 pixels */ *pic0++ = CLIP(outy[outy1]);outy1++; *pic0++ = CLIP(outy[outy1]);outy1++; *pic1++ = CLIP(outy[outy2]);outy2++; *pic1++ = CLIP(outy[outy2]);outy2++; /* maybe one day yuv422P */ *outv++ = CLIP(128 + *inv);inv++; *outu++ = CLIP(128 + *inu);inu++; } 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 int bayer_decode(struct spca50x_frame *myframe, int force_rgb ){ int r_offset, g_offset, b_offset; int my , mx; /* scan input surface */ unsigned char *pic1; /* output surface */ __u16 *pix1,*pix2; /* same for 16 bits output */ 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 bpp; 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; int framesize, frameUsize; inr=ing1=ing2=ing=inb=r=b=0; //compiler maybe happy !! framesize = softwidth * softheight; frameUsize = framesize >> 2; /* rgb or bgr like U or V that's the question */ if (force_rgb) { V = pic + framesize; U = V + frameUsize; r_offset = 0; g_offset = 1; b_offset = 2; } else { U = pic + framesize; V = U + frameUsize; r_offset = 2; g_offset = 1; b_offset = 0; } /* 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){ inb = buf [inl + 1 + mx] ; inr = buf [inl1 + mx]; } else { inr = buf [inl + 1 + mx] ; inb = buf [inl1 + mx]; } ing2 = buf [inl1 + 1 + mx]; ing = (ing1 + ing2) >> 1; */ /* yes decode GBRG */ ing1 = buf [inl + mx] ; if(force_rgb){ inb = buf [inl + 1 + mx] ; inr = buf [inl1 + mx]; } else { inr = buf [inl + 1 + mx] ; inb = 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 } myframe->scanlength = (long)(softwidth*softheight*bpp); 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 GBGR ing1 = buf [inl + mx] ; inb = buf [inl+ 1 + mx] ; ing2 = buf [inl1 + mx]; inr = buf [inl1 +1 + mx]; ing = (in
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -