Blame tests/runcheck.c

Packit c948fe
/*
Packit c948fe
 *  Copyright (C) 2004 Steve Harris
Packit c948fe
 *
Packit c948fe
 *  This program is free software; you can redistribute it and/or modify
Packit c948fe
 *  it under the terms of the GNU General Public License as published by
Packit c948fe
 *  the Free Software Foundation; either version 2 of the License, or
Packit c948fe
 *  (at your option) any later version.
Packit c948fe
 *
Packit c948fe
 *  This program is distributed in the hope that it will be useful,
Packit c948fe
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c948fe
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit c948fe
 *  GNU General Public License for more details.
Packit c948fe
 *
Packit c948fe
 *  $Id: runcheck.c $
Packit c948fe
 */
Packit c948fe
Packit c948fe
#include <stdio.h>
Packit c948fe
#include <stdint.h>
Packit c948fe
#include <stdlib.h>
Packit c948fe
#include <assert.h>
Packit c948fe
#include <math.h>
Packit c948fe
Packit c948fe
#define SIZE 1024
Packit c948fe
Packit c948fe
#include "gdither.h"
Packit c948fe
#include "compare.h"
Packit c948fe
#include "gettime.h"
Packit c948fe
Packit c948fe
inline static float noise()
Packit c948fe
{
Packit c948fe
    static unsigned long rnd = 23232323;
Packit c948fe
    rnd = (rnd * 196314165) + 907633515;
Packit c948fe
Packit c948fe
    return rnd * 2.3283064365387e-10f;
Packit c948fe
}
Packit c948fe
Packit c948fe
int main(int argc, char *argv[])
Packit c948fe
{
Packit c948fe
    GDither ds;
Packit c948fe
    float in[SIZE];
Packit c948fe
    double ind[SIZE];
Packit c948fe
    int32_t out32[SIZE];
Packit c948fe
    int16_t out16[SIZE];
Packit c948fe
    float outf[SIZE];
Packit c948fe
    int i;
Packit c948fe
Packit c948fe
    for (i=0; i
Packit c948fe
	in[i] = ((i % 20) - 10) * 0.2f;
Packit c948fe
    }
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherNone, 1, GDither32bit, 24);
Packit c948fe
    if (!ds) {
Packit c948fe
	fprintf(stderr, "counld not get gdither object for 24 in 32 dither\n");
Packit c948fe
	fprintf(stderr, "failing\n");
Packit c948fe
	exit(1);
Packit c948fe
    }
Packit c948fe
Packit c948fe
    gdither_runf(ds, 0, SIZE, in, out32);
Packit c948fe
#if SIZE == 1024
Packit c948fe
    for (i=0; i
Packit c948fe
	if (out32[i] != compare[i]) {
Packit c948fe
	    fprintf(stderr, "result comparison failed, index %d\n   %d != %d\n",
Packit c948fe
		    i, out32[i], compare[i]);
Packit c948fe
	}
Packit c948fe
    }
Packit c948fe
#endif
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherNone, 1, GDitherFloat, 8);
Packit c948fe
    for (i=0; i
Packit c948fe
	in[i] = noise() - 0.5f;
Packit c948fe
	ind[i] = in[i];
Packit c948fe
    }
Packit c948fe
    gdither_runf(ds, 0, SIZE, in, outf);
Packit c948fe
    for (i=0; i
Packit c948fe
	if (outf[i] * 128.0f - nearbyintf(outf[i] * 128.0f) > 0.00001f) {
Packit c948fe
	    fprintf(stderr, "bad float rounding: %d\t%f\n", i,
Packit c948fe
		    outf[i] * 128.0f);
Packit c948fe
	    fprintf(stderr, "failing\n");
Packit c948fe
	    exit(1);
Packit c948fe
	}
Packit c948fe
    }
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    /* Warm up the buffers and so on */
Packit c948fe
    ds = gdither_new(GDitherNone, 1, 23, 0);
Packit c948fe
    gdither_runf(ds, 0, SIZE, in, out32);
Packit c948fe
Packit c948fe
    TIME("baseline 24 in 32 test, 1024 samples",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out32));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    printf("\nOptimised:\n");
Packit c948fe
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherNone, 1, GDither32bit, 24);
Packit c948fe
    TIME("GDitherNone, 1024 samples, 24 in 32bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out32));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherRect, 1, GDither32bit, 24);
Packit c948fe
    TIME("GDitherRect, 1024 samples, 24 in 32bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out32));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherTri, 1, GDither32bit, 24);
Packit c948fe
    TIME("GDitherTri, 1024 samples, 24 in 32bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out32));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherShaped, 1, GDither32bit, 24);
Packit c948fe
    TIME("GDitherShaped, 1024 samples, 24 in 32bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out32));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    printf("\n");
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherNone, 1, GDither16bit, 0);
Packit c948fe
    TIME("GDitherNone, 1024 samples, 16bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out16));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherRect, 1, GDither16bit, 0);
Packit c948fe
    TIME("GDitherRect, 1024 samples, 16bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out16));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherTri, 1, GDither16bit, 0);
Packit c948fe
    TIME("GDitherTri, 1024 samples, 16bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out16));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherShaped, 1, GDither16bit, 0);
Packit c948fe
    TIME("GDitherShaped, 1024 samples, 16bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out16));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    printf("\nUnoptimised:\n");
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherNone, 1, GDither32bit, 20);
Packit c948fe
    TIME("GDitherNone, 1024 samples, 20 in 32bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out32));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherRect, 1, GDither32bit, 20);
Packit c948fe
    TIME("GDitherRect, 1024 samples, 20 in 32bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out32));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherTri, 1, GDither32bit, 20);
Packit c948fe
    TIME("GDitherTri, 1024 samples, 20 in 32bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out32));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherShaped, 1, GDither32bit, 20);
Packit c948fe
    TIME("GDitherShaped, 1024 samples, 20 in 32bit",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, out32));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    printf("\n");
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherNone, 1, GDitherFloat, 20);
Packit c948fe
    TIME("GDitherNone, 1024 samples, 24 in float",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, outf));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherRect, 1, GDitherFloat, 20);
Packit c948fe
    TIME("GDitherRect, 1024 samples, 24 in float",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, outf));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherTri, 1, GDitherFloat, 20);
Packit c948fe
    TIME("GDitherTri, 1024 samples, 24 in float",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, outf));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherShaped, 1, GDitherFloat, 20);
Packit c948fe
    TIME("GDitherShaped, 1024 samples, 24 in float",
Packit c948fe
         gdither_runf(ds, 0, SIZE, in, outf));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    printf("\n");
Packit c948fe
Packit c948fe
    ds = gdither_new(GDitherTri, 1, GDitherFloat, 20);
Packit c948fe
    TIME("GDitherTri, 1024 samples, 24 in float, double input",
Packit c948fe
         gdither_run(ds, 0, SIZE, ind, outf));
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    return 0;
Packit c948fe
}
Packit c948fe
Packit c948fe
/* vi:set ts=8 sts=4 sw=4: */