Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.4 KiB

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. /*
  4. * jfdctflt.c
  5. *
  6. * Copyright (C) 1994-1996, Thomas G. Lane.
  7. * This file is part of the Independent JPEG Group's software.
  8. * For conditions of distribution and use, see the accompanying README file.
  9. *
  10. * This file contains a floating-point implementation of the
  11. * forward DCT (Discrete Cosine Transform).
  12. *
  13. * This implementation should be more accurate than either of the integer
  14. * DCT implementations. However, it may not give the same results on all
  15. * machines because of differences in roundoff behavior. Speed will depend
  16. * on the hardware's floating point capacity.
  17. *
  18. * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
  19. * on each column. Direct algorithms are also available, but they are
  20. * much more complex and seem not to be any faster when reduced to code.
  21. *
  22. * This implementation is based on Arai, Agui, and Nakajima's algorithm for
  23. * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
  24. * Japanese, but the algorithm is described in the Pennebaker & Mitchell
  25. * JPEG textbook (see REFERENCES section in file README). The following code
  26. * is based directly on figure 4-8 in P&M.
  27. * While an 8-point DCT cannot be done in less than 11 multiplies, it is
  28. * possible to arrange the computation so that many of the multiplies are
  29. * simple scalings of the final outputs. These multiplies can then be
  30. * folded into the multiplications or divisions by the JPEG quantization
  31. * table entries. The AA&N method leaves only 5 multiplies and 29 adds
  32. * to be done in the DCT itself.
  33. * The primary disadvantage of this method is that with a fixed-point
  34. * implementation, accuracy is lost due to imprecise representation of the
  35. * scaled quantization values. However, that problem does not arise if
  36. * we use floating point arithmetic.
  37. */
  38. #define JPEG_INTERNALS
  39. #include "jinclude.h"
  40. #include "jpeglib.h"
  41. #include "jdct.h" /* Private declarations for DCT subsystem */
  42. #ifdef DCT_FLOAT_SUPPORTED
  43. /*
  44. * This module is specialized to the case DCTSIZE = 8.
  45. */
  46. #if DCTSIZE != 8
  47. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  48. #endif
  49. /*
  50. * Perform the forward DCT on one block of samples.
  51. */
  52. GLOBAL(void)
  53. jpeg_fdct_float (FAST_FLOAT * data)
  54. {
  55. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  56. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  57. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  58. FAST_FLOAT *dataptr;
  59. int ctr;
  60. /* Pass 1: process rows. */
  61. dataptr = data;
  62. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  63. tmp0 = dataptr[0] + dataptr[7];
  64. tmp7 = dataptr[0] - dataptr[7];
  65. tmp1 = dataptr[1] + dataptr[6];
  66. tmp6 = dataptr[1] - dataptr[6];
  67. tmp2 = dataptr[2] + dataptr[5];
  68. tmp5 = dataptr[2] - dataptr[5];
  69. tmp3 = dataptr[3] + dataptr[4];
  70. tmp4 = dataptr[3] - dataptr[4];
  71. /* Even part */
  72. tmp10 = tmp0 + tmp3; /* phase 2 */
  73. tmp13 = tmp0 - tmp3;
  74. tmp11 = tmp1 + tmp2;
  75. tmp12 = tmp1 - tmp2;
  76. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  77. dataptr[4] = tmp10 - tmp11;
  78. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  79. dataptr[2] = tmp13 + z1; /* phase 5 */
  80. dataptr[6] = tmp13 - z1;
  81. /* Odd part */
  82. tmp10 = tmp4 + tmp5; /* phase 2 */
  83. tmp11 = tmp5 + tmp6;
  84. tmp12 = tmp6 + tmp7;
  85. /* The rotator is modified from fig 4-8 to avoid extra negations. */
  86. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  87. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  88. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  89. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  90. z11 = tmp7 + z3; /* phase 5 */
  91. z13 = tmp7 - z3;
  92. dataptr[5] = z13 + z2; /* phase 6 */
  93. dataptr[3] = z13 - z2;
  94. dataptr[1] = z11 + z4;
  95. dataptr[7] = z11 - z4;
  96. dataptr += DCTSIZE; /* advance pointer to next row */
  97. }
  98. /* Pass 2: process columns. */
  99. dataptr = data;
  100. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  101. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  102. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  103. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  104. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  105. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  106. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  107. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  108. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  109. /* Even part */
  110. tmp10 = tmp0 + tmp3; /* phase 2 */
  111. tmp13 = tmp0 - tmp3;
  112. tmp11 = tmp1 + tmp2;
  113. tmp12 = tmp1 - tmp2;
  114. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  115. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  116. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  117. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  118. dataptr[DCTSIZE*6] = tmp13 - z1;
  119. /* Odd part */
  120. tmp10 = tmp4 + tmp5; /* phase 2 */
  121. tmp11 = tmp5 + tmp6;
  122. tmp12 = tmp6 + tmp7;
  123. /* The rotator is modified from fig 4-8 to avoid extra negations. */
  124. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  125. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  126. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  127. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  128. z11 = tmp7 + z3; /* phase 5 */
  129. z13 = tmp7 - z3;
  130. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  131. dataptr[DCTSIZE*3] = z13 - z2;
  132. dataptr[DCTSIZE*1] = z11 + z4;
  133. dataptr[DCTSIZE*7] = z11 - z4;
  134. dataptr++; /* advance pointer to next column */
  135. }
  136. }
  137. #endif /* DCT_FLOAT_SUPPORTED */