190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/*
2f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber *
4f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Use of this source code is governed by a BSD-style license
5f71323e297a928af368937089d3ed71239786f86Andreas Huber *  that can be found in the LICENSE file in the root of the source
6f71323e297a928af368937089d3ed71239786f86Andreas Huber *  tree. An additional intellectual property rights grant can be found
7f71323e297a928af368937089d3ed71239786f86Andreas Huber *  in the file PATENTS.  All contributing project authors may
8f71323e297a928af368937089d3ed71239786f86Andreas Huber *  be found in the AUTHORS file in the root of the source tree.
990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber */
1090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "vpx_ports/config.h"
1390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "dequantize.h"
1490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "predictdc.h"
1590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "idct.h"
1690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "vpx_mem/vpx_mem.h"
1790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberextern void vp8_short_idct4x4llm_c(short *input, short *output, int pitch) ;
1990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberextern void vp8_short_idct4x4llm_1_c(short *input, short *output, int pitch);
2090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
2190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
2290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubervoid vp8_dequantize_b_c(BLOCKD *d)
2390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
2490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int i;
2590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    short *DQ  = d->dqcoeff;
2690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    short *Q   = d->qcoeff;
2776e0247ec867fcc232fc79f21e9bf85d3c3a5a3fAndreas Huber    short *DQC = d->dequant;
2890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
2990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    for (i = 0; i < 16; i++)
3090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    {
3190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        DQ[i] = Q[i] * DQC[i];
3290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    }
3390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber}
3490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
35f71323e297a928af368937089d3ed71239786f86Andreas Hubervoid vp8_dequant_idct_add_c(short *input, short *dq, unsigned char *pred,
36f71323e297a928af368937089d3ed71239786f86Andreas Huber                            unsigned char *dest, int pitch, int stride)
3790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
38f71323e297a928af368937089d3ed71239786f86Andreas Huber    short output[16];
39f71323e297a928af368937089d3ed71239786f86Andreas Huber    short *diff_ptr = output;
40f71323e297a928af368937089d3ed71239786f86Andreas Huber    int r, c;
4190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int i;
4290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    for (i = 0; i < 16; i++)
4490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    {
4590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        input[i] = dq[i] * input[i];
4690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    }
4790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4876e0247ec867fcc232fc79f21e9bf85d3c3a5a3fAndreas Huber    /* the idct halves ( >> 1) the pitch */
49f71323e297a928af368937089d3ed71239786f86Andreas Huber    vp8_short_idct4x4llm_c(input, output, 4 << 1);
50f71323e297a928af368937089d3ed71239786f86Andreas Huber
5190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    vpx_memset(input, 0, 32);
52f71323e297a928af368937089d3ed71239786f86Andreas Huber
53f71323e297a928af368937089d3ed71239786f86Andreas Huber    for (r = 0; r < 4; r++)
54f71323e297a928af368937089d3ed71239786f86Andreas Huber    {
55f71323e297a928af368937089d3ed71239786f86Andreas Huber        for (c = 0; c < 4; c++)
56f71323e297a928af368937089d3ed71239786f86Andreas Huber        {
57f71323e297a928af368937089d3ed71239786f86Andreas Huber            int a = diff_ptr[c] + pred[c];
58f71323e297a928af368937089d3ed71239786f86Andreas Huber
59f71323e297a928af368937089d3ed71239786f86Andreas Huber            if (a < 0)
60f71323e297a928af368937089d3ed71239786f86Andreas Huber                a = 0;
61f71323e297a928af368937089d3ed71239786f86Andreas Huber
62f71323e297a928af368937089d3ed71239786f86Andreas Huber            if (a > 255)
63f71323e297a928af368937089d3ed71239786f86Andreas Huber                a = 255;
64f71323e297a928af368937089d3ed71239786f86Andreas Huber
65f71323e297a928af368937089d3ed71239786f86Andreas Huber            dest[c] = (unsigned char) a;
66f71323e297a928af368937089d3ed71239786f86Andreas Huber        }
67f71323e297a928af368937089d3ed71239786f86Andreas Huber
68f71323e297a928af368937089d3ed71239786f86Andreas Huber        dest += stride;
69f71323e297a928af368937089d3ed71239786f86Andreas Huber        diff_ptr += 4;
70f71323e297a928af368937089d3ed71239786f86Andreas Huber        pred += pitch;
71f71323e297a928af368937089d3ed71239786f86Andreas Huber    }
7290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber}
7390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
74f71323e297a928af368937089d3ed71239786f86Andreas Hubervoid vp8_dequant_dc_idct_add_c(short *input, short *dq, unsigned char *pred,
75f71323e297a928af368937089d3ed71239786f86Andreas Huber                               unsigned char *dest, int pitch, int stride,
76f71323e297a928af368937089d3ed71239786f86Andreas Huber                               int Dc)
7790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
7890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int i;
79f71323e297a928af368937089d3ed71239786f86Andreas Huber    short output[16];
80f71323e297a928af368937089d3ed71239786f86Andreas Huber    short *diff_ptr = output;
81f71323e297a928af368937089d3ed71239786f86Andreas Huber    int r, c;
8290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
8390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    input[0] = (short)Dc;
8490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
8590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    for (i = 1; i < 16; i++)
8690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    {
8790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        input[i] = dq[i] * input[i];
8890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    }
8990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
9076e0247ec867fcc232fc79f21e9bf85d3c3a5a3fAndreas Huber    /* the idct halves ( >> 1) the pitch */
91f71323e297a928af368937089d3ed71239786f86Andreas Huber    vp8_short_idct4x4llm_c(input, output, 4 << 1);
92f71323e297a928af368937089d3ed71239786f86Andreas Huber
9390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    vpx_memset(input, 0, 32);
94f71323e297a928af368937089d3ed71239786f86Andreas Huber
95f71323e297a928af368937089d3ed71239786f86Andreas Huber    for (r = 0; r < 4; r++)
96f71323e297a928af368937089d3ed71239786f86Andreas Huber    {
97f71323e297a928af368937089d3ed71239786f86Andreas Huber        for (c = 0; c < 4; c++)
98f71323e297a928af368937089d3ed71239786f86Andreas Huber        {
99f71323e297a928af368937089d3ed71239786f86Andreas Huber            int a = diff_ptr[c] + pred[c];
100f71323e297a928af368937089d3ed71239786f86Andreas Huber
101f71323e297a928af368937089d3ed71239786f86Andreas Huber            if (a < 0)
102f71323e297a928af368937089d3ed71239786f86Andreas Huber                a = 0;
103f71323e297a928af368937089d3ed71239786f86Andreas Huber
104f71323e297a928af368937089d3ed71239786f86Andreas Huber            if (a > 255)
105f71323e297a928af368937089d3ed71239786f86Andreas Huber                a = 255;
106f71323e297a928af368937089d3ed71239786f86Andreas Huber
107f71323e297a928af368937089d3ed71239786f86Andreas Huber            dest[c] = (unsigned char) a;
108f71323e297a928af368937089d3ed71239786f86Andreas Huber        }
109f71323e297a928af368937089d3ed71239786f86Andreas Huber
110f71323e297a928af368937089d3ed71239786f86Andreas Huber        dest += stride;
111f71323e297a928af368937089d3ed71239786f86Andreas Huber        diff_ptr += 4;
112f71323e297a928af368937089d3ed71239786f86Andreas Huber        pred += pitch;
113f71323e297a928af368937089d3ed71239786f86Andreas Huber    }
11490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber}
115