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.

106 lines
2.6KB

  1. /* DCT test. (c) 2001 Gerard Lantau.
  2. Started from sample code by Juan J. Sierralta P.
  3. */
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <sys/time.h>
  8. #include <unistd.h>
  9. #include "dsputil.h"
  10. extern void fdct(DCTELEM *block);
  11. extern void init_fdct();
  12. #define AANSCALE_BITS 12
  13. static const unsigned short aanscales[64] = {
  14. /* precomputed values scaled up by 14 bits */
  15. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  16. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  17. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  18. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  19. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  20. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  21. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  22. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  23. };
  24. INT64 gettime(void)
  25. {
  26. struct timeval tv;
  27. gettimeofday(&tv,NULL);
  28. return (INT64)tv.tv_sec * 1000000 + tv.tv_usec;
  29. }
  30. #define NB_ITS 20000
  31. #define NB_ITS_SPEED 50000
  32. void dct_error(const char *name,
  33. void (*fdct_func)(DCTELEM *block))
  34. {
  35. int it, i, scale;
  36. DCTELEM block[64], block1[64];
  37. int err_inf, v;
  38. INT64 err2, ti, ti1, it1;
  39. srandom(0);
  40. err_inf = 0;
  41. err2 = 0;
  42. for(it=0;it<NB_ITS;it++) {
  43. for(i=0;i<64;i++)
  44. block1[i] = random() % 256;
  45. memcpy(block, block1, sizeof(DCTELEM) * 64);
  46. fdct_func(block);
  47. if (fdct_func == jpeg_fdct_ifast) {
  48. for(i=0; i<64; i++) {
  49. scale = (1 << (AANSCALE_BITS + 11)) / aanscales[i];
  50. block[i] = (block[i] * scale) >> AANSCALE_BITS;
  51. }
  52. }
  53. fdct(block1);
  54. for(i=0;i<64;i++) {
  55. v = abs(block[i] - block1[i]);
  56. if (v > err_inf)
  57. err_inf = v;
  58. err2 += v * v;
  59. }
  60. }
  61. printf("DCT %s: err_inf=%d err2=%0.2f\n",
  62. name, err_inf, (double)err2 / NB_ITS / 64.0);
  63. /* speed test */
  64. for(i=0;i<64;i++)
  65. block1[i] = 255 - 63 + i;
  66. ti = gettime();
  67. it1 = 0;
  68. do {
  69. for(it=0;it<NB_ITS_SPEED;it++) {
  70. memcpy(block, block1, sizeof(DCTELEM) * 64);
  71. fdct_func(block);
  72. }
  73. it1 += NB_ITS_SPEED;
  74. ti1 = gettime() - ti;
  75. } while (ti1 < 1000000);
  76. printf("DCT %s: %0.1f kdct/s\n",
  77. name, (double)it1 * 1000.0 / (double)ti1);
  78. }
  79. int main(int argc, char **argv)
  80. {
  81. init_fdct();
  82. printf("ffmpeg DCT test\n");
  83. dct_error("REF", fdct); /* only to verify code ! */
  84. dct_error("AAN", jpeg_fdct_ifast);
  85. dct_error("MMX", fdct_mmx);
  86. return 0;
  87. }