📄 ov518_decomp.c
字号:
out[4]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base - val1 + val2 - val3 - tmp1 + tmp2) >> 17; out[27]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base + val1 - val2 - val3 - C16 - C20) >> 17; out[28]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t;// Second half C2_18 = coeff[2] - coeff[18]; C6_22 = coeff[6] - coeff[22]; C1_17 = coeff[1] - coeff[17]; C3_19 = coeff[3] - coeff[19]; C5_21 = coeff[5] - coeff[21]; C7_23 = coeff[7] - coeff[23];// 8,15,16,23 base = 0x1000000; base += coeff[0] + coeff[4] - coeff[16] - coeff[20]; base +=TIMES_30270(C2_18); base +=TIMES_12538(C6_22); val1 = TIMES_17391(coeff[9]); val1 += TIMES_14743(coeff[11]); val1 += TIMES_9851(coeff[13]); val1 += TIMES_3459(coeff[15]); val1 -= TIMES_41986(coeff[25]); val1 -= TIMES_35594(coeff[27]); val1 -= TIMES_23783(coeff[29]); val1 -= TIMES_8351(coeff[31]); val2 = TIMES_32134(C1_17); val2 += TIMES_27242(C3_19); val2 += TIMES_18202(C5_21); val2 += TIMES_6392(C7_23); val3 = TIMES_16382(coeff[10] - coeff[30]); val3 += TIMES_6785(coeff[14]); val3 -= TIMES_39550(coeff[26]); val3 -=TIMES_30270(coeff[24] + coeff[28]); val3 +=TIMES_12538(coeff[8] + coeff[12]); t=(base + val1 + val2 + val3) >> 17; out[8]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base - val1 - val2 + val3 - C4 + C16 + C20) >> 17; out[15]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base - val1 + val2 - val3) >> 17; out[16]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base + val1 - val2 - val3 - C4 + C20) >> 17; out[23]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t;//9,14,17,22 base = 0x1000000; base += coeff[0] - coeff[4] - coeff[16] + coeff[20]; base += TIMES_12538(C2_18); base -= TIMES_30270(C6_22); val1 = TIMES_14743(coeff[9]); val1 -= TIMES_3459(coeff[11]); val1 -= TIMES_17391(coeff[13]); val1 -= TIMES_9851(coeff[15]); val1 -= TIMES_35594(coeff[25]); val1 += TIMES_8351(coeff[27]); val1 += TIMES_41986(coeff[29]); val1 += TIMES_23783(coeff[31]); val2 = TIMES_27242(C1_17); val2 -= TIMES_6392(C3_19); val2 -= TIMES_32134(C5_21); val2 -= TIMES_18202(C7_23); val3 = TIMES_6785(coeff[10]); val3 -= TIMES_16382(coeff[14] + coeff[26]); val3 += TIMES_39550(coeff[30]); val3 += TIMES_12538(coeff[8] - coeff[12]); val3 -= TIMES_30270(coeff[24] - coeff[28]); t=(base + val1 + val2 + val3 + C4 + C16 - C20) >> 17; out[9]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base - val1 - val2 + val3 + C16) >> 17; out[14]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base - val1 + val2 - val3 + C4) >> 17; out[17]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base + val1 - val2 - val3) >> 17; out[22]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t;//10,13,18,21 base = 0x1000000; base += coeff[0] - coeff[4] - coeff[16] + coeff[20]; base -= TIMES_12538(C2_18); base += TIMES_30270(C6_22); val1 = TIMES_9851(coeff[9]); val1 -= TIMES_17391(coeff[11]); val1 += TIMES_3459(coeff[13]); val1 += TIMES_14743(coeff[15]); val1 -= TIMES_23783(coeff[25]); val1 += TIMES_41986(coeff[27]); val1 -= TIMES_8351(coeff[29]); val1 -= TIMES_35594(coeff[31]); val2 = TIMES_18202(C1_17); val2 -= TIMES_32134(C3_19); val2 += TIMES_6392(C5_21); val2 += TIMES_27242(C7_23); val3 = -TIMES_6785(coeff[10]); val3 += TIMES_16382(coeff[14]+coeff[26]); val3 -= TIMES_39550(coeff[30]); val3 += TIMES_12538(coeff[8]-coeff[12]); val3 -= TIMES_30270(coeff[24]-coeff[28]); t=(base + val1 + val2 + val3) >> 17; out[10]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base - val1 - val2 + val3 + C4 + C16 - C20) >> 17; out[13]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base - val1 + val2 - val3) >> 17; out[18]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base + val1 - val2 - val3 + C4) >> 17; out[21]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t;// 11,12,19,20 base = 0x1000000; base += coeff[0]+coeff[4]-coeff[16]-coeff[20]; base -= TIMES_30270(C2_18); base -= TIMES_12538(C6_22); val1 = TIMES_3459(coeff[9]); val1 -= TIMES_9851(coeff[11]); val1 += TIMES_14743(coeff[13]); val1 -= TIMES_8351(coeff[25]); val1 += TIMES_23783(coeff[27]); val1 -= TIMES_35594(coeff[29]); val2 = TIMES_6392(C1_17); val2 -= TIMES_18202(C3_19); val2 += TIMES_27242(C5_21); val3 = -TIMES_16382(coeff[10] - coeff[30]); val3 -= TIMES_6785(coeff[14]); val3 += TIMES_39550(coeff[26]); val3 -= TIMES_30270(coeff[24]+coeff[28]); val3 += TIMES_12538(coeff[8]+coeff[12]); tmp1 = TIMES_32134(C7_23); tmp2 = -TIMES_17391(coeff[15]) + TIMES_41986(coeff[31]); t=(base + val1 + val2 + val3 - tmp1 + tmp2 + C16 + C20) >> 17; out[11]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base - val1 - val2 + val3 + C16 + C20) >> 17; out[12]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base - val1 + val2 - val3 - tmp1 - tmp2 - C4 + C20) >> 17; out[19]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t; t=(base + val1 - val2 - val3) >> 17; out[20]= t&0xFFFFFF00? t<0?0:255 : (unsigned char)t;}#undef TIMES_16382#undef TIMES_23168#undef TIMES_30270#undef TIMES_41986#undef TIMES_35594#undef TIMES_23783#undef TIMES_8351#undef TIMES_17391#undef TIMES_14743#undef TIMES_9851#undef TIMES_3459#undef TIMES_32134#undef TIMES_27242#undef TIMES_18202#undef TIMES_6392#undef TIMES_39550#undef TIMES_6785#undef TIMES_12538/****************************************************************************** * Main Decoder Functions ******************************************************************************//* This function handles the decompression of a single 8x4 block. It is * independent of the palette (YUV422, YUV420, YUV400, GBR422...). cinfo->bytes * determines the positin in the input buffer. */static int decomp_8x4(unsigned char *pOut, unsigned char *pIn, int *lastDC, int uvFlag, struct comp_info *cinfo){ int i, x, y, dc; int coeffs[32]; int deZigZag[32]; int *dest; int *src; unsigned char *qt = cinfo->qt; if (! uvFlag) { huffmanDecoderY(coeffs, (int*) pIn, cinfo); /* iDPCM and dequantize first coefficient */ dc = (*lastDC) + coeffs[0]; coeffs[0] = dc * (qt[0] + 1); *lastDC = dc; /* ...and the second coefficient */ coeffs[1] = ((qt[1] + 1) * coeffs[1]) >> 1; /* Dequantize, starting at 3rd element */ for (i = 2; i < 32; i++) coeffs[i] = (qt[i] + 1) * coeffs[i]; } else { huffmanDecoderUV(coeffs, (int*) pIn, cinfo); /* iDPCM */ dc = (*lastDC) + coeffs[0]; coeffs[0] = dc; *lastDC = dc; /* Dequantize */ for (i = 0; i < 32; i++) coeffs[i] = (qt[32 + i] + 1) * coeffs[i]; } /* Dezigzag */ for (i = 0; i < 32; i++) deZigZag[i] = coeffs[ZigZag518[i]]; /* Transpose the dezigzagged coefficient matrix */ src = deZigZag; dest = coeffs; for (y = 0; y <= 3; ++y) { for (x = 0; x <= 7; ++x) { dest[x] = src[x * 4]; } src += 1; dest += 8; } /* Do the inverse DCT transform */ DCT_8x4(coeffs, pOut); return 0; /* Always returns 0 */}static inline void copyBlock(unsigned char *src, unsigned char *dest, int destInc){ int i; unsigned int *pSrc, *pDest; for (i = 0; i <= 3; i++) { pSrc = (unsigned int *) src; pDest = (unsigned int *) dest; pDest[0] = pSrc[0]; pDest[1] = pSrc[1]; src += 8; dest += destInc; }}static inline intdo_decomp_400(unsigned char *pIn, unsigned char *pOut, unsigned char *pTmp, const int w, const int h, const int numpix, struct comp_info *cinfo){ int iOutY, x, y; int lastYDC = 0; /* Start Y loop */ y = 0; do { iOutY = w * y; x = 0; do { decomp_8x4(pTmp, pIn, &lastYDC, 0, cinfo); copyBlock(pTmp, pOut + iOutY, w); iOutY += 8; x += 8; } while (x < w); y += 4; } while (y < h); /* Did we decode too much? */ if (cinfo->bytes > cinfo->rawLen + 897) return 1; /* Did we decode enough? */ if (cinfo->bytes >= cinfo->rawLen - 897) return 0; else return 1;}static inline intdo_decomp_420(unsigned char *pIn, unsigned char *pOut, unsigned char *pTmp, const int w, const int h, const int numpix, struct comp_info *cinfo){ unsigned char *pOutU = pOut + numpix; unsigned char *pOutV = pOutU + numpix / 4; int iOutY, iOutU, iOutV, x, y; int lastYDC = 0; int lastUDC = 0; int lastVDC = 0; /* Start Y loop */ y = 0; do { iOutY = w * y; iOutV = iOutU = iOutY / 4; x = 0; do { decomp_8x4(pTmp, pIn, &lastYDC, 0, cinfo); copyBlock(pTmp, pOut + iOutY, w); iOutY += 8; x += 8; } while (x < w); iOutY = w * (y + 4); x = 0; do { decomp_8x4(pTmp, pIn, &lastUDC, 1, cinfo); copyBlock(pTmp, pOutU + iOutU, w/2); iOutU += 8; decomp_8x4(pTmp, pIn, &lastVDC, 1, cinfo); copyBlock(pTmp, pOutV + iOutV, w/2); iOutV += 8; decomp_8x4(pTmp, pIn, &lastYDC, 0, cinfo); copyBlock(pTmp, pOut + iOutY, w); iOutY += 8; decomp_8x4(pTmp, pIn, &lastYDC, 0, cinfo); copyBlock(pTmp, pOut + iOutY, w); iOutY += 8; x += 16; } while (x < w); y += 8; } while (y < h); /* Did we decode too much? */ if (cinfo->bytes > cinfo->rawLen + 897) return 1; /* Did we decode enough? */ if (cinfo->bytes >= cinfo->rawLen - 897) return 0; else return 1;}/* Get quantization tables from static arrays * Returns: <0 if error, or >=0 otherwise */static intget_qt_static(struct comp_info *cinfo){ unsigned char qtY[] = OV518_YQUANTABLE; unsigned char qtUV[] = OV518_UVQUANTABLE; unsigned char qt[64]; memcpy(qt, qtY, 32); memcpy(qt + 32, qtUV, 32); cinfo->qt = qt; return 0;}/* Get quantization tables from input * Returns: <0 if error, or >=0 otherwise */static intget_qt_dynamic(unsigned char *pIn, struct comp_info *cinfo){ int rawLen = cinfo->rawLen; /* Make sure input is actually big enough to hold trailer */ if (rawLen < 72) { PDEBUG(1, "Not enough input to decompress"); return -EINVAL; } cinfo->qt = pIn + rawLen - 64; print_qt(cinfo->qt); return 0;}/* Input format is raw iso data (with intact SOF header, packet numbers * stripped, and zero-padding removed). * Output format is planar YUV400 * Returns uncompressed data length if success, or zero if error */static int ov518_decomp_400(unsigned char *pIn, unsigned char *pOut, unsigned char *pTmp, int w, int h, int inSize){ struct comp_info cinfo; int numpix = w * h; PDEBUG(4, "%dx%d pIn=%p pOut=%p pTmp=%p inSize=%d", w, h, pIn, pOut, pTmp, inSize); cinfo.bytes = 0; cinfo.bits = 0; cinfo.rawLen = inSize; if (staticquant) { if (get_qt_static(&cinfo) < 0) return 0; } else { if (get_qt_dynamic(pIn, &cinfo) < 0) return 0; } /* Decompress, skipping the 8-byte SOF header */ if (do_decomp_400(pIn + 8, pOut, pTmp, w, h, numpix, &cinfo))// return 0; ; /* Don't return error yet */ return (numpix);}/* Input format is raw iso data (with intact SOF header, packet numbers * stripped, and zero-padding removed). * Output format is planar YUV420 * Returns uncompressed data length if success, or zero if error */static int ov518_decomp_420(unsigned char *pIn, unsigned char *pOut, unsigned char *pTmp, int w, int h, int inSize){ struct comp_info cinfo; int numpix = w * h; PDEBUG(4, "%dx%d pIn=%p pOut=%p pTmp=%p inSize=%d", w, h, pIn, pOut, pTmp, inSize); cinfo.bytes = 0; cinfo.bits = 0; cinfo.rawLen = inSize; if (staticquant) { if (get_qt_static(&cinfo) < 0) return 0; } else { if (get_qt_dynamic(pIn, &cinfo) < 0) return 0; } /* Decompress, skipping the 8-byte SOF header */ if (do_decomp_420(pIn + 8, pOut, pTmp, w, h, numpix, &cinfo))// return 0; ; /* Don't return error yet */ if (!ov518_color) { int i; unsigned char *pU = pOut + numpix; unsigned char *pV = pU + numpix/4; for (i = 0; i < numpix/4; i++) { *pU++ = 127; *pV++ = 127; } } return (numpix * 3 / 2);}struct ov51x_decomp_ops ov518_decomp_ops = { .decomp_400 = ov518_decomp_400, .decomp_420 = ov518_decomp_420, };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -