00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdint.h>
00023 #include "libavutil/common.h"
00024 #include "mss34dsp.h"
00025
00026 static const uint8_t luma_quant[64] = {
00027 16, 11, 10, 16, 24, 40, 51, 61,
00028 12, 12, 14, 19, 26, 58, 60, 55,
00029 14, 13, 16, 24, 40, 57, 69, 56,
00030 14, 17, 22, 29, 51, 87, 80, 62,
00031 18, 22, 37, 56, 68, 109, 103, 77,
00032 24, 35, 55, 64, 81, 104, 113, 92,
00033 49, 64, 78, 87, 103, 121, 120, 101,
00034 72, 92, 95, 98, 112, 100, 103, 99
00035 };
00036
00037 static const uint8_t chroma_quant[64] = {
00038 17, 18, 24, 47, 99, 99, 99, 99,
00039 18, 21, 26, 66, 99, 99, 99, 99,
00040 24, 26, 56, 99, 99, 99, 99, 99,
00041 47, 66, 99, 99, 99, 99, 99, 99,
00042 99, 99, 99, 99, 99, 99, 99, 99,
00043 99, 99, 99, 99, 99, 99, 99, 99,
00044 99, 99, 99, 99, 99, 99, 99, 99,
00045 99, 99, 99, 99, 99, 99, 99, 99
00046 };
00047
00048 void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
00049 {
00050 int i;
00051 const uint8_t *qsrc = luma ? luma_quant : chroma_quant;
00052
00053 if (quality >= 50) {
00054 int scale = 200 - 2 * quality;
00055
00056 for (i = 0; i < 64; i++)
00057 qmat[i] = (qsrc[i] * scale + 50) / 100;
00058 } else {
00059 for (i = 0; i < 64; i++)
00060 qmat[i] = (5000 * qsrc[i] / quality + 50) / 100;
00061 }
00062 }
00063
00064 #define DCT_TEMPLATE(blk, step, SOP, shift) \
00065 const int t0 = -39409 * blk[7 * step] - 58980 * blk[1 * step]; \
00066 const int t1 = 39410 * blk[1 * step] - 58980 * blk[7 * step]; \
00067 const int t2 = -33410 * blk[5 * step] - 167963 * blk[3 * step]; \
00068 const int t3 = 33410 * blk[3 * step] - 167963 * blk[5 * step]; \
00069 const int t4 = blk[3 * step] + blk[7 * step]; \
00070 const int t5 = blk[1 * step] + blk[5 * step]; \
00071 const int t6 = 77062 * t4 + 51491 * t5; \
00072 const int t7 = 77062 * t5 - 51491 * t4; \
00073 const int t8 = 35470 * blk[2 * step] - 85623 * blk[6 * step]; \
00074 const int t9 = 35470 * blk[6 * step] + 85623 * blk[2 * step]; \
00075 const int tA = SOP(blk[0 * step] - blk[4 * step]); \
00076 const int tB = SOP(blk[0 * step] + blk[4 * step]); \
00077 \
00078 blk[0 * step] = ( t1 + t6 + t9 + tB) >> shift; \
00079 blk[1 * step] = ( t3 + t7 + t8 + tA) >> shift; \
00080 blk[2 * step] = ( t2 + t6 - t8 + tA) >> shift; \
00081 blk[3 * step] = ( t0 + t7 - t9 + tB) >> shift; \
00082 blk[4 * step] = (-(t0 + t7) - t9 + tB) >> shift; \
00083 blk[5 * step] = (-(t2 + t6) - t8 + tA) >> shift; \
00084 blk[6 * step] = (-(t3 + t7) + t8 + tA) >> shift; \
00085 blk[7 * step] = (-(t1 + t6) + t9 + tB) >> shift; \
00086
00087 #define SOP_ROW(a) ((a) << 16) + 0x2000
00088 #define SOP_COL(a) ((a + 32) << 16)
00089
00090 void ff_mss34_dct_put(uint8_t *dst, int stride, int *block)
00091 {
00092 int i, j;
00093 int *ptr;
00094
00095 ptr = block;
00096 for (i = 0; i < 8; i++) {
00097 DCT_TEMPLATE(ptr, 1, SOP_ROW, 13);
00098 ptr += 8;
00099 }
00100
00101 ptr = block;
00102 for (i = 0; i < 8; i++) {
00103 DCT_TEMPLATE(ptr, 8, SOP_COL, 22);
00104 ptr++;
00105 }
00106
00107 ptr = block;
00108 for (j = 0; j < 8; j++) {
00109 for (i = 0; i < 8; i++)
00110 dst[i] = av_clip_uint8(ptr[i] + 128);
00111 dst += stride;
00112 ptr += 8;
00113 }
00114 }