Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * jidctvenum.c |
| 3 | * |
| 4 | * Copyright (c) 2010, Code Aurora Forum. All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following |
| 13 | * disclaimer in the documentation and/or other materials provided |
| 14 | * with the distribution. |
| 15 | * * Neither the name of Code Aurora Forum, Inc. nor the names of its |
| 16 | * contributors may be used to endorse or promote products derived |
| 17 | * from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 26 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 29 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | #define JPEG_INTERNALS |
| 33 | #include "jinclude.h" |
| 34 | #include "jpeglib.h" |
| 35 | #include "jdct.h" /* Private declarations for DCT subsystem */ |
| 36 | |
| 37 | #ifdef ANDROID_JPEG_USE_VENUM |
| 38 | /* |
| 39 | * This module is specialized to the case DCTSIZE = 8. |
| 40 | */ |
| 41 | #if DCTSIZE != 8 |
| 42 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ |
| 43 | #endif |
| 44 | |
| 45 | /* Dequantize a coefficient by multiplying it by the multiplier-table |
| 46 | * entry; produce an int result. In this module, both inputs and result |
| 47 | * are 16 bits or less, so either int or short multiply will work. |
| 48 | */ |
| 49 | |
| 50 | #define DEQUANTIZE(coef,quantval) ((coef) * ((INT16)quantval)) |
| 51 | |
| 52 | GLOBAL(void) |
| 53 | jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
| 54 | JCOEFPTR coef_block, |
| 55 | JSAMPARRAY output_buf, JDIMENSION output_col) |
| 56 | { |
| 57 | ISLOW_MULT_TYPE * quantptr; |
| 58 | JCOEFPTR coefptr; |
| 59 | int ctr; |
| 60 | |
| 61 | /* idct_out temp buffer is needed because output_buf sample allocation is 8 bits, |
| 62 | * while IDCT output expects 16 bits. |
| 63 | */ |
| 64 | INT16 idct_out[DCTSIZE2]; /* buffers data between passes */ |
| 65 | JSAMPROW outptr; |
| 66 | INT16* idctptr; |
| 67 | |
| 68 | coefptr = coef_block; |
| 69 | quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; |
| 70 | |
| 71 | /* Dequantize the coeff buffer and write it back to the same location */ |
| 72 | for (ctr = DCTSIZE; ctr > 0; ctr--) { |
| 73 | coefptr[0] = DEQUANTIZE(coefptr[0] , quantptr[0] ); |
| 74 | coefptr[DCTSIZE*1] = DEQUANTIZE(coefptr[DCTSIZE*1], quantptr[DCTSIZE*1]); |
| 75 | coefptr[DCTSIZE*2] = DEQUANTIZE(coefptr[DCTSIZE*2], quantptr[DCTSIZE*2]); |
| 76 | coefptr[DCTSIZE*3] = DEQUANTIZE(coefptr[DCTSIZE*3], quantptr[DCTSIZE*3]); |
| 77 | coefptr[DCTSIZE*4] = DEQUANTIZE(coefptr[DCTSIZE*4], quantptr[DCTSIZE*4]); |
| 78 | coefptr[DCTSIZE*5] = DEQUANTIZE(coefptr[DCTSIZE*5], quantptr[DCTSIZE*5]); |
| 79 | coefptr[DCTSIZE*6] = DEQUANTIZE(coefptr[DCTSIZE*6], quantptr[DCTSIZE*6]); |
| 80 | coefptr[DCTSIZE*7] = DEQUANTIZE(coefptr[DCTSIZE*7], quantptr[DCTSIZE*7]); |
| 81 | |
| 82 | /* advance pointers to next column */ |
| 83 | quantptr++; |
| 84 | coefptr++; |
| 85 | } |
| 86 | |
| 87 | idct_8x8_venum((INT16*)coef_block, |
| 88 | (INT16*)idct_out, |
| 89 | DCTSIZE * sizeof(INT16)); |
| 90 | |
| 91 | idctptr = idct_out; |
| 92 | for (ctr = 0; ctr < DCTSIZE; ctr++) { |
| 93 | outptr = output_buf[ctr] + output_col; |
| 94 | // outptr sample size is 1 byte while idctptr sample size is 2 bytes |
| 95 | outptr[0] = idctptr[0]; |
| 96 | outptr[1] = idctptr[1]; |
| 97 | outptr[2] = idctptr[2]; |
| 98 | outptr[3] = idctptr[3]; |
| 99 | outptr[4] = idctptr[4]; |
| 100 | outptr[5] = idctptr[5]; |
| 101 | outptr[6] = idctptr[6]; |
| 102 | outptr[7] = idctptr[7]; |
| 103 | idctptr += DCTSIZE; /* advance pointers to next row */ |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | GLOBAL(void) |
| 108 | jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
| 109 | JCOEFPTR coef_block, |
| 110 | JSAMPARRAY output_buf, JDIMENSION output_col) |
| 111 | { |
| 112 | ISLOW_MULT_TYPE * quantptr; |
| 113 | JSAMPROW outptr; |
| 114 | |
| 115 | /* Note: Must allocate 8x4 even though only 4x4 is used because |
| 116 | * IDCT function expects stride of 8. Stride input to function is ignored. |
| 117 | */ |
| 118 | INT16 idct_out[DCTSIZE * (DCTSIZE>>1)]; /* buffers data between passes */ |
| 119 | INT16* idctptr; |
| 120 | JCOEFPTR coefptr; |
| 121 | int ctr; |
| 122 | |
| 123 | coefptr = coef_block; |
| 124 | quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; |
| 125 | |
| 126 | /* Dequantize the coeff buffer and write it back to the same location */ |
| 127 | for (ctr = (DCTSIZE>>1); ctr > 0; ctr--) { |
| 128 | coefptr[0] = DEQUANTIZE(coefptr[0] , quantptr[0] ); |
| 129 | coefptr[DCTSIZE*1] = DEQUANTIZE(coefptr[DCTSIZE*1], quantptr[DCTSIZE*1]); |
| 130 | coefptr[DCTSIZE*2] = DEQUANTIZE(coefptr[DCTSIZE*2], quantptr[DCTSIZE*2]); |
| 131 | coefptr[DCTSIZE*3] = DEQUANTIZE(coefptr[DCTSIZE*3], quantptr[DCTSIZE*3]); |
| 132 | |
| 133 | /* advance pointers to next column */ |
| 134 | quantptr++; |
| 135 | coefptr++; |
| 136 | } |
| 137 | |
| 138 | idct_4x4_venum((INT16*)coef_block, |
| 139 | (INT16*)idct_out, |
| 140 | DCTSIZE * sizeof(INT16)); |
| 141 | |
| 142 | idctptr = idct_out; |
| 143 | for (ctr = 0; ctr < (DCTSIZE>>1); ctr++) { |
| 144 | outptr = output_buf[ctr] + output_col; |
| 145 | |
| 146 | /* outptr sample size is 1 byte while idctptr sample size is 2 bytes */ |
| 147 | outptr[0] = idctptr[0]; |
| 148 | outptr[1] = idctptr[1]; |
| 149 | outptr[2] = idctptr[2]; |
| 150 | outptr[3] = idctptr[3]; |
| 151 | /* IDCT function assumes stride of 8 units */ |
| 152 | idctptr += (DCTSIZE); /* advance pointers to next row */ |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | GLOBAL(void) |
| 157 | jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
| 158 | JCOEFPTR coef_block, |
| 159 | JSAMPARRAY output_buf, JDIMENSION output_col) |
| 160 | { |
| 161 | ISLOW_MULT_TYPE * quantptr; |
| 162 | JSAMPROW outptr; |
| 163 | |
| 164 | /* Note: Must allocate 8x2 even though only 2x2 is used because |
| 165 | * IDCT function expects stride of 8. Stride input to function is ignored. |
| 166 | * There is also a hw limitation requiring input size to be 8x2. |
| 167 | */ |
| 168 | INT16 idct_out[DCTSIZE * (DCTSIZE>>2)]; /* buffers data between passes */ |
| 169 | INT16* idctptr; |
| 170 | JCOEFPTR coefptr; |
| 171 | int ctr; |
| 172 | |
| 173 | coefptr = coef_block; |
| 174 | quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; |
| 175 | |
| 176 | /* Dequantize the coeff buffer and write it back to the same location */ |
| 177 | for (ctr = (DCTSIZE>>2); ctr > 0; ctr--) { |
| 178 | coefptr[0] = DEQUANTIZE(coefptr[0] , quantptr[0] ); |
| 179 | coefptr[DCTSIZE*1] = DEQUANTIZE(coefptr[DCTSIZE*1], quantptr[DCTSIZE*1]); |
| 180 | |
| 181 | /* advance pointers to next column */ |
| 182 | quantptr++; |
| 183 | coefptr++; |
| 184 | } |
| 185 | |
| 186 | idct_2x2_venum((INT16*)coef_block, |
| 187 | (INT16*)idct_out, |
| 188 | DCTSIZE * sizeof(INT16)); |
| 189 | |
| 190 | idctptr = idct_out; |
| 191 | for (ctr = 0; ctr < (DCTSIZE>>2); ctr++) { |
| 192 | outptr = output_buf[ctr] + output_col; |
| 193 | |
| 194 | /* outptr sample size is 1 bytes, idctptr sample size is 2 bytes */ |
| 195 | outptr[0] = idctptr[0]; |
| 196 | outptr[1] = idctptr[1]; |
| 197 | |
| 198 | /* IDCT function assumes stride of 8 units */ |
| 199 | idctptr += (DCTSIZE); /* advance pointers to next row */ |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | |
| 204 | GLOBAL(void) |
| 205 | jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
| 206 | JCOEFPTR coef_block, |
| 207 | JSAMPARRAY output_buf, JDIMENSION output_col) |
| 208 | { |
| 209 | ISLOW_MULT_TYPE * quantptr; |
| 210 | JSAMPROW outptr; // 8-bit type |
| 211 | INT16 idct_out[DCTSIZE]; /* Required to allocate 8 samples, even though we only use one. */ |
| 212 | JCOEFPTR coefptr; |
| 213 | int ctr; |
| 214 | |
| 215 | coefptr = coef_block; |
| 216 | quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; |
| 217 | outptr = output_buf[0] + output_col; |
| 218 | |
| 219 | /* Dequantize the coeff buffer and write it back to the same location */ |
| 220 | coefptr[0] = DEQUANTIZE(coefptr[0], quantptr[0]); |
| 221 | |
| 222 | idct_1x1_venum((INT16*)coef_block, |
| 223 | (INT16*)idct_out, |
| 224 | DCTSIZE * sizeof(INT16)); |
| 225 | outptr[0] = idct_out[0]; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | #endif /* ANDROID_JPEG_USE_VENUM */ |