dct.c 5.7 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9 10 11 12
 */


#include <math.h>
13
#include "vpx_ports/config.h"
14 15 16 17 18





Yaowu Xu's avatar
Yaowu Xu committed
19
#if CONFIG_T8X8
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
void vp8_short_fdct8x8_c(short *block, short *coefs, int pitch)
{
  int j1, i, j, k;
  float b[8];
  float b1[8];
  float d[8][8];
  float f0 = (float) .7071068;
  float f1 = (float) .4903926;
  float f2 = (float) .4619398;
  float f3 = (float) .4157348;
  float f4 = (float) .3535534;
  float f5 = (float) .2777851;
  float f6 = (float) .1913417;
  float f7 = (float) .0975452;
  pitch = pitch / 2;
  for (i = 0, k = 0; i < 8; i++, k += pitch)
  {
    for (j = 0; j < 8; j++)
    {
      b[j] = (float)( block[k + j]<<1);
    }
    /* Horizontal transform */
    for (j = 0; j < 4; j++)
    {
      j1 = 7 - j;
      b1[j] = b[j] + b[j1];
      b1[j1] = b[j] - b[j1];
    }
    b[0] = b1[0] + b1[3];
    b[1] = b1[1] + b1[2];
    b[2] = b1[1] - b1[2];
    b[3] = b1[0] - b1[3];
    b[4] = b1[4];
    b[5] = (b1[6] - b1[5]) * f0;
    b[6] = (b1[6] + b1[5]) * f0;
    b[7] = b1[7];
    d[i][0] = (b[0] + b[1]) * f4;
    d[i][4] = (b[0] - b[1]) * f4;
    d[i][2] = b[2] * f6 + b[3] * f2;
    d[i][6] = b[3] * f6 - b[2] * f2;
    b1[4] = b[4] + b[5];
    b1[7] = b[7] + b[6];
    b1[5] = b[4] - b[5];
    b1[6] = b[7] - b[6];
    d[i][1] = b1[4] * f7 + b1[7] * f1;
    d[i][5] = b1[5] * f3 + b1[6] * f5;
    d[i][7] = b1[7] * f7 - b1[4] * f1;
    d[i][3] = b1[6] * f3 - b1[5] * f5;
  }
  /* Vertical transform */
  for (i = 0; i < 8; i++)
  {
    for (j = 0; j < 4; j++)
    {
      j1 = 7 - j;
      b1[j] = d[j][i] + d[j1][i];
      b1[j1] = d[j][i] - d[j1][i];
    }
    b[0] = b1[0] + b1[3];
    b[1] = b1[1] + b1[2];
    b[2] = b1[1] - b1[2];
    b[3] = b1[0] - b1[3];
    b[4] = b1[4];
    b[5] = (b1[6] - b1[5]) * f0;
    b[6] = (b1[6] + b1[5]) * f0;
    b[7] = b1[7];
    d[0][i] = (b[0] + b[1]) * f4;
    d[4][i] = (b[0] - b[1]) * f4;
    d[2][i] = b[2] * f6 + b[3] * f2;
    d[6][i] = b[3] * f6 - b[2] * f2;
    b1[4] = b[4] + b[5];
    b1[7] = b[7] + b[6];
    b1[5] = b[4] - b[5];
    b1[6] = b[7] - b[6];
    d[1][i] = b1[4] * f7 + b1[7] * f1;
    d[5][i] = b1[5] * f3 + b1[6] * f5;
    d[7][i] = b1[7] * f7 - b1[4] * f1;
    d[3][i] = b1[6] * f3 - b1[5] * f5;
  }
  for (i = 0; i < 8; i++)
  {
    for (j = 0; j < 8; j++)
    {
      *(coefs + j + i * 8) = (short) floor(d[i][j] +0.5);
    }
  }
  return;
}



void vp8_short_fhaar2x2_c(short *input, short *output, int pitch) //pitch = 8
{
    /* [1 1 ; 1 -1] orthogonal transform */
    /* use position: 0,1, 4, 8 */
   int i;
   short *ip1 = input;
   short *op1 = output;
   for (i = 0; i < 16; i++)
   {
       op1[i] = 0;
   }

   op1[0]=ip1[0] + ip1[1] + ip1[4] + ip1[8];
   op1[1]=ip1[0] - ip1[1] + ip1[4] - ip1[8];
   op1[4]=ip1[0] + ip1[1] - ip1[4] - ip1[8];
   op1[8]=ip1[0] - ip1[1] - ip1[4] + ip1[8];

}
Yaowu Xu's avatar
Yaowu Xu committed
129
#endif
John Koleszar's avatar
John Koleszar committed
130 131 132 133 134 135 136 137 138
void vp8_short_fdct4x4_c(short *input, short *output, int pitch)
{
    int i;
    int a1, b1, c1, d1;
    short *ip = input;
    short *op = output;

    for (i = 0; i < 4; i++)
    {
139 140 141 142 143 144
#if CONFIG_EXTEND_QRANGE
        a1 = ((ip[0] + ip[3])<<5);
        b1 = ((ip[1] + ip[2])<<5);
        c1 = ((ip[1] - ip[2])<<5);
        d1 = ((ip[0] - ip[3])<<5);
#else
Yaowu Xu's avatar
Yaowu Xu committed
145 146 147 148
        a1 = ((ip[0] + ip[3])<<3);
        b1 = ((ip[1] + ip[2])<<3);
        c1 = ((ip[1] - ip[2])<<3);
        d1 = ((ip[0] - ip[3])<<3);
149
#endif
Yaowu Xu's avatar
Yaowu Xu committed
150 151
        op[0] = a1 + b1;
        op[2] = a1 - b1;
John Koleszar's avatar
John Koleszar committed
152

Yaowu Xu's avatar
Yaowu Xu committed
153 154
        op[1] = (c1 * 2217 + d1 * 5352 +  14500)>>12;
        op[3] = (d1 * 2217 - c1 * 5352 +   7500)>>12;
John Koleszar's avatar
John Koleszar committed
155 156 157 158

        ip += pitch / 2;
        op += 4;

Yaowu Xu's avatar
Yaowu Xu committed
159
    }
John Koleszar's avatar
John Koleszar committed
160 161 162 163 164 165 166 167 168
    ip = output;
    op = output;
    for (i = 0; i < 4; i++)
    {
        a1 = ip[0] + ip[12];
        b1 = ip[4] + ip[8];
        c1 = ip[4] - ip[8];
        d1 = ip[0] - ip[12];

Yaowu Xu's avatar
Yaowu Xu committed
169 170
        op[0]  = ( a1 + b1 + 7)>>4;
        op[8]  = ( a1 - b1 + 7)>>4;
John Koleszar's avatar
John Koleszar committed
171

Yaowu Xu's avatar
Yaowu Xu committed
172 173
        op[4]  =((c1 * 2217 + d1 * 5352 +  12000)>>16) + (d1!=0);
        op[12] = (d1 * 2217 - c1 * 5352 +  51000)>>16;
John Koleszar's avatar
John Koleszar committed
174 175 176 177 178 179

        ip++;
        op++;
    }
}

Yaowu Xu's avatar
Yaowu Xu committed
180 181 182 183 184
void vp8_short_fdct8x4_c(short *input, short *output, int pitch)
{
    vp8_short_fdct4x4_c(input,   output,    pitch);
    vp8_short_fdct4x4_c(input + 4, output + 16, pitch);
}
John Koleszar's avatar
John Koleszar committed
185 186 187 188 189 190 191 192 193

void vp8_short_walsh4x4_c(short *input, short *output, int pitch)
{
    int i;
    int a1, b1, c1, d1;
    int a2, b2, c2, d2;
    short *ip = input;
    short *op = output;

194

John Koleszar's avatar
John Koleszar committed
195 196
    for (i = 0; i < 4; i++)
    {
197
#if !CONFIG_EXTEND_QRANGE
198 199 200 201 202
        a1 = ((ip[0] + ip[2])<<2);
        d1 = ((ip[1] + ip[3])<<2);
        c1 = ((ip[1] - ip[3])<<2);
        b1 = ((ip[0] - ip[2])<<2);

Yaowu Xu's avatar
Yaowu Xu committed
203
        op[0] = a1 + d1 + (a1!=0);
204 205 206 207 208 209 210 211 212
#else
        a1 = ((ip[0] + ip[2]));
        d1 = ((ip[1] + ip[3]));
        c1 = ((ip[1] - ip[3]));
        b1 = ((ip[0] - ip[2]));


        op[0] = a1 + d1;
#endif
213 214 215
        op[1] = b1 + c1;
        op[2] = b1 - c1;
        op[3] = a1 - d1;
John Koleszar's avatar
John Koleszar committed
216 217 218 219 220 221 222 223 224
        ip += pitch / 2;
        op += 4;
    }

    ip = output;
    op = output;

    for (i = 0; i < 4; i++)
    {
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
        a1 = ip[0] + ip[8];
        d1 = ip[4] + ip[12];
        c1 = ip[4] - ip[12];
        b1 = ip[0] - ip[8];

        a2 = a1 + d1;
        b2 = b1 + c1;
        c2 = b1 - c1;
        d2 = a1 - d1;

        a2 += a2<0;
        b2 += b2<0;
        c2 += c2<0;
        d2 += d2<0;

240
#if !CONFIG_EXTEND_QRANGE
241 242 243 244
        op[0] = (a2+3) >> 3;
        op[4] = (b2+3) >> 3;
        op[8] = (c2+3) >> 3;
        op[12]= (d2+3) >> 3;
245 246 247 248 249 250
#else
        op[0] = (a2+1) >> 2;
        op[4] = (b2+1) >> 2;
        op[8] = (c2+1) >> 2;
        op[12]= (d2+1) >> 2;
#endif
John Koleszar's avatar
John Koleszar committed
251 252 253 254
        ip++;
        op++;
    }
}