-/* DCT test. (c) 2001 Fabrice Bellard.
- Started from sample code by Juan J. Sierralta P.
-*/
+/**
+ * @file dct-test.c
+ * DCT test. (c) 2001 Fabrice Bellard.
+ * Started from sample code by Juan J. Sierralta P.
+ */
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
-#include <getopt.h>
#include "dsputil.h"
#include "i386/mmx.h"
#include "simple_idct.h"
+#ifndef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
/* reference fdct/idct */
extern void fdct(DCTELEM *block);
extern void idct(DCTELEM *block);
extern void odivx_idct_c (short *block);
-void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/,
- UINT8 *pixels/*align 8*/, int line_size);
-
-void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/,
- UINT8 *pixels/*align 8*/, int line_size);
-
#define AANSCALE_BITS 12
static const unsigned short aanscales[64] = {
/* precomputed values scaled up by 14 bits */
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
};
-UINT8 cropTbl[256 + 2 * MAX_NEG_CROP];
+uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
-INT64 gettime(void)
+int64_t gettime(void)
{
struct timeval tv;
gettimeofday(&tv,NULL);
- return (INT64)tv.tv_sec * 1000000 + tv.tv_usec;
+ return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
}
#define NB_ITS 20000
{
int it, i, scale;
int err_inf, v;
- INT64 err2, ti, ti1, it1;
- INT64 sysErr[64], sysErrMax=0;
+ int64_t err2, ti, ti1, it1;
+ int64_t sysErr[64], sysErrMax=0;
int maxout=0;
int blockSumErrMax=0, blockSumErr;
#endif
}
-static UINT8 img_dest[64] __attribute__ ((aligned (8)));
-static UINT8 img_dest1[64] __attribute__ ((aligned (8)));
+static uint8_t img_dest[64] __attribute__ ((aligned (8)));
+static uint8_t img_dest1[64] __attribute__ ((aligned (8)));
-void idct248_ref(UINT8 *dest, int linesize, INT16 *block)
+void idct248_ref(uint8_t *dest, int linesize, int16_t *block)
{
static int init;
static double c8[8][8];
}
/* butterfly */
+ s = 0.5 * sqrt(2.0);
for(i=0;i<4;i++) {
for(j=0;j<8;j++) {
- block1[8*(2*i)+j] = (block[8*(2*i)+j] + block[8*(2*i+1)+j]) * 0.5;
- block1[8*(2*i+1)+j] = (block[8*(2*i)+j] - block[8*(2*i+1)+j]) * 0.5;
+ block1[8*(2*i)+j] = (block[8*(2*i)+j] + block[8*(2*i+1)+j]) * s;
+ block1[8*(2*i+1)+j] = (block[8*(2*i)+j] - block[8*(2*i+1)+j]) * s;
}
}
/* clamp and store the result */
for(i=0;i<8;i++) {
for(j=0;j<8;j++) {
- v = block3[8*i+j] + 128.0;
+ v = block3[8*i+j];
if (v < 0)
v = 0;
else if (v > 255)
}
void idct248_error(const char *name,
- void (*idct248_put)(UINT8 *dest, int line_size, INT16 *block))
+ void (*idct248_put)(uint8_t *dest, int line_size, int16_t *block))
{
int it, i, it1, ti, ti1, err_max, v;
important here) */
err_max = 0;
for(it=0;it<NB_ITS;it++) {
- for(i=0;i<64;i++)
- block1[i] = (random() % 512) - 256;
+ /* XXX: use forward transform to generate values */
+ for(i=0;i<64;i++)
+ block1[i] = (random() % 256) - 128;
+ block1[0] += 1024;
+
for(i=0; i<64; i++)
block[i]= block1[i];
idct248_ref(img_dest1, 8, block);
+ for(i=0; i<64; i++)
+ block[i]= block1[i];
+ idct248_put(img_dest, 8, block);
+
+ for(i=0;i<64;i++) {
+ v = abs((int)img_dest[i] - (int)img_dest1[i]);
+ if (v == 255)
+ printf("%d %d\n", img_dest[i], img_dest1[i]);
+ if (v > err_max)
+ err_max = v;
+ }
#if 0
printf("ref=\n");
for(i=0;i<8;i++) {
}
printf("\n");
}
-#endif
- for(i=0; i<64; i++)
- block[i]= block1[i];
- idct248_put(img_dest, 8, block);
-
-#if 0
printf("out=\n");
for(i=0;i<8;i++) {
int j;
printf("\n");
}
#endif
- for(i=0;i<64;i++) {
- v = abs(img_dest[i] - img_dest1[i]);
- if (v > err_max)
- err_max = v;
- }
}
printf("%s %s: err_inf=%d\n",
1 ? "IDCT248" : "DCT248",