📄 gspcadecoder.c
字号:
} *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};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]; t1 = tmp[j + 1]; t2 = tmp[j + 2]; t3 = tmp[j + 3]; t4 = tmp[j + 4]; t5 = tmp[j + 5]; t6 = tmp[j + 6]; t7 = tmp[j + 7]; if ((t1 | t2 | t3 | t4 | t5 | t6 | t7) == 0) { te = ITOINT(t0); out[j + 0] = te; out[j + 1] = te; out[j + 2] = te; out[j + 3] = te; out[j + 4] = te; out[j + 5] = te; out[j + 6] = te; out[j + 7] = te; j += 8; 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; out[j + 0] = ITOINT(tmp3 + t7); out[j + 1] = ITOINT(tmp1 + t6); out[j + 2] = ITOINT(tmp2 + t5); out[j + 3] = ITOINT(t3 + t4); out[j + 4] = ITOINT(t3 - t4); out[j + 5] = ITOINT(tmp2 - t5); out[j + 6] = ITOINT(tmp1 - t6); out[j + 7] = ITOINT(tmp3 - t7); j += 8; }}static unsigned char zig[64] = { 0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12, 17, 25, 30, 41, 43, 9, 11, 18, 24, 31, 40, 44, 53, 10, 19, 23, 32, 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50, 56, 59, 61, 35, 36, 48, 49, 57, 58, 62, 63};static int aaidct[8] = { IFIX(0.3535533906), IFIX(0.4903926402), IFIX(0.4619397663), IFIX(0.4157348062), IFIX(0.3535533906), IFIX(0.2777851165), IFIX(0.1913417162), IFIX(0.0975451610)};inline static void idctqtab(unsigned char *qin, int *qout){ int i, j; for (i = 0; i < 8; i++) for (j = 0; j < 8; j++) qout[zig[i * 8 + j]] = qin[zig[i * 8 + j]] * IMULT(aaidct[i], aaidct[j]);}inline static void scaleidctqtab(int *q, int sc){ int i; for (i = 0; i < 64; i++) q[i] = IMULT(q[i], sc);}/* Reduce to the necessary minimum. FIXME */void init_qTable(struct usb_spca50x *spca50x, unsigned int qIndex){ int i, j; /* set up a quantization table */ for (i = 0; i < 2; i++) { for (j = 0; j < 64; j++) { spca50x->maindecode.quant[i][j] = GsmartQTable[qIndex * 2 + i][j]; } } idctqtab(spca50x->maindecode. quant[spca50x->maindecode.dscans[0].tq], spca50x->maindecode.dquant[0]); idctqtab(spca50x->maindecode. quant[spca50x->maindecode.dscans[1].tq], spca50x->maindecode.dquant[1]); idctqtab(spca50x->maindecode. quant[spca50x->maindecode.dscans[2].tq], spca50x->maindecode.dquant[2]); /* rescale qtab */ //scaleidctqtab (spca50x->maindecode.dquant[0], IFIX (0.7)); //scaleidctqtab (spca50x->maindecode.dquant[1], IFIX (0.7)); //scaleidctqtab (spca50x->maindecode.dquant[2], IFIX (0.7)); }inline static voiddecode_mcus_PAC7311(struct in *in, int *dct, int n, struct scan *sc, int *maxp){ struct dec_hufftbl *hu; int i, r, t; int le, bi; char trash; 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++; } trash = GETBITS(in, 8); LEBI_PUT(in);}static int jpeg_decode422_PAC7311(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; unsigned char *red = myframe->decoder->Red; unsigned char *green = myframe->decoder->Green; unsigned char *blue = myframe->decoder->Blue; struct dec_data *decode = myframe->decoder; if ((height & 7) || (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(decode, buf, 1); /* for each component. Reset dc values. */ dec_initscans(decode); /* 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 (decode->info.dri && !--decode->info.nm) if (dec_checkmarker(decode)) return ERR_WRONG_MARKER; decode_mcus_PAC7311(&decode->in, dcts, 4, decode->dscans, max); if ((my >= cropy1) && (my < mcusy - cropy2) && (mx >= cropx1) && (mx < mcusx - cropx2)) { idct(dcts, out, decode->dquant[0], IFIX(128.5), max[0]); idct(dcts + 64, out + 64, decode->dquant[0], IFIX(128.5), max[1]); idct(dcts + 128, out + 256, decode->dquant[1], IFIX(0.5), max[2]); idct(dcts + 192, out + 320, decode->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++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -