1 /* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * 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. 9 */ 10 11 #include "vp9_rtcd.h" 12 #include "vp9/common/vp9_blockd.h" 13 #include "vp9/decoder/vp9_idct_blk.h" 14 15 static void add_constant_residual(const int16_t diff, uint8_t *dest, int stride, 16 int width, int height) { 17 int r, c; 18 19 for (r = 0; r < height; r++) { 20 for (c = 0; c < width; c++) 21 dest[c] = clip_pixel(diff + dest[c]); 22 23 dest += stride; 24 } 25 } 26 27 void vp9_add_constant_residual_8x8_c(const int16_t diff, uint8_t *dest, 28 int stride) { 29 add_constant_residual(diff, dest, stride, 8, 8); 30 } 31 32 void vp9_add_constant_residual_16x16_c(const int16_t diff, uint8_t *dest, 33 int stride) { 34 add_constant_residual(diff, dest, stride, 16, 16); 35 } 36 37 void vp9_add_constant_residual_32x32_c(const int16_t diff, uint8_t *dest, 38 int stride) { 39 add_constant_residual(diff, dest, stride, 32, 32); 40 } 41 42 void vp9_iht_add_c(TX_TYPE tx_type, int16_t *input, uint8_t *dest, int stride, 43 int eob) { 44 if (tx_type == DCT_DCT) { 45 vp9_idct_add(input, dest, stride, eob); 46 } else { 47 vp9_short_iht4x4_add(input, dest, stride, tx_type); 48 vpx_memset(input, 0, 32); 49 } 50 } 51 52 void vp9_iht_add_8x8_c(TX_TYPE tx_type, int16_t *input, uint8_t *dest, 53 int stride, int eob) { 54 if (tx_type == DCT_DCT) { 55 vp9_idct_add_8x8(input, dest, stride, eob); 56 } else { 57 if (eob > 0) { 58 vp9_short_iht8x8_add(input, dest, stride, tx_type); 59 vpx_memset(input, 0, 128); 60 } 61 } 62 } 63 64 void vp9_idct_add_c(int16_t *input, uint8_t *dest, int stride, int eob) { 65 if (eob > 1) { 66 vp9_short_idct4x4_add(input, dest, stride); 67 vpx_memset(input, 0, 32); 68 } else { 69 vp9_short_idct4x4_1_add(input, dest, stride); 70 ((int *)input)[0] = 0; 71 } 72 } 73 74 void vp9_idct_add_lossless_c(int16_t *input, uint8_t *dest, int stride, 75 int eob) { 76 if (eob > 1) { 77 vp9_short_iwalsh4x4_add(input, dest, stride); 78 vpx_memset(input, 0, 32); 79 } else { 80 vp9_short_iwalsh4x4_1_add_c(input, dest, stride); 81 ((int *)input)[0] = 0; 82 } 83 } 84 85 void vp9_idct_add_8x8_c(int16_t *input, uint8_t *dest, int stride, int eob) { 86 // If dc is 1, then input[0] is the reconstructed value, do not need 87 // dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1. 88 89 // The calculation can be simplified if there are not many non-zero dct 90 // coefficients. Use eobs to decide what to do. 91 // TODO(yunqingwang): "eobs = 1" case is also handled in vp9_short_idct8x8_c. 92 // Combine that with code here. 93 if (eob) { 94 if (eob == 1) { 95 // DC only DCT coefficient 96 vp9_short_idct8x8_1_add(input, dest, stride); 97 input[0] = 0; 98 } else if (eob <= 10) { 99 vp9_short_idct10_8x8_add(input, dest, stride); 100 vpx_memset(input, 0, 128); 101 } else { 102 vp9_short_idct8x8_add(input, dest, stride); 103 vpx_memset(input, 0, 128); 104 } 105 } 106 } 107 108 void vp9_iht_add_16x16_c(TX_TYPE tx_type, int16_t *input, uint8_t *dest, 109 int stride, int eob) { 110 if (tx_type == DCT_DCT) { 111 vp9_idct_add_16x16(input, dest, stride, eob); 112 } else { 113 if (eob > 0) { 114 vp9_short_iht16x16_add(input, dest, stride, tx_type); 115 vpx_memset(input, 0, 512); 116 } 117 } 118 } 119 120 void vp9_idct_add_16x16_c(int16_t *input, uint8_t *dest, int stride, int eob) { 121 /* The calculation can be simplified if there are not many non-zero dct 122 * coefficients. Use eobs to separate different cases. */ 123 if (eob) { 124 if (eob == 1) { 125 /* DC only DCT coefficient. */ 126 vp9_short_idct16x16_1_add(input, dest, stride); 127 input[0] = 0; 128 } else if (eob <= 10) { 129 vp9_short_idct10_16x16_add(input, dest, stride); 130 vpx_memset(input, 0, 512); 131 } else { 132 vp9_short_idct16x16_add(input, dest, stride); 133 vpx_memset(input, 0, 512); 134 } 135 } 136 } 137 138 void vp9_idct_add_32x32_c(int16_t *input, uint8_t *dest, int stride, int eob) { 139 DECLARE_ALIGNED_ARRAY(16, int16_t, output, 1024); 140 141 if (eob) { 142 if (eob == 1) { 143 vp9_short_idct1_32x32(input, output); 144 vp9_add_constant_residual_32x32(output[0], dest, stride); 145 input[0] = 0; 146 } else { 147 vp9_short_idct32x32_add(input, dest, stride); 148 vpx_memset(input, 0, 2048); 149 } 150 } 151 } 152 153