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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019