x265的DCT

news2024/11/28 14:15:19

文章目录

  • DCT相关背景知识
      • DCT变换系数矩阵
          • 32x32变换矩阵系数
          • 其他尺寸变换矩阵系数
      • 变换计算过程
          • 流程图
  • 代码实现
      • 数据
          • 残差变换系数
          • 对应残差
      • 我的简单实现
          • 实现细节
          • 实现代码
      • x265对应代码实现
      • openHEVC代码实现

DCT相关背景知识

DCT变换系数矩阵

标准提供了32x32的系数矩阵,4x4、8x8、16x16的矩阵都可以从中提取出来

32x32变换矩阵系数

左半边
右半边

其他尺寸变换矩阵系数

其他尺寸矩阵变换系数
从上面来看,4x4的变换矩阵,系数为:
[ 64 64 64 64 83 36 − 36 − 83 64 − 64 − 64 64 36 − 83 83 − 36 ] \begin{bmatrix} 64 & 64 & 64 & 64 \\ 83 & 36 & -36 & -83 \\ 64 & -64 & -64 & 64 \\ 36 & -83 & 83 & -36 \end{bmatrix} 64836436643664836436648364836436
其他尺寸的变换系数矩阵也可以从图中对应找到

变换计算过程

流程图

流程图
需要注意的是:

  1. 左乘表示列变换,右乘表示行变换
  2. 反变换的过程中,进行了两次Scale

伸缩矩阵,具体定义为:
伸缩矩阵

代码实现

数据

残差变换系数

残差变换系数

对应残差

残差

我的简单实现

实现细节
  1. 实现公式
    R = D T ⋅ C × S I T 1 ⋅ D × S I T 2 R = D^T \cdot C \times S_{IT1} \cdot D \times S_{IT2} R=DTC×SIT1D×SIT2
  2. 暂时忽略伸缩
    R = D T ⋅ C ⋅ D R = D^T \cdot C \cdot D R=DTCD
  3. 稍加处理
    R = ( C T ⋅ D ) T ⋅ D R = { (C^T \cdot D) }^T \cdot D R=(CTD)TD
  4. 重点来了,到这里之后。
    就可以把公式可以分成两部分
    T m p = C T ⋅ D R = T m p T ⋅ D Tmp =C^T \cdot D \\ R = { Tmp }^T \cdot D Tmp=CTDR=TmpTD
  5. 加入伸缩
    T m p = C T ⋅ D × S I T 1 R = T m p T ⋅ D × S I T 2 Tmp =C^T \cdot D \times S_{IT1} \\ R = { Tmp }^T \cdot D \times S_{IT2} Tmp=CTD×SIT1R=TmpTD×SIT2
  6. 也就是说,我们可以这样定义函数。
    y = f u n ( a , b , s ) = a T ⋅ b × s y = fun(a,b,s) = a^T \cdot b \times s y=fun(a,b,s)=aTb×s
    函数步骤为:先转置,再列变换,然后伸缩
    也就是说,我们只需要实现这个函数,然后调用两次即可
实现代码
// 变换系数
static const signed char transform[32][32] = {
    { 64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
      64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64 },
    { 90,  90,  88,  85,  82,  78,  73,  67,  61,  54,  46,  38,  31,  22,  13,   4,
      -4, -13, -22, -31, -38, -46, -54, -61, -67, -73, -78, -82, -85, -88, -90, -90 },
    { 90,  87,  80,  70,  57,  43,  25,   9,  -9, -25, -43, -57, -70, -80, -87, -90,
     -90, -87, -80, -70, -57, -43, -25,  -9,   9,  25,  43,  57,  70,  80,  87,  90 },
    { 90,  82,  67,  46,  22,  -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13,
      13,  38,  61,  78,  88,  90,  85,  73,  54,  31,   4, -22, -46, -67, -82, -90 },
    { 89,  75,  50,  18, -18, -50, -75, -89, -89, -75, -50, -18,  18,  50,  75,  89,
      89,  75,  50,  18, -18, -50, -75, -89, -89, -75, -50, -18,  18,  50,  75,  89 },
    { 88,  67,  31, -13, -54, -82, -90, -78, -46, -4,   38,  73,  90,  85,  61,  22,
     -22, -61, -85, -90, -73, -38,   4,  46,  78,  90,  82,  54,  13, -31, -67, -88 },
    { 87,  57,   9, -43, -80, -90, -70, -25,  25,  70,  90,  80,  43,  -9, -57, -87,
     -87, -57,  -9,  43,  80,  90,  70,  25, -25, -70, -90, -80, -43,   9,  57,  87 },
    { 85,  46, -13, -67, -90, -73, -22,  38,  82,  88,  54,  -4, -61, -90, -78, -31,
      31,  78,  90,  61,   4, -54, -88, -82, -38,  22,  73,  90,  67,  13, -46, -85 },
    { 83,  36, -36, -83, -83, -36,  36,  83,  83,  36, -36, -83, -83, -36,  36,  83,
      83,  36, -36, -83, -83, -36,  36,  83,  83,  36, -36, -83, -83, -36,  36,  83 },
    { 82,  22, -54, -90, -61,  13,  78,  85,  31, -46, -90, -67,   4,  73,  88,  38,
     -38, -88, -73,  -4,  67,  90,  46, -31, -85, -78, -13,  61,  90,  54, -22, -82 },
    { 80,   9, -70, -87, -25,  57,  90,  43, -43, -90, -57,  25,  87,  70,  -9, -80,
     -80,  -9,  70,  87,  25, -57, -90, -43,  43,  90,  57, -25, -87, -70,   9,  80 },
    { 78,  -4, -82, -73,  13,  85,  67, -22, -88, -61,  31,  90,  54, -38, -90, -46,
      46,  90,  38, -54, -90, -31,  61,  88,  22, -67, -85, -13,  73,  82,   4, -78 },
    { 75, -18, -89, -50,  50,  89,  18, -75, -75,  18,  89,  50, -50, -89, -18,  75,
      75, -18, -89, -50,  50,  89,  18, -75, -75,  18,  89,  50, -50, -89, -18,  75 },
    { 73, -31, -90, -22,  78,  67, -38, -90, -13,  82,  61, -46, -88,  -4,  85,  54,
     -54, -85,   4,  88,  46, -61, -82,  13,  90,  38, -67, -78,  22,  90,  31, -73 },
    { 70, -43, -87,   9,  90,  25, -80, -57,  57,  80, -25, -90,  -9,  87,  43, -70,
     -70,  43,  87,  -9, -90, -25,  80,  57, -57, -80,  25,  90,   9, -87, -43,  70 },
    { 67, -54, -78,  38,  85, -22, -90,   4,  90,  13, -88, -31,  82,  46, -73, -61,
      61,  73, -46, -82,  31,  88, -13, -90,  -4,  90,  22, -85, -38,  78,  54, -67 },
    { 64, -64, -64,  64,  64, -64, -64,  64,  64, -64, -64,  64,  64, -64, -64,  64,
      64, -64, -64,  64,  64, -64, -64,  64,  64, -64, -64,  64,  64, -64, -64,  64 },
    { 61, -73, -46,  82,  31, -88, -13,  90,  -4, -90,  22,  85, -38, -78,  54,  67,
     -67, -54,  78,  38, -85, -22,  90,   4, -90,  13,  88, -31, -82,  46,  73, -61 },
    { 57, -80, -25,  90,  -9, -87,  43,  70, -70, -43,  87,   9, -90,  25,  80, -57,
     -57,  80,  25, -90,   9,  87, -43, -70,  70,  43, -87,  -9,  90, -25, -80,  57 },
    { 54, -85,  -4,  88, -46, -61,  82,  13, -90,  38,  67, -78, -22,  90, -31, -73,
      73,  31, -90,  22,  78, -67, -38,  90, -13, -82,  61,  46, -88,   4,  85, -54 },
    { 50, -89,  18,  75, -75, -18,  89, -50, -50,  89, -18, -75,  75,  18, -89,  50,
      50, -89,  18,  75, -75, -18,  89, -50, -50,  89, -18, -75,  75,  18, -89,  50 },
    { 46, -90,  38,  54, -90,  31,  61, -88,  22,  67, -85,  13,  73, -82,   4,  78,
     -78,  -4,  82, -73, -13,  85, -67, -22,  88, -61, -31,  90, -54, -38,  90, -46 },
    { 43, -90,  57,  25, -87,  70,   9, -80,  80,  -9, -70,  87, -25, -57,  90, -43,
     -43,  90, -57, -25,  87, -70,  -9,  80, -80,   9,  70, -87,  25,  57, -90,  43 },
    { 38, -88,  73,  -4, -67,  90, -46, -31,  85, -78,  13,  61, -90,  54,  22, -82,
      82, -22, -54,  90, -61, -13,  78, -85,  31,  46, -90,  67,   4, -73,  88, -38 },
    { 36, -83,  83, -36, -36,  83, -83,  36,  36, -83,  83, -36, -36,  83, -83,  36,
      36, -83,  83, -36, -36,  83, -83,  36,  36, -83,  83, -36, -36,  83, -83,  36 },
    { 31, -78,  90, -61,   4,  54, -88,  82, -38, -22,  73, -90,  67, -13, -46,  85,
     -85,  46,  13, -67,  90, -73,  22,  38, -82,  88, -54,  -4,  61, -90,  78, -31 },
    { 25, -70,  90, -80,  43,   9, -57,  87, -87,  57,  -9, -43,  80, -90,  70, -25,
     -25,  70, -90,  80, -43,  -9,  57, -87,  87, -57,   9,  43, -80,  90, -70,  25 },
    { 22, -61,  85, -90,  73, -38,  -4,  46, -78,  90, -82,  54, -13, -31,  67, -88,
      88, -67,  31,  13, -54,  82, -90,  78, -46,   4,  38, -73,  90, -85,  61, -22 },
    { 18, -50,  75, -89,  89, -75,  50, -18, -18,  50, -75,  89, -89,  75, -50,  18,
      18, -50,  75, -89,  89, -75,  50, -18, -18,  50, -75,  89, -89,  75, -50,  18 },
    { 13, -38,  61, -78,  88, -90,  85, -73,  54, -31,   4,  22, -46,  67, -82,  90,
     -90,  82, -67,  46, -22,  -4,  31, -54,  73, -85,  90, -88,  78, -61,  38, -13 },
    {  9, -25,  43, -57,  70, -80,  87, -90,  90, -87,  80, -70,  57, -43,  25, -9,
      -9,  25, -43,  57, -70,  80, -87,  90, -90,  87, -80,  70, -57,  43, -25,   9 },
    {  4, -13,  22, -31,  38, -46,  54, -61,  67, -73,  78, -82,  85, -88,  90, -90,
      90, -90,  88, -85,  82, -78,  73, -67,  61, -54,  46, -38,  31, -22,  13,  -4 },
};

// 残差变换系数
short coeffs1[16 * 16] = {
-8730, -180,  -90,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,  -90,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
   90,    0,  -90,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
   90,    0,  -90,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
   90,    0,  -90,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
   90,    0,  -90,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
   90,    0,  -90,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
   90,    0,  -90,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0
};

// 
static void func(short* src, short* dst, int s) {
    short add = (1 << (s - 1));
    for (int r1 = 0; r1 < 16; ++r1) {
        for (int c2 = 0; c2 < 16; ++c2) {
            int tmp = 0;
            for (int t = 0; t < 16; ++t)
                tmp += src[r1 + t * 16] * transform[2 * t][c2];
            dst[r1 * 16 + c2] = ((tmp + add) >> s);
        }
    }
}

static void MyIDCT(short* src, short* dst) {
    func(src, dst, 7);
    func(dst, src, 12);
}

x265对应代码实现

const short g_t16[16][16] =
{
    { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
    { 90, 87, 80, 70, 57, 43, 25,  9, -9, -25, -43, -57, -70, -80, -87, -90 },
    { 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89 },
    { 87, 57,  9, -43, -80, -90, -70, -25, 25, 70, 90, 80, 43, -9, -57, -87 },
    { 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83 },
    { 80,  9, -70, -87, -25, 57, 90, 43, -43, -90, -57, 25, 87, 70, -9, -80 },
    { 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75 },
    { 70, -43, -87,  9, 90, 25, -80, -57, 57, 80, -25, -90, -9, 87, 43, -70 },
    { 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64 },
    { 57, -80, -25, 90, -9, -87, 43, 70, -70, -43, 87,  9, -90, 25, 80, -57 },
    { 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50 },
    { 43, -90, 57, 25, -87, 70,  9, -80, 80, -9, -70, 87, -25, -57, 90, -43 },
    { 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36 },
    { 25, -70, 90, -80, 43,  9, -57, 87, -87, 57, -9, -43, 80, -90, 70, -25 },
    { 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18 },
    {  9, -25, 43, -57, 70, -80, 87, -90, 90, -87, 80, -70, 57, -43, 25, -9 }
};

static void partialButterflyInverse16(const short* src, short* dst, int shift, int line)
{
    int j, k;
    int E[8], O[8];
    int EE[4], EO[4];
    int EEE[2], EEO[2];
    int add = 1 << (shift - 1);

    for (j = 0; j < line; j++)
    {
        /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
        for (k = 0; k < 8; k++)
        {
            O[k] = g_t16[1][k] * src[line] + g_t16[3][k] * src[3 * line] + g_t16[5][k] * src[5 * line] + g_t16[7][k] * src[7 * line] +
                g_t16[9][k] * src[9 * line] + g_t16[11][k] * src[11 * line] + g_t16[13][k] * src[13 * line] + g_t16[15][k] * src[15 * line];
        }

        for (k = 0; k < 4; k++)
        {
            EO[k] = g_t16[2][k] * src[2 * line] + g_t16[6][k] * src[6 * line] + g_t16[10][k] * src[10 * line] + g_t16[14][k] * src[14 * line];
        }

        EEO[0] = g_t16[4][0] * src[4 * line] + g_t16[12][0] * src[12 * line];
        EEE[0] = g_t16[0][0] * src[0] + g_t16[8][0] * src[8 * line];
        EEO[1] = g_t16[4][1] * src[4 * line] + g_t16[12][1] * src[12 * line];
        EEE[1] = g_t16[0][1] * src[0] + g_t16[8][1] * src[8 * line];

        /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */
        for (k = 0; k < 2; k++)
        {
            EE[k] = EEE[k] + EEO[k];
            EE[k + 2] = EEE[1 - k] - EEO[1 - k];
        }

        for (k = 0; k < 4; k++)
        {
            E[k] = EE[k] + EO[k];
            E[k + 4] = EE[3 - k] - EO[3 - k];
        }

        for (k = 0; k < 8; k++)
        {
            dst[k] = (short)x265_clip3(-32768, 32767, (E[k] + O[k] + add) >> shift);
            dst[k + 8] = (short)x265_clip3(-32768, 32767, (E[7 - k] - O[7 - k] + add) >> shift);
        }

        src++;
        dst += 16;
    }
}

static void idct16_c(const short* src, short* dst, __int64 dstStride)
{
    const int shift_1st = 7;
    const int shift_2nd = 12 - (X265_DEPTH - 8);

    ALIGN_VAR_32(short, coef[16 * 16]);
    ALIGN_VAR_32(short, block[16 * 16]);

    partialButterflyInverse16(src, coef, shift_1st, 16);
    partialButterflyInverse16(coef, block, shift_2nd, 16);

    for (int i = 0; i < 16; i++)
    {
        memcpy(&dst[i * dstStride], &block[i * 16], 16 * sizeof(short));
    }
}

openHEVC代码实现

static const signed char transform[32][32] = {
    { 64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
      64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64 },
    { 90,  90,  88,  85,  82,  78,  73,  67,  61,  54,  46,  38,  31,  22,  13,   4,
      -4, -13, -22, -31, -38, -46, -54, -61, -67, -73, -78, -82, -85, -88, -90, -90 },
    { 90,  87,  80,  70,  57,  43,  25,   9,  -9, -25, -43, -57, -70, -80, -87, -90,
     -90, -87, -80, -70, -57, -43, -25,  -9,   9,  25,  43,  57,  70,  80,  87,  90 },
    { 90,  82,  67,  46,  22,  -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13,
      13,  38,  61,  78,  88,  90,  85,  73,  54,  31,   4, -22, -46, -67, -82, -90 },
    { 89,  75,  50,  18, -18, -50, -75, -89, -89, -75, -50, -18,  18,  50,  75,  89,
      89,  75,  50,  18, -18, -50, -75, -89, -89, -75, -50, -18,  18,  50,  75,  89 },
    { 88,  67,  31, -13, -54, -82, -90, -78, -46, -4,   38,  73,  90,  85,  61,  22,
     -22, -61, -85, -90, -73, -38,   4,  46,  78,  90,  82,  54,  13, -31, -67, -88 },
    { 87,  57,   9, -43, -80, -90, -70, -25,  25,  70,  90,  80,  43,  -9, -57, -87,
     -87, -57,  -9,  43,  80,  90,  70,  25, -25, -70, -90, -80, -43,   9,  57,  87 },
    { 85,  46, -13, -67, -90, -73, -22,  38,  82,  88,  54,  -4, -61, -90, -78, -31,
      31,  78,  90,  61,   4, -54, -88, -82, -38,  22,  73,  90,  67,  13, -46, -85 },
    { 83,  36, -36, -83, -83, -36,  36,  83,  83,  36, -36, -83, -83, -36,  36,  83,
      83,  36, -36, -83, -83, -36,  36,  83,  83,  36, -36, -83, -83, -36,  36,  83 },
    { 82,  22, -54, -90, -61,  13,  78,  85,  31, -46, -90, -67,   4,  73,  88,  38,
     -38, -88, -73,  -4,  67,  90,  46, -31, -85, -78, -13,  61,  90,  54, -22, -82 },
    { 80,   9, -70, -87, -25,  57,  90,  43, -43, -90, -57,  25,  87,  70,  -9, -80,
     -80,  -9,  70,  87,  25, -57, -90, -43,  43,  90,  57, -25, -87, -70,   9,  80 },
    { 78,  -4, -82, -73,  13,  85,  67, -22, -88, -61,  31,  90,  54, -38, -90, -46,
      46,  90,  38, -54, -90, -31,  61,  88,  22, -67, -85, -13,  73,  82,   4, -78 },
    { 75, -18, -89, -50,  50,  89,  18, -75, -75,  18,  89,  50, -50, -89, -18,  75,
      75, -18, -89, -50,  50,  89,  18, -75, -75,  18,  89,  50, -50, -89, -18,  75 },
    { 73, -31, -90, -22,  78,  67, -38, -90, -13,  82,  61, -46, -88,  -4,  85,  54,
     -54, -85,   4,  88,  46, -61, -82,  13,  90,  38, -67, -78,  22,  90,  31, -73 },
    { 70, -43, -87,   9,  90,  25, -80, -57,  57,  80, -25, -90,  -9,  87,  43, -70,
     -70,  43,  87,  -9, -90, -25,  80,  57, -57, -80,  25,  90,   9, -87, -43,  70 },
    { 67, -54, -78,  38,  85, -22, -90,   4,  90,  13, -88, -31,  82,  46, -73, -61,
      61,  73, -46, -82,  31,  88, -13, -90,  -4,  90,  22, -85, -38,  78,  54, -67 },
    { 64, -64, -64,  64,  64, -64, -64,  64,  64, -64, -64,  64,  64, -64, -64,  64,
      64, -64, -64,  64,  64, -64, -64,  64,  64, -64, -64,  64,  64, -64, -64,  64 },
    { 61, -73, -46,  82,  31, -88, -13,  90,  -4, -90,  22,  85, -38, -78,  54,  67,
     -67, -54,  78,  38, -85, -22,  90,   4, -90,  13,  88, -31, -82,  46,  73, -61 },
    { 57, -80, -25,  90,  -9, -87,  43,  70, -70, -43,  87,   9, -90,  25,  80, -57,
     -57,  80,  25, -90,   9,  87, -43, -70,  70,  43, -87,  -9,  90, -25, -80,  57 },
    { 54, -85,  -4,  88, -46, -61,  82,  13, -90,  38,  67, -78, -22,  90, -31, -73,
      73,  31, -90,  22,  78, -67, -38,  90, -13, -82,  61,  46, -88,   4,  85, -54 },
    { 50, -89,  18,  75, -75, -18,  89, -50, -50,  89, -18, -75,  75,  18, -89,  50,
      50, -89,  18,  75, -75, -18,  89, -50, -50,  89, -18, -75,  75,  18, -89,  50 },
    { 46, -90,  38,  54, -90,  31,  61, -88,  22,  67, -85,  13,  73, -82,   4,  78,
     -78,  -4,  82, -73, -13,  85, -67, -22,  88, -61, -31,  90, -54, -38,  90, -46 },
    { 43, -90,  57,  25, -87,  70,   9, -80,  80,  -9, -70,  87, -25, -57,  90, -43,
     -43,  90, -57, -25,  87, -70,  -9,  80, -80,   9,  70, -87,  25,  57, -90,  43 },
    { 38, -88,  73,  -4, -67,  90, -46, -31,  85, -78,  13,  61, -90,  54,  22, -82,
      82, -22, -54,  90, -61, -13,  78, -85,  31,  46, -90,  67,   4, -73,  88, -38 },
    { 36, -83,  83, -36, -36,  83, -83,  36,  36, -83,  83, -36, -36,  83, -83,  36,
      36, -83,  83, -36, -36,  83, -83,  36,  36, -83,  83, -36, -36,  83, -83,  36 },
    { 31, -78,  90, -61,   4,  54, -88,  82, -38, -22,  73, -90,  67, -13, -46,  85,
     -85,  46,  13, -67,  90, -73,  22,  38, -82,  88, -54,  -4,  61, -90,  78, -31 },
    { 25, -70,  90, -80,  43,   9, -57,  87, -87,  57,  -9, -43,  80, -90,  70, -25,
     -25,  70, -90,  80, -43,  -9,  57, -87,  87, -57,   9,  43, -80,  90, -70,  25 },
    { 22, -61,  85, -90,  73, -38,  -4,  46, -78,  90, -82,  54, -13, -31,  67, -88,
      88, -67,  31,  13, -54,  82, -90,  78, -46,   4,  38, -73,  90, -85,  61, -22 },
    { 18, -50,  75, -89,  89, -75,  50, -18, -18,  50, -75,  89, -89,  75, -50,  18,
      18, -50,  75, -89,  89, -75,  50, -18, -18,  50, -75,  89, -89,  75, -50,  18 },
    { 13, -38,  61, -78,  88, -90,  85, -73,  54, -31,   4,  22, -46,  67, -82,  90,
     -90,  82, -67,  46, -22,  -4,  31, -54,  73, -85,  90, -88,  78, -61,  38, -13 },
    {  9, -25,  43, -57,  70, -80,  87, -90,  90, -87,  80, -70,  57, -43,  25, -9,
      -9,  25, -43,  57, -70,  80, -87,  90, -90,  87, -80,  70, -57,  43, -25,   9 },
    {  4, -13,  22, -31,  38, -46,  54, -61,  67, -73,  78, -82,  85, -88,  90, -90,
      90, -90,  88, -85,  82, -78,  73, -67,  61, -54,  46, -38,  31, -22,  13,  -4 },
};
static __forceinline short av_clip_int16(int a)
{
    if ((a + 0x8000U) & ~0xFFFF) return (a >> 31) ^ 0x7FFF;
    else                      return a;
}

#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
#define SET(dst, x)   (dst) = (x)
#define SCALE(dst, x) (dst) = av_clip_int16(((x) + add) >> shift)

#define TR_4(dst, src, dstep, sstep, assign, end)                 \
    do {                                                          \
        const int e0 = 64 * src[0 * sstep] + 64 * src[2 * sstep]; \
        const int e1 = 64 * src[0 * sstep] - 64 * src[2 * sstep]; \
        const int o0 = 83 * src[1 * sstep] + 36 * src[3 * sstep]; \
        const int o1 = 36 * src[1 * sstep] - 83 * src[3 * sstep]; \
                                                                  \
        assign(dst[0 * dstep], e0 + o0);                          \
        assign(dst[1 * dstep], e1 + o1);                          \
        assign(dst[2 * dstep], e1 - o1);                          \
        assign(dst[3 * dstep], e0 - o0);                          \
    } while (0)

#define TR_8(dst, src, dstep, sstep, assign, end)                 \
    do {                                                          \
        int i, j;                                                 \
        int e_8[4];                                               \
        int o_8[4] = { 0 };                                       \
        for (i = 0; i < 4; i++)                                   \
            for (j = 1; j < end; j += 2)                          \
                o_8[i] += transform[4 * j][i] * src[j * sstep];   \
        TR_4(e_8, src, 1, 2 * sstep, SET, 4);                     \
                                                                  \
        for (i = 0; i < 4; i++) {                                 \
            assign(dst[i * dstep], e_8[i] + o_8[i]);              \
            assign(dst[(7 - i) * dstep], e_8[i] - o_8[i]);        \
        }                                                         \
    } while (0)

#define TR_16(dst, src, dstep, sstep, assign, end)                \
    do {                                                          \
        int i, j;                                                 \
        int e_16[8];                                              \
        int o_16[8] = { 0 };                                      \
        for (i = 0; i < 8; i++)                                   \
            for (j = 1; j < end; j += 2)                          \
                o_16[i] += transform[2 * j][i] * src[j * sstep];  \
        TR_8(e_16, src, 1, 2 * sstep, SET, 8);                    \
                                                                  \
        for (i = 0; i < 8; i++) {                                 \
            assign(dst[i * dstep], e_16[i] + o_16[i]);            \
            assign(dst[(15 - i) * dstep], e_16[i] - o_16[i]);     \
        }                                                         \
    } while (0)

static void idct_16x16_8(short* coeffs, int col_limit) {
    int i;
    int      shift = 7;
    int      add = 1 << (shift - 1);
    short* src = coeffs;
    int limit = FFMIN(col_limit, 16);
    int limit2 = FFMIN(col_limit + 4, 16);

    for (i = 0; i < 16; i++) {
        TR_16(src, src, 16, 16, SCALE, limit2);                  
        if (limit2 < 16 && i%4 == 0 && !!i)                        
            limit2 -= 4;                                         
        src++;                                                    
    }      
    shift = 20 - BIT_DEPTH;                                       
    add = 1 << (shift - 1);                                     
    for (i = 0; i < 16; i++) {
        TR_16(coeffs, coeffs, 1, 1, SCALE, limit);             
        coeffs += 16;                                              
    }                                                             
};

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/620301.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Leetcode | 39 组合总和

Leetcode | 39 组合总和 题目 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target &#xff0c;找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 &#xff0c;并以列表形式返回。你可以按 任意顺序 返回这些组合。 candidates 中的 同一个 数…

理解 Vue 中的 MVVM 思想

1. 什么是 Vue Vue 是一套用于构建用户界面的渐进式 JavaScript 框架, 与其他大型框架不同的是, Vue 被设计为可以自底向上逐层应用, Vue 的核心库只关心视图层, 方便与第三方库或既有项目整合. 2. JavaScript 框架了解 jQuery : 大家熟悉的 JavaScript 框架, 优点是简化了 D…

VulnHub项目:MONEY HEIST: 1.0.1

靶机地址&#xff1a;Money Heist: 1.0.1 ~ VulnHub 渗透过程&#xff1a; 确定靶机ip&#xff0c;攻击机kali的ip 对靶机进行端口检测 存在22、53、80、3000、3001端口&#xff0c;访问80端口 发现了登录注册按钮&#xff0c;尝试进行注册 注册成功后进行登录&#xff0c…

VulnHub项目:Gaara

项目地址&#xff1a;Gaara: 1 ~ VulnHub 我爱罗&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;火影前200集无敌存在&#xff01;&#xff01;&#xff01; 渗透过程&#xff1a; 收集三件套&#xff01;搞一手~&#xff0c;发现80&#xff0c;访问web&…

第四节 ogre 2.3实现一个简单的模型纹理贴图

本节简单介绍下如何使用Ogre 2.3加载模型&#xff0c;并给模型贴上纹理材质。 一. 安装ogre 2.3 主要有两种安装方法&#xff1a; 简单安装方法&#xff0c;使用scripts for Ogre 2.3 脚本,按照官网给出的步骤安装即可。需要注意的是脚本解压后的 *.bat 文件需要修改下 CMAK…

【Java|golang】2611. 老鼠和奶酪

有两只老鼠和 n 块不同类型的奶酪&#xff0c;每块奶酪都只能被其中一只老鼠吃掉。 下标为 i 处的奶酪被吃掉的得分为&#xff1a; 如果第一只老鼠吃掉&#xff0c;则得分为 reward1[i] 。 如果第二只老鼠吃掉&#xff0c;则得分为 reward2[i] 。 给你一个正整数数组 reward1…

SpringCloud-Gateway过滤器

路由过滤器 GatewayFilter GatewayFilter 是网关中提供的一种过滤器&#xff0c;可以对进入网关的请求和微服务返回的响应做处理。 路由过滤器的作用是什么&#xff1f; 对路由的请求或想象做加工处理&#xff0c;比如添加请求头配置子路由下的过滤器只对当前路由的请求生效…

monkey测试关机/重启问题分析(二)

systemui关机dialog相关 1、systemui下拉关机按钮 通过Android 布局分析工具发现 按钮布局 base/packages/SystemUI/res-keyguard/layout/footer_actions.xml 按钮初始化和点击事件 frameworks/base/packages/SystemUI/src/com/android/systemui/qs/FooterActionsControlle…

斐波那契算法的理解

1.斐波那契数列 &#xff1a; 数组&#xff1a;int[] F{1, 1, 2, 3, 5, 8, 13, 21, 34, 55 }; 特点&#xff1a; 从第三个数开始&#xff0c;后边每一个数都是前两个数的和 。F[k]F[k-1]F[k-2]; 如图所示&#xff1a; ①low、mid、high都是F数组的索引&#xff0c;F[k]-1表示…

基础实验篇 | 课程总体介绍(一)

本讲主要介绍多旋翼的特点及选用多旋翼作为实验平台的原因、对于无人系统教育的一些新需求、RflySim平台对于飞控的底层控制算法的开发优势、本期平台课程的设置、以及如何开发自驾仪系统。 相较于固定翼和直升机&#xff0c;多旋翼具有机械结构简单、 易维护的优点。以四旋翼…

操作Arrays.asList的list报UnsupportedOperationException的坑

Arrays.asList() 将数组转换成List集合 /*** Returns a fixed-size list backed by the specified array. (Changes to* the returned list "write through" to the array.) This method acts* as bridge between array-based and collection-based APIs, in* com…

通过Python封装商品ID获取阿里巴巴商品详情数据,阿里巴巴商品详情数据API接口,阿里巴巴API接口

目的&#xff1a;通过Python封装商品ID获取阿里巴巴商品详情数据&#xff0c;本文将给出Python代码的一些思路和示例。 首先&#xff0c;你需要找到获取阿里巴巴商品详情数据的API接口。阿里巴巴开放平台提供了一些API接口&#xff0c;例如阿里巴巴开放平台商品API&#xff0c…

软件开发项目成本控制的7个重点

1、精细计划预算和管控机制 制定详细的项目计划和预算&#xff0c;包括资源需求、人力资源、时间表和财务预测等&#xff0c;以确保项目不会超出预算。实时跟踪项目的实际开支和进度&#xff0c;并对计划进行调整&#xff0c;以便更好地管理成本。 软件开发项目成本控制的7个重…

MongoDB Study Notes

文章目录 1 MongoDB快速入门1.1 什么是MongDB1.2 部署安装——基于docker1.3 基本概念1.4 基本操作1.4.1 查看所有数据库1.4.2 切换数据库1.4.3 创建数据库1.4.4 删除数据库1.4.5 查看数据库中表1.4.6 新增数据1.4.7 查询数据1.4.8 更新数据1.4.8.1 更新不存在字段1.4.8.2 更新…

Nginx 504 gateway timeout

方案 调整这几个参数来调大nginx的超时时间。 proxy_connect_timeout proxy_send_timeout proxy_read_timeoutnginx 三个代理超时时间配置 proxy_connect_timeout 60s; Defines a timeout for establishing a connection with a proxied server. It should be noted that thi…

【期末划重点】计算机英语(2)(更新中)

阿金的计算机英语&#xff0c;线下考试版~ 时隔半年&#xff0c;又开始赌徒模式啦 这次尝试用大数据文本分析&#xff0c;精准备考 欢迎补充 2023计英期末考赌徒版 Part 1 词汇题&#xff08;20题&#xff0c;40分&#xff09;1、词库说明2、本题答题技巧3、背词方法4、完整词库…

【Python实战】Python采集情感音频

成年人的世界真不容易啊 总是悲伤大于欢喜 爱情因为懵懂而快乐 却走进了复杂和困惑的婚姻 前言 我最近喜欢去听情感类的节目&#xff0c;比如说&#xff0c;婚姻类&#xff0c;我可能老了吧。我就想着怎么把音乐下载下来了&#xff0c;保存到手机上&#xff0c;方便我们业余时…

jdk配置语句以及idea配置问题idea科学使用

一、第一步上链接 官网地址&#xff0c;不过每次都在变版本不过都一样没事&#xff1a; https://www.oracle.com/java/technologies/downloads/ idea2021官网 https://www.jetbrains.com/zh-cn/idea/download/other.html 你可以下载右边付费的版本&#xff0c;如果想下载左边…

IPO观察丨绿源持续推进IPO,这次不止“一部车能骑10年”

近期&#xff0c;国内两轮电动车行业又有新动态。业内老牌企业绿源集团更新招股书&#xff0c;继续推进上市进程&#xff0c;中信建投国际担任保荐人。 其实去年11月&#xff0c;绿源已向港交所递交招股书&#xff0c;只不过受若干原因影响&#xff0c;在今年5月失效。当然&am…

synchronized简单理解

一、简述 1.1 synchronized介绍 synchronized是一种互斥锁&#xff0c;也成为同步锁&#xff0c;它的作用是保证在同一时刻&#xff0c;被修饰的代码块或方法只会有一个线程执行&#xff0c;以到达保证并发安全效果。在JDK1.6以前&#xff0c;很多人称之为重量级锁&#xff0…