Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
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.

175 lines
5.5 KiB

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