Main MRPT website > C++ reference for MRPT 1.5.6
jfdctfst.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #define JPEG_INTERNALS
11 #include "jinclude.h"
12 #include "mrpt_jpeglib.h"
13 #include "jdct.h" /* Private declarations for DCT subsystem */
14 
15 #ifdef DCT_IFAST_SUPPORTED
16 
17 
18 /*
19  * This module is specialized to the case DCTSIZE = 8.
20  */
21 
22 #if DCTSIZE != 8
23  Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
24 #endif
25 
26 
27 /* Scaling decisions are generally the same as in the LL&M algorithm;
28  * see jfdctint.c for more details. However, we choose to descale
29  * (right shift) multiplication products as soon as they are formed,
30  * rather than carrying additional fractional bits into subsequent additions.
31  * This compromises accuracy slightly, but it lets us save a few shifts.
32  * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
33  * everywhere except in the multiplications proper; this saves a good deal
34  * of work on 16-bit-int machines.
35  *
36  * Again to save a few shifts, the intermediate results between pass 1 and
37  * pass 2 are not upscaled, but are represented only to integral precision.
38  *
39  * A final compromise is to represent the multiplicative constants to only
40  * 8 fractional bits, rather than 13. This saves some shifting work on some
41  * machines, and may also reduce the cost of multiplication (since there
42  * are fewer one-bits in the constants).
43  */
44 
45 #define CONST_BITS 8
46 
47 
48 /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
49  * causing a lot of useless floating-point operations at run time.
50  * To get around this we use the following pre-calculated constants.
51  * If you change CONST_BITS you may want to add appropriate values.
52  * (With a reasonable C compiler, you can just rely on the FIX() macro...)
53  */
54 
55 #if CONST_BITS == 8
56 #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
57 #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
58 #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
59 #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
60 #else
61 #define FIX_0_382683433 FIX(0.382683433)
62 #define FIX_0_541196100 FIX(0.541196100)
63 #define FIX_0_707106781 FIX(0.707106781)
64 #define FIX_1_306562965 FIX(1.306562965)
65 #endif
66 
67 
68 /* We can gain a little more speed, with a further compromise in accuracy,
69  * by omitting the addition in a descaling shift. This yields an incorrectly
70  * rounded result half the time...
71  */
72 
73 #ifndef USE_ACCURATE_ROUNDING
74 #undef DESCALE
75 #define DESCALE(x,n) RIGHT_SHIFT(x, n)
76 #endif
77 
78 
79 /* Multiply a DCTELEM variable by an INT32 constant, and immediately
80  * descale to yield a DCTELEM result.
81  */
82 
83 #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
84 
85 
86 /*
87  * Perform the forward DCT on one block of samples.
88  */
89 
90 GLOBAL(void)
92 {
93  DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
94  DCTELEM tmp10, tmp11, tmp12, tmp13;
95  DCTELEM z1, z2, z3, z4, z5, z11, z13;
97  int ctr;
99 
100  /* Pass 1: process rows. */
101 
102  dataptr = data;
103  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
104  tmp0 = dataptr[0] + dataptr[7];
105  tmp7 = dataptr[0] - dataptr[7];
106  tmp1 = dataptr[1] + dataptr[6];
107  tmp6 = dataptr[1] - dataptr[6];
108  tmp2 = dataptr[2] + dataptr[5];
109  tmp5 = dataptr[2] - dataptr[5];
110  tmp3 = dataptr[3] + dataptr[4];
111  tmp4 = dataptr[3] - dataptr[4];
112 
113  /* Even part */
114 
115  tmp10 = tmp0 + tmp3; /* phase 2 */
116  tmp13 = tmp0 - tmp3;
117  tmp11 = tmp1 + tmp2;
118  tmp12 = tmp1 - tmp2;
119 
120  dataptr[0] = tmp10 + tmp11; /* phase 3 */
121  dataptr[4] = tmp10 - tmp11;
122 
123  z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
124  dataptr[2] = tmp13 + z1; /* phase 5 */
125  dataptr[6] = tmp13 - z1;
126 
127  /* Odd part */
128 
129  tmp10 = tmp4 + tmp5; /* phase 2 */
130  tmp11 = tmp5 + tmp6;
131  tmp12 = tmp6 + tmp7;
132 
133  /* The rotator is modified from fig 4-8 to avoid extra negations. */
134  z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
135  z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
136  z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
137  z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
138 
139  z11 = tmp7 + z3; /* phase 5 */
140  z13 = tmp7 - z3;
141 
142  dataptr[5] = z13 + z2; /* phase 6 */
143  dataptr[3] = z13 - z2;
144  dataptr[1] = z11 + z4;
145  dataptr[7] = z11 - z4;
146 
147  dataptr += DCTSIZE; /* advance pointer to next row */
148  }
149 
150  /* Pass 2: process columns. */
151 
152  dataptr = data;
153  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
154  tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
155  tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
156  tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
157  tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
158  tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
159  tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
160  tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
161  tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
162 
163  /* Even part */
164 
165  tmp10 = tmp0 + tmp3; /* phase 2 */
166  tmp13 = tmp0 - tmp3;
167  tmp11 = tmp1 + tmp2;
168  tmp12 = tmp1 - tmp2;
169 
170  dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
171  dataptr[DCTSIZE*4] = tmp10 - tmp11;
172 
173  z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
174  dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
175  dataptr[DCTSIZE*6] = tmp13 - z1;
176 
177  /* Odd part */
178 
179  tmp10 = tmp4 + tmp5; /* phase 2 */
180  tmp11 = tmp5 + tmp6;
181  tmp12 = tmp6 + tmp7;
182 
183  /* The rotator is modified from fig 4-8 to avoid extra negations. */
184  z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
185  z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
186  z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
187  z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
188 
189  z11 = tmp7 + z3; /* phase 5 */
190  z13 = tmp7 - z3;
191 
192  dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
193  dataptr[DCTSIZE*3] = z13 - z2;
194  dataptr[DCTSIZE*1] = z11 + z4;
195  dataptr[DCTSIZE*7] = z11 - z4;
196 
197  dataptr++; /* advance pointer to next column */
198  }
199 }
200 
201 #endif /* DCT_IFAST_SUPPORTED */
int const JOCTET * dataptr
Definition: mrpt_jpeglib.h:947
#define DCTSIZE
Definition: mrpt_jpeglib.h:38
#define FIX_0_382683433
Definition: jfdctfst.cpp:56
INT32 DCTELEM
Definition: jdct.h:27
#define SHIFT_TEMPS
Definition: jpegint.h:286
#define FIX_0_707106781
Definition: jfdctfst.cpp:58
#define FIX_1_306562965
Definition: jfdctfst.cpp:59
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1284
Definition: inftrees.h:28
#define FIX_0_541196100
Definition: jfdctfst.cpp:57
#define GLOBAL(type)
Definition: jmorecfg.h:185
jpeg_fdct_ifast(DCTELEM *data)
Definition: jfdctfst.cpp:91
#define MULTIPLY(var, const)
Definition: jfdctfst.cpp:83



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018