pffst.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 13k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. /***************************************************************************
  2. *
  3. *                INTEL Corporation Proprietary Information  
  4. *
  5. *      
  6. *                  Copyright (c) 1996 Intel Corporation.
  7. *                         All rights reserved.
  8. *
  9. ***************************************************************************
  10. */
  11. /*
  12.  * jfdctfst.c
  13.  *
  14.  * Copyright (C) 1994-1996, Thomas G. Lane.
  15.  * This file is part of the Independent JPEG Group's software.
  16.  * For conditions of distribution and use, see the accompanying README file.
  17.  *
  18.  * This file contains a fast, not so accurate integer implementation of the
  19.  * forward DCT (Discrete Cosine Transform).
  20.  *
  21.  * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
  22.  * on each column.  Direct algorithms are also available, but they are
  23.  * much more complex and seem not to be any faster when reduced to code.
  24.  *
  25.  * This implementation is based on Arai, Agui, and Nakajima's algorithm for
  26.  * scaled DCT.  Their original paper (Trans. IEICE E-71(11):1095) is in
  27.  * Japanese, but the algorithm is described in the Pennebaker & Mitchell
  28.  * JPEG textbook (see REFERENCES section in file README).  The following code
  29.  * is based directly on figure 4-8 in P&M.
  30.  * While an 8-point DCT cannot be done in less than 11 multiplies, it is
  31.  * possible to arrange the computation so that many of the multiplies are
  32.  * simple scalings of the final outputs.  These multiplies can then be
  33.  * folded into the multiplications or divisions by the JPEG quantization
  34.  * table entries.  The AA&N method leaves only 5 multiplies and 29 adds
  35.  * to be done in the DCT itself.
  36.  * The primary disadvantage of this method is that with fixed-point math,
  37.  * accuracy is lost due to imprecise representation of the scaled
  38.  * quantization values.  The smaller the quantization table entry, the less
  39.  * precise the scaled value, so this implementation does worse with high-
  40.  * quality-setting files than with low-quality ones.
  41.  */
  42. #define JPEG_INTERNALS
  43. #include "jinclude.h"
  44. #include "jpeglib.h"
  45. #include "jdct.h" /* Private declarations for DCT subsystem */
  46. #ifdef DCT_IFAST_SUPPORTED
  47. /*
  48.  * This module is specialized to the case DCTSIZE = 8.
  49.  */
  50. #if DCTSIZE != 8
  51.   Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  52. #endif
  53. /* Scaling decisions are generally the same as in the LL&M algorithm;
  54.  * see jfdctint.c for more details.  However, we choose to descale
  55.  * (right shift) multiplication products as soon as they are formed,
  56.  * rather than carrying additional fractional bits into subsequent additions.
  57.  * This compromises accuracy slightly, but it lets us save a few shifts.
  58.  * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
  59.  * everywhere except in the multiplications proper; this saves a good deal
  60.  * of work on 16-bit-int machines.
  61.  *
  62.  * Again to save a few shifts, the intermediate results between pass 1 and
  63.  * pass 2 are not upscaled, but are represented only to integral precision.
  64.  *
  65.  * A final compromise is to represent the multiplicative constants to only
  66.  * 8 fractional bits, rather than 13.  This saves some shifting work on some
  67.  * machines, and may also reduce the cost of multiplication (since there
  68.  * are fewer one-bits in the constants).
  69.  */
  70. #define CONST_BITS  8
  71. /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
  72.  * causing a lot of useless floating-point operations at run time.
  73.  * To get around this we use the following pre-calculated constants.
  74.  * If you change CONST_BITS you may want to add appropriate values.
  75.  * (With a reasonable C compiler, you can just rely on the FIX() macro...)
  76.  */
  77. #if CONST_BITS == 8
  78. #define FIX_0_382683433  98 /* FIX(0.382683433) */
  79. #define FIX_0_541196100 139 /* FIX(0.541196100) */
  80. #define FIX_0_707106781 181 /* FIX(0.707106781) */
  81. #define FIX_1_306562965 334 /* FIX(1.306562965) */
  82. #else
  83. #define FIX_0_382683433  FIX(0.382683433)
  84. #define FIX_0_541196100  FIX(0.541196100)
  85. #define FIX_0_707106781  FIX(0.707106781)
  86. #define FIX_1_306562965  FIX(1.306562965)
  87. #endif
  88. /* We can gain a little more speed, with a further compromise in accuracy,
  89.  * by omitting the addition in a descaling shift.  This yields an incorrectly
  90.  * rounded result half the time...
  91.  */
  92. // The assembly version makes this compromise.
  93.  
  94. //#ifndef USE_ACCURATE_ROUNDING
  95. //#undef DESCALE
  96. //#define DESCALE(x,n)  RIGHT_SHIFT(x, n)
  97. //#endif
  98. #define DCTWIDTH 32
  99. #define DATASIZE 4
  100. /* Multiply a DCTELEM variable by an INT32 constant, and immediately
  101.  * descale to yield a DCTELEM result.
  102.  */
  103. #define MULTIPLY(var,const)  ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  104. /*
  105.  * Perform the forward DCT on one block of samples.
  106.  */
  107. GLOBAL(void)
  108. pfdct8x8aan (DCTELEM * data)
  109. {
  110.   DCTELEM tmp4, tmp6, tmp7;
  111.   int counter;
  112.   __asm{
  113.  
  114.   /* Pass 1: process rows. */
  115. //  dataptr = data;
  116. mov  esi, [data]
  117. mov counter, 8
  118. //  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  119. //   tmp0 = dataptr[0] + dataptr[7];
  120. //   tmp7 = dataptr[0] - dataptr[7];
  121. //    tmp1 = dataptr[1] + dataptr[6];
  122. //    tmp6 = dataptr[1] - dataptr[6];
  123. //    tmp2 = dataptr[2] + dataptr[5];
  124. //    tmp5 = dataptr[2] - dataptr[5];
  125. //    tmp3 = dataptr[3] + dataptr[4];
  126. //    tmp4 = dataptr[3] - dataptr[4];
  127.     
  128.  StartRow:
  129.   mov eax, [esi][DATASIZE*0]
  130.   mov ebx, [esi][DATASIZE*7]
  131.  
  132.   mov edx, eax
  133.   add eax, ebx ; eax = tmp0
  134.  
  135.   sub edx, ebx ; edx = tmp7
  136.    mov ebx, [esi][DATASIZE*3]
  137.  
  138.   mov ecx, [esi][DATASIZE*4]
  139.   mov edi, ebx
  140.  
  141.   add ebx, ecx ; ebx = tmp3
  142.   sub edi, ecx ; edi = tmp4
  143.  
  144.   mov tmp4, edi
  145.   mov tmp7, edx
  146.  
  147.     /* Even part */
  148.     
  149. //    tmp10 = tmp0 + tmp3;
  150. //    tmp13 = tmp0 - tmp3;
  151. //    tmp11 = tmp1 + tmp2;
  152. //    tmp12 = tmp1 - tmp2;
  153.     
  154. mov ecx, eax
  155. add eax, ebx ; eax = tmp10
  156. sub ecx, ebx ; ecx = tmp13
  157.    mov edx, [esi][DATASIZE*1] 
  158.   
  159.    mov edi, [esi][DATASIZE*6]
  160.    mov ebx, edx
  161.   
  162.    add edx, edi ; edx = tmp1
  163.    sub ebx, edi ; ebx = tmp6
  164.   
  165.    mov tmp6, ebx
  166.    push ebp
  167.   
  168.    mov edi, [esi][DATASIZE*2]
  169.    mov ebp, [esi][DATASIZE*5]
  170.    mov ebx, edi
  171.    add edi, ebp ; edi = tmp2
  172.   
  173.    sub ebx, ebp ; ebx = tmp5
  174.    mov ebp, edx
  175.   
  176.    add edx, edi ; edx = tmp11
  177.    sub ebp, edi ; ebp = tmp12
  178.   
  179. //    dataptr[0] = tmp10 + tmp11; /* phase 3 */
  180. //    dataptr[4] = tmp10 - tmp11;
  181.     
  182. mov edi, eax
  183. add eax, edx ; eax = tmp10 + tmp11
  184. sub edi, edx ; edi = tmp10 - tmp11
  185. add ebp, ecx ; ebp = tmp12 + tmp13
  186. //    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  187. imul ebp, FIX_0_707106781 ; ebp = z1
  188. sar ebp, 8
  189. mov [esi][DATASIZE*0], eax
  190. //    dataptr[2] = tmp13 + z1; /* phase 5 */
  191. //    dataptr[6] = tmp13 - z1;
  192. mov eax, ecx
  193. add ecx, ebp
  194. sub eax, ebp
  195. pop ebp
  196. mov [esi][DATASIZE*4], edi
  197. mov [esi][DATASIZE*2], ecx
  198. mov [esi][DATASIZE*6], eax
  199. mov edi, tmp4
  200.     /* Odd part */
  201.     
  202. //    tmp10 = tmp4 + tmp5; /* phase 2 */
  203. //    tmp11 = tmp5 + tmp6;
  204. //    tmp12 = tmp6 + tmp7;
  205. mov ecx, tmp6
  206. mov edx, tmp7
  207. add edi, ebx ; edi = tmp10
  208. add ebx, ecx ; ebx = tmp11
  209. //    z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  210. //    z11 = tmp7 + z3; /* phase 5 */
  211. //    z13 = tmp7 - z3;
  212. imul ebx, FIX_0_707106781 ; ebx = z3
  213. sar ebx, 8
  214. add ecx, edx ; ecx = tmp12
  215. mov eax, edx
  216. add edx, ebx ; edx = z11
  217. sub eax, ebx ; eax = z13
  218. mov ebx, edi
  219.     /* The rotator is modified from fig 4-8 to avoid extra negations. */
  220. //    z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  221. //    z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  222. //    z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  223. imul ebx, FIX_0_541196100
  224. sar ebx, 8
  225. sub edi, ecx ; edi = tmp10 - tmp12
  226. imul edi, FIX_0_382683433 ; edi = z5
  227. sar edi, 8
  228. add esi, 32
  229. imul ecx, FIX_1_306562965
  230. sar ecx, 8
  231. add ebx, edi ; ebx = z2
  232. add ecx, edi ; ecx = z4
  233. mov edi, eax
  234. //    dataptr[5] = z13 + z2; /* phase 6 */
  235. //    dataptr[3] = z13 - z2;
  236. //    dataptr[1] = z11 + z4;
  237. //    dataptr[7] = z11 - z4;
  238. add eax, ebx ; eax = z13 + z2
  239. sub edi, ebx ; edi = z13 - z2
  240. mov [esi][DATASIZE*5-32], eax
  241. mov ebx, edx
  242. mov [esi][DATASIZE*3-32], edi
  243. add edx, ecx ; edx = z11 + z4
  244. mov [esi][DATASIZE*1-32], edx
  245. sub ebx, ecx ; ebx = z11 - z4
  246. mov ecx, counter
  247. mov [esi][DATASIZE*7-32], ebx
  248. dec ecx
  249. mov counter, ecx
  250. jnz StartRow
  251.     
  252. //    dataptr += DCTSIZE; /* advance pointer to next row */
  253. //  }
  254.   
  255.   
  256.   
  257.   /* Pass 2: process columns.*/
  258. //  dataptr = data;
  259. mov  esi, [data]
  260. mov counter, 8
  261. //  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  262. //    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  263. //    tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  264. //    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  265. //    tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  266. //    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  267. //    tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  268. //    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  269. //    tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  270.     
  271.  StartCol:
  272.   mov eax, [esi][DCTWIDTH*0]
  273.   mov ebx, [esi][DCTWIDTH*7]
  274.  
  275.   mov edx, eax
  276.   add eax, ebx ; eax = tmp0
  277.  
  278.   sub edx, ebx ; edx = tmp7
  279.    mov ebx, [esi][DCTWIDTH*3]
  280.  
  281.   mov ecx, [esi][DCTWIDTH*4]
  282.   mov edi, ebx
  283.  
  284.   add ebx, ecx ; ebx = tmp3
  285.   sub edi, ecx ; edi = tmp4
  286.  
  287.   mov tmp4, edi
  288.   mov tmp7, edx
  289.  
  290.     /* Even part */
  291.     
  292. //    tmp10 = tmp0 + tmp3;
  293. //    tmp13 = tmp0 - tmp3;
  294. //    tmp11 = tmp1 + tmp2;
  295. //    tmp12 = tmp1 - tmp2;
  296.     
  297. mov ecx, eax
  298. add eax, ebx ; eax = tmp10
  299. sub ecx, ebx ; ecx = tmp13
  300.    mov edx, [esi][DCTWIDTH*1] 
  301.   
  302.    mov edi, [esi][DCTWIDTH*6]
  303.    mov ebx, edx
  304.   
  305.    add edx, edi ; edx = tmp1
  306.    sub ebx, edi ; ebx = tmp6
  307.   
  308.    mov tmp6, ebx
  309.    push ebp
  310.   
  311.    mov edi, [esi][DCTWIDTH*2]
  312.    mov ebp, [esi][DCTWIDTH*5]
  313.    mov ebx, edi
  314.    add edi, ebp ; edi = tmp2
  315.   
  316.    sub ebx, ebp ; ebx = tmp5
  317.    mov ebp, edx
  318.   
  319.    add edx, edi ; edx = tmp11
  320.    sub ebp, edi ; ebp = tmp12
  321.   
  322. //    dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  323. //    dataptr[DCTSIZE*4] = tmp10 - tmp11;
  324.     
  325. mov edi, eax
  326. add eax, edx ; eax = tmp10 + tmp11
  327. sub edi, edx ; edi = tmp10 - tmp11
  328. add ebp, ecx ; ebp = tmp12 + tmp13
  329. //    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  330. imul ebp, FIX_0_707106781 ; ebp = z1
  331. sar ebp, 8
  332. mov [esi][DCTWIDTH*0], eax
  333. //    dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  334. //    dataptr[DCTSIZE*6] = tmp13 - z1;
  335. mov eax, ecx
  336. add ecx, ebp
  337. sub eax, ebp
  338. pop ebp
  339. mov [esi][DCTWIDTH*4], edi
  340. mov [esi][DCTWIDTH*2], ecx
  341. mov [esi][DCTWIDTH*6], eax
  342. mov edi, tmp4
  343.     /* Odd part */
  344.     
  345. //    tmp10 = tmp4 + tmp5; /* phase 2 */
  346. //    tmp11 = tmp5 + tmp6;
  347. //    tmp12 = tmp6 + tmp7;
  348. mov ecx, tmp6
  349. mov edx, tmp7
  350. add edi, ebx ; edi = tmp10
  351. add ebx, ecx ; ebx = tmp11
  352. //    z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  353. //    z11 = tmp7 + z3; /* phase 5 */
  354. //    z13 = tmp7 - z3;
  355. imul ebx, FIX_0_707106781 ; ebx = z3
  356. sar ebx, 8
  357. add ecx, edx ; ecx = tmp12
  358. mov eax, edx
  359. add edx, ebx ; edx = z11
  360. sub eax, ebx ; eax = z13
  361. mov ebx, edi
  362.     /* The rotator is modified from fig 4-8 to avoid extra negations. */
  363. //    z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  364. //    z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  365. //    z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  366. imul ebx, FIX_0_541196100
  367. sar ebx, 8
  368. sub edi, ecx ; edi = tmp10 - tmp12
  369. imul edi, FIX_0_382683433 ; edi = z5
  370. sar edi, 8
  371. add esi, 4
  372. imul ecx, FIX_1_306562965
  373. sar ecx, 8
  374. add ebx, edi ; ebx = z2
  375. add ecx, edi ; ecx = z4
  376. mov edi, eax
  377. //    dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  378. //    dataptr[DCTSIZE*3] = z13 - z2;
  379. //    dataptr[DCTSIZE*1] = z11 + z4;
  380. //    dataptr[DCTSIZE*7] = z11 - z4;
  381. add eax, ebx ; eax = z13 + z2
  382. sub edi, ebx ; edi = z13 - z2
  383. mov [esi][DCTWIDTH*5-4], eax
  384. mov ebx, edx
  385. mov [esi][DCTWIDTH*3-4], edi
  386. add edx, ecx ; edx = z11 + z4
  387. mov [esi][DCTWIDTH*1-4], edx
  388. sub ebx, ecx ; ebx = z11 - z4
  389. mov ecx, counter
  390. mov [esi][DCTWIDTH*7-4], ebx
  391. dec ecx
  392. mov counter, ecx
  393. jnz StartCol
  394.   } //end asm
  395. //    dataptr++; /* advance pointer to next column */
  396. //  }
  397. }
  398. #endif /* DCT_ISLOW_SUPPORTED */