jidctred.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. Unit JIDctRed;
  2. { This file contains inverse-DCT routines that produce reduced-size output:
  3. either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block.
  4. The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M)
  5. algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step
  6. with an 8-to-4 step that produces the four averages of two adjacent outputs
  7. (or an 8-to-2 step producing two averages of four outputs, for 2x2 output).
  8. These steps were derived by computing the corresponding values at the end
  9. of the normal LL&M code, then simplifying as much as possible.
  10. 1x1 is trivial: just take the DC coefficient divided by 8.
  11. See jidctint.c for additional comments. }
  12. { Original : jidctred.c ; Copyright (C) 1994-1998, Thomas G. Lane. }
  13. interface
  14. {$I jconfig.inc}
  15. uses
  16. jmorecfg,
  17. jinclude,
  18. jpeglib,
  19. jdct; { Private declarations for DCT subsystem }
  20. { Perform dequantization and inverse DCT on one block of coefficients,
  21. producing a reduced-size 1x1 output block. }
  22. {GLOBAL}
  23. procedure jpeg_idct_1x1 (cinfo : j_decompress_ptr;
  24. compptr : jpeg_component_info_ptr;
  25. coef_block : JCOEFPTR;
  26. output_buf : JSAMPARRAY;
  27. output_col : JDIMENSION);
  28. { Perform dequantization and inverse DCT on one block of coefficients,
  29. producing a reduced-size 2x2 output block. }
  30. {GLOBAL}
  31. procedure jpeg_idct_2x2 (cinfo : j_decompress_ptr;
  32. compptr : jpeg_component_info_ptr;
  33. coef_block : JCOEFPTR;
  34. output_buf : JSAMPARRAY;
  35. output_col : JDIMENSION);
  36. { Perform dequantization and inverse DCT on one block of coefficients,
  37. producing a reduced-size 4x4 output block. }
  38. {GLOBAL}
  39. procedure jpeg_idct_4x4 (cinfo : j_decompress_ptr;
  40. compptr : jpeg_component_info_ptr;
  41. coef_block : JCOEFPTR;
  42. output_buf : JSAMPARRAY;
  43. output_col : JDIMENSION);
  44. implementation
  45. { This module is specialized to the case DCTSIZE = 8. }
  46. {$ifndef DCTSIZE_IS_8}
  47. Sorry, this code only copes with 8x8 DCTs. { deliberate syntax err }
  48. {$endif}
  49. { Scaling is the same as in jidctint.c. }
  50. {$ifdef BITS_IN_JSAMPLE_IS_8}
  51. const
  52. CONST_BITS = 13;
  53. PASS1_BITS = 2;
  54. {$else}
  55. const
  56. CONST_BITS = 13;
  57. PASS1_BITS = 1; { lose a little precision to avoid overflow }
  58. {$endif}
  59. const
  60. FIX_0_211164243 = INT32(Round((INT32(1) shl CONST_BITS) * 0.211164243)); {1730}
  61. FIX_0_509795579 = INT32(Round((INT32(1) shl CONST_BITS) * 0.509795579)); {4176}
  62. FIX_0_601344887 = INT32(Round((INT32(1) shl CONST_BITS) * 0.601344887)); {4926}
  63. FIX_0_720959822 = INT32(Round((INT32(1) shl CONST_BITS) * 0.720959822)); {5906}
  64. FIX_0_765366865 = INT32(Round((INT32(1) shl CONST_BITS) * 0.765366865)); {6270}
  65. FIX_0_850430095 = INT32(Round((INT32(1) shl CONST_BITS) * 0.850430095)); {6967}
  66. FIX_0_899976223 = INT32(Round((INT32(1) shl CONST_BITS) * 0.899976223)); {7373}
  67. FIX_1_061594337 = INT32(Round((INT32(1) shl CONST_BITS) * 1.061594337)); {8697}
  68. FIX_1_272758580 = INT32(Round((INT32(1) shl CONST_BITS) * 1.272758580)); {10426}
  69. FIX_1_451774981 = INT32(Round((INT32(1) shl CONST_BITS) * 1.451774981)); {11893}
  70. FIX_1_847759065 = INT32(Round((INT32(1) shl CONST_BITS) * 1.847759065)); {15137}
  71. FIX_2_172734803 = INT32(Round((INT32(1) shl CONST_BITS) * 2.172734803)); {17799}
  72. FIX_2_562915447 = INT32(Round((INT32(1) shl CONST_BITS) * 2.562915447)); {20995}
  73. FIX_3_624509785 = INT32(Round((INT32(1) shl CONST_BITS) * 3.624509785)); {29692}
  74. { Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
  75. For 8-bit samples with the recommended scaling, all the variable
  76. and constant values involved are no more than 16 bits wide, so a
  77. 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
  78. For 12-bit samples, a full 32-bit multiplication will be needed. }
  79. {$ifdef BITS_IN_JSAMPLE_IS_8}
  80. {function Multiply(X, Y: Integer): integer; assembler;
  81. asm
  82. mov ax, X
  83. imul Y
  84. mov al, ah
  85. mov ah, dl
  86. end;}
  87. {MULTIPLY16C16(var,const)}
  88. function Multiply(X, Y: Integer): INT32;
  89. begin
  90. Multiply := X*INT32(Y);
  91. end;
  92. {$else}
  93. function Multiply(X, Y: INT32): INT32;
  94. begin
  95. Multiply := X*Y;
  96. end;
  97. {$endif}
  98. { Dequantize a coefficient by multiplying it by the multiplier-table
  99. entry; produce an int result. In this module, both inputs and result
  100. are 16 bits or less, so either int or short multiply will work. }
  101. function DEQUANTIZE(coef,quantval : int) : int;
  102. begin
  103. Dequantize := ( ISLOW_MULT_TYPE(coef) * quantval);
  104. end;
  105. { Descale and correctly round an INT32 value that's scaled by N bits.
  106. We assume RIGHT_SHIFT rounds towards minus infinity, so adding
  107. the fudge factor is correct for either sign of X. }
  108. function DESCALE(x : INT32; n : int) : INT32;
  109. var
  110. shift_temp : INT32;
  111. begin
  112. {$ifdef RIGHT_SHIFT_IS_UNSIGNED}
  113. shift_temp := x + (INT32(1) shl (n-1));
  114. if shift_temp < 0 then
  115. Descale := (shift_temp shr n) or ((not INT32(0)) shl (32-n))
  116. else
  117. Descale := (shift_temp shr n);
  118. {$else}
  119. Descale := (x + (INT32(1) shl (n-1)) shr n;
  120. {$endif}
  121. end;
  122. { Perform dequantization and inverse DCT on one block of coefficients,
  123. producing a reduced-size 4x4 output block. }
  124. {GLOBAL}
  125. procedure jpeg_idct_4x4 (cinfo : j_decompress_ptr;
  126. compptr : jpeg_component_info_ptr;
  127. coef_block : JCOEFPTR;
  128. output_buf : JSAMPARRAY;
  129. output_col : JDIMENSION);
  130. type
  131. PWorkspace = ^TWorkspace;
  132. TWorkspace = array[0..(DCTSIZE*4)-1] of int; { buffers data between passes }
  133. var
  134. tmp0, tmp2, tmp10, tmp12 : INT32;
  135. z1, z2, z3, z4 : INT32;
  136. inptr : JCOEFPTR;
  137. quantptr : ISLOW_MULT_TYPE_FIELD_PTR;
  138. wsptr : PWorkspace;
  139. outptr : JSAMPROW;
  140. range_limit : JSAMPROW;
  141. ctr : int;
  142. workspace : TWorkspace; { buffers data between passes }
  143. {SHIFT_TEMPS}
  144. var
  145. dcval : int;
  146. var
  147. dcval_ : JSAMPLE;
  148. begin
  149. { Each IDCT routine is responsible for range-limiting its results and
  150. converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
  151. be quite far out of range if the input data is corrupt, so a bulletproof
  152. range-limiting step is required. We use a mask-and-table-lookup method
  153. to do the combined operations quickly. See the comments with
  154. prepare_range_limit_table (in jdmaster.c) for more info. }
  155. range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
  156. { Pass 1: process columns from input, store into work array. }
  157. inptr := coef_block;
  158. quantptr := ISLOW_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
  159. wsptr := @workspace;
  160. for ctr := DCTSIZE downto 1 do
  161. begin
  162. { Don't bother to process column 4, because second pass won't use it }
  163. if (ctr = DCTSIZE-4) then
  164. begin
  165. Inc(JCOEF_PTR(inptr));
  166. Inc(ISLOW_MULT_TYPE_PTR(quantptr));
  167. Inc(int_ptr(wsptr));
  168. continue;
  169. end;
  170. if (inptr^[DCTSIZE*1]=0) and (inptr^[DCTSIZE*2]=0) and (inptr^[DCTSIZE*3]=0) and
  171. (inptr^[DCTSIZE*5]=0) and (inptr^[DCTSIZE*6]=0) and (inptr^[DCTSIZE*7]=0) then
  172. begin
  173. { AC terms all zero; we need not examine term 4 for 4x4 output }
  174. dcval := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) *
  175. quantptr^[DCTSIZE*0]) shl PASS1_BITS;
  176. wsptr^[DCTSIZE*0] := dcval;
  177. wsptr^[DCTSIZE*1] := dcval;
  178. wsptr^[DCTSIZE*2] := dcval;
  179. wsptr^[DCTSIZE*3] := dcval;
  180. Inc(JCOEF_PTR(inptr));
  181. Inc(ISLOW_MULT_TYPE_PTR(quantptr));
  182. Inc(int_ptr(wsptr));
  183. continue;
  184. end;
  185. { Even part }
  186. tmp0 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) * quantptr^[DCTSIZE*0]);
  187. tmp0 := tmp0 shl (CONST_BITS+1);
  188. z2 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*2]) * quantptr^[DCTSIZE*2]);
  189. z3 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*6]) * quantptr^[DCTSIZE*6]);
  190. tmp2 := MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  191. tmp10 := tmp0 + tmp2;
  192. tmp12 := tmp0 - tmp2;
  193. { Odd part }
  194. z1 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*7]) * quantptr^[DCTSIZE*7];
  195. z2 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*5]) * quantptr^[DCTSIZE*5];
  196. z3 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*3]) * quantptr^[DCTSIZE*3];
  197. z4 := ISLOW_MULT_TYPE(inptr^[DCTSIZE*1]) * quantptr^[DCTSIZE*1];
  198. tmp0 := MULTIPLY(z1, - FIX_0_211164243) { sqrt(2) * (c3-c1) }
  199. + MULTIPLY(z2, FIX_1_451774981) { sqrt(2) * (c3+c7) }
  200. + MULTIPLY(z3, - FIX_2_172734803) { sqrt(2) * (-c1-c5) }
  201. + MULTIPLY(z4, FIX_1_061594337); { sqrt(2) * (c5+c7) }
  202. tmp2 := MULTIPLY(z1, - FIX_0_509795579) { sqrt(2) * (c7-c5) }
  203. + MULTIPLY(z2, - FIX_0_601344887) { sqrt(2) * (c5-c1) }
  204. + MULTIPLY(z3, FIX_0_899976223) { sqrt(2) * (c3-c7) }
  205. + MULTIPLY(z4, FIX_2_562915447); { sqrt(2) * (c1+c3) }
  206. { Final output stage }
  207. wsptr^[DCTSIZE*0] := int(DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1));
  208. wsptr^[DCTSIZE*3] := int(DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1));
  209. wsptr^[DCTSIZE*1] := int(DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1));
  210. wsptr^[DCTSIZE*2] := int(DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1));
  211. Inc(JCOEF_PTR(inptr));
  212. Inc(ISLOW_MULT_TYPE_PTR(quantptr));
  213. Inc(int_ptr(wsptr));
  214. end;
  215. { Pass 2: process 4 rows from work array, store into output array. }
  216. wsptr := @workspace;
  217. for ctr := 0 to pred(4) do
  218. begin
  219. outptr := JSAMPROW(@ output_buf^[ctr]^[output_col]);
  220. { It's not clear whether a zero row test is worthwhile here ... }
  221. {$ifndef NO_ZERO_ROW_TEST}
  222. if (wsptr^[1]=0) and (wsptr^[2]=0) and (wsptr^[3]=0) and
  223. (wsptr^[5]=0) and (wsptr^[6]=0) and (wsptr^[7]=0) then
  224. begin
  225. { AC terms all zero }
  226. dcval_ := range_limit^[int(DESCALE(INT32(wsptr^[0]), PASS1_BITS+3))
  227. and RANGE_MASK];
  228. outptr^[0] := dcval_;
  229. outptr^[1] := dcval_;
  230. outptr^[2] := dcval_;
  231. outptr^[3] := dcval_;
  232. Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
  233. continue;
  234. end;
  235. {$endif}
  236. { Even part }
  237. tmp0 := (INT32(wsptr^[0])) shl (CONST_BITS+1);
  238. tmp2 := MULTIPLY(INT32(wsptr^[2]), FIX_1_847759065)
  239. + MULTIPLY(INT32(wsptr^[6]), - FIX_0_765366865);
  240. tmp10 := tmp0 + tmp2;
  241. tmp12 := tmp0 - tmp2;
  242. { Odd part }
  243. z1 := INT32(wsptr^[7]);
  244. z2 := INT32(wsptr^[5]);
  245. z3 := INT32(wsptr^[3]);
  246. z4 := INT32(wsptr^[1]);
  247. tmp0 := MULTIPLY(z1, - FIX_0_211164243) { sqrt(2) * (c3-c1) }
  248. + MULTIPLY(z2, FIX_1_451774981) { sqrt(2) * (c3+c7) }
  249. + MULTIPLY(z3, - FIX_2_172734803) { sqrt(2) * (-c1-c5) }
  250. + MULTIPLY(z4, FIX_1_061594337); { sqrt(2) * (c5+c7) }
  251. tmp2 := MULTIPLY(z1, - FIX_0_509795579) { sqrt(2) * (c7-c5) }
  252. + MULTIPLY(z2, - FIX_0_601344887) { sqrt(2) * (c5-c1) }
  253. + MULTIPLY(z3, FIX_0_899976223) { sqrt(2) * (c3-c7) }
  254. + MULTIPLY(z4, FIX_2_562915447); { sqrt(2) * (c1+c3) }
  255. { Final output stage }
  256. outptr^[0] := range_limit^[ int(DESCALE(tmp10 + tmp2,
  257. CONST_BITS+PASS1_BITS+3+1))
  258. and RANGE_MASK];
  259. outptr^[3] := range_limit^[ int(DESCALE(tmp10 - tmp2,
  260. CONST_BITS+PASS1_BITS+3+1))
  261. and RANGE_MASK];
  262. outptr^[1] := range_limit^[ int(DESCALE(tmp12 + tmp0,
  263. CONST_BITS+PASS1_BITS+3+1))
  264. and RANGE_MASK];
  265. outptr^[2] := range_limit^[ int(DESCALE(tmp12 - tmp0,
  266. CONST_BITS+PASS1_BITS+3+1))
  267. and RANGE_MASK];
  268. Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
  269. end;
  270. end;
  271. { Perform dequantization and inverse DCT on one block of coefficients,
  272. producing a reduced-size 2x2 output block. }
  273. {GLOBAL}
  274. procedure jpeg_idct_2x2 (cinfo : j_decompress_ptr;
  275. compptr : jpeg_component_info_ptr;
  276. coef_block : JCOEFPTR;
  277. output_buf : JSAMPARRAY;
  278. output_col : JDIMENSION);
  279. type
  280. PWorkspace = ^TWorkspace;
  281. TWorkspace = array[0..(DCTSIZE*2)-1] of int; { buffers data between passes }
  282. var
  283. tmp0, tmp10, z1 : INT32;
  284. inptr : JCOEFPTR;
  285. quantptr : ISLOW_MULT_TYPE_FIELD_PTR;
  286. wsptr : PWorkspace;
  287. outptr : JSAMPROW;
  288. range_limit : JSAMPROW;
  289. ctr : int;
  290. workspace : TWorkspace; { buffers data between passes }
  291. {SHIFT_TEMPS}
  292. var
  293. dcval : int;
  294. var
  295. dcval_ : JSAMPLE;
  296. begin
  297. { Each IDCT routine is responsible for range-limiting its results and
  298. converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
  299. be quite far out of range if the input data is corrupt, so a bulletproof
  300. range-limiting step is required. We use a mask-and-table-lookup method
  301. to do the combined operations quickly. See the comments with
  302. prepare_range_limit_table (in jdmaster.c) for more info. }
  303. range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
  304. { Pass 1: process columns from input, store into work array. }
  305. inptr := coef_block;
  306. quantptr := ISLOW_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
  307. wsptr := @workspace;
  308. for ctr := DCTSIZE downto 1 do
  309. begin
  310. { Don't bother to process columns 2,4,6 }
  311. if (ctr = DCTSIZE-2) or (ctr = DCTSIZE-4) or (ctr = DCTSIZE-6) then
  312. begin
  313. Inc(JCOEF_PTR(inptr));
  314. Inc(ISLOW_MULT_TYPE_PTR(quantptr));
  315. Inc(int_ptr(wsptr));
  316. continue;
  317. end;
  318. if (inptr^[DCTSIZE*1]=0) and (inptr^[DCTSIZE*3]=0) and
  319. (inptr^[DCTSIZE*5]=0) and (inptr^[DCTSIZE*7]=0) then
  320. begin
  321. { AC terms all zero; we need not examine terms 2,4,6 for 2x2 output }
  322. dcval := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) *
  323. quantptr^[DCTSIZE*0]) shl PASS1_BITS;
  324. wsptr^[DCTSIZE*0] := dcval;
  325. wsptr^[DCTSIZE*1] := dcval;
  326. Inc(JCOEF_PTR(inptr));
  327. Inc(ISLOW_MULT_TYPE_PTR(quantptr));
  328. Inc(int_ptr(wsptr));
  329. continue;
  330. end;
  331. { Even part }
  332. z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*0]) * quantptr^[DCTSIZE*0]);
  333. tmp10 := z1 shl (CONST_BITS+2);
  334. { Odd part }
  335. z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*7]) * quantptr^[DCTSIZE*7]);
  336. tmp0 := MULTIPLY(z1, - FIX_0_720959822); { sqrt(2) * (c7-c5+c3-c1) }
  337. z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*5]) * quantptr^[DCTSIZE*5]);
  338. Inc(tmp0, MULTIPLY(z1, FIX_0_850430095)); { sqrt(2) * (-c1+c3+c5+c7) }
  339. z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*3]) * quantptr^[DCTSIZE*3]);
  340. Inc(tmp0, MULTIPLY(z1, - FIX_1_272758580)); { sqrt(2) * (-c1+c3-c5-c7) }
  341. z1 := (ISLOW_MULT_TYPE(inptr^[DCTSIZE*1]) * quantptr^[DCTSIZE*1]);
  342. Inc(tmp0, MULTIPLY(z1, FIX_3_624509785)); { sqrt(2) * (c1+c3+c5+c7) }
  343. { Final output stage }
  344. wsptr^[DCTSIZE*0] := int (DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2));
  345. wsptr^[DCTSIZE*1] := int (DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2));
  346. Inc(JCOEF_PTR(inptr));
  347. Inc(ISLOW_MULT_TYPE_PTR(quantptr));
  348. Inc(int_ptr(wsptr));
  349. end;
  350. { Pass 2: process 2 rows from work array, store into output array. }
  351. wsptr := @workspace;
  352. for ctr := 0 to pred(2) do
  353. begin
  354. outptr := JSAMPROW(@ output_buf^[ctr]^[output_col]);
  355. { It's not clear whether a zero row test is worthwhile here ... }
  356. {$ifndef NO_ZERO_ROW_TEST}
  357. if (wsptr^[1]=0) and (wsptr^[3]=0) and (wsptr^[5]=0) and (wsptr^[7]= 0) then
  358. begin
  359. { AC terms all zero }
  360. dcval_ := range_limit^[ int(DESCALE(INT32(wsptr^[0]), PASS1_BITS+3))
  361. and RANGE_MASK];
  362. outptr^[0] := dcval_;
  363. outptr^[1] := dcval_;
  364. Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
  365. continue;
  366. end;
  367. {$endif}
  368. { Even part }
  369. tmp10 := (INT32 (wsptr^[0])) shl (CONST_BITS+2);
  370. { Odd part }
  371. tmp0 := MULTIPLY( INT32(wsptr^[7]), - FIX_0_720959822) { sqrt(2) * (c7-c5+c3-c1) }
  372. + MULTIPLY( INT32(wsptr^[5]), FIX_0_850430095) { sqrt(2) * (-c1+c3+c5+c7) }
  373. + MULTIPLY( INT32(wsptr^[3]), - FIX_1_272758580) { sqrt(2) * (-c1+c3-c5-c7) }
  374. + MULTIPLY( INT32(wsptr^[1]), FIX_3_624509785); { sqrt(2) * (c1+c3+c5+c7) }
  375. { Final output stage }
  376. outptr^[0] := range_limit^[ int(DESCALE(tmp10 + tmp0,
  377. CONST_BITS+PASS1_BITS+3+2))
  378. and RANGE_MASK];
  379. outptr^[1] := range_limit^[ int(DESCALE(tmp10 - tmp0,
  380. CONST_BITS+PASS1_BITS+3+2))
  381. and RANGE_MASK];
  382. Inc(int_ptr(wsptr), DCTSIZE); { advance pointer to next row }
  383. end;
  384. end;
  385. { Perform dequantization and inverse DCT on one block of coefficients,
  386. producing a reduced-size 1x1 output block. }
  387. {GLOBAL}
  388. procedure jpeg_idct_1x1 (cinfo : j_decompress_ptr;
  389. compptr : jpeg_component_info_ptr;
  390. coef_block : JCOEFPTR;
  391. output_buf : JSAMPARRAY;
  392. output_col : JDIMENSION);
  393. var
  394. dcval : int;
  395. quantptr : ISLOW_MULT_TYPE_FIELD_PTR;
  396. range_limit : JSAMPROW;
  397. {SHIFT_TEMPS}
  398. begin
  399. { Each IDCT routine is responsible for range-limiting its results and
  400. converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
  401. be quite far out of range if the input data is corrupt, so a bulletproof
  402. range-limiting step is required. We use a mask-and-table-lookup method
  403. to do the combined operations quickly. See the comments with
  404. prepare_range_limit_table (in jdmaster.c) for more info. }
  405. range_limit := JSAMPROW(@(cinfo^.sample_range_limit^[CENTERJSAMPLE]));
  406. { Pass 1: process columns from input, store into work array. }
  407. { We hardly need an inverse DCT routine for this: just take the
  408. average pixel value, which is one-eighth of the DC coefficient. }
  409. quantptr := ISLOW_MULT_TYPE_FIELD_PTR (compptr^.dct_table);
  410. dcval := (ISLOW_MULT_TYPE(coef_block^[0]) * quantptr^[0]);
  411. dcval := int (DESCALE( INT32(dcval), 3));
  412. output_buf^[0]^[output_col] := range_limit^[dcval and RANGE_MASK];
  413. end;
  414. end.