inp005.c 8.33 KB
#include <bstring.h>
#include <math.h>
#include <stdio.h>

#include "inp.h"

static void varyKeyValues(void);
static void passThrough(void);
static void boundaryValues(void);
static void checkCompareClamp(void);
static void monteCarlo(void);
static void initKeyMode(cc_t *);

int
main(int argc, char *argv[])
{
	printHeader();
	passThrough();
	varyKeyValues();
	boundaryValues();
	checkCompareClamp();
	monteCarlo();
	printTrailingCycles();
}

static void
passThrough(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i;

	printf("# Verify X (SUBA) inputs are passed through to pixel outputs\n");

	initKeyMode(ccp);

	printf("#  tf = (0x%x,0x%x,0x%x)\n", ccp->tf_r, ccp->tf_g, ccp->tf_b);
	printVector(ccp, 1);

	for (i = 0; i < 9; i++) {
		ccp->tf_b = 1 << i;
		printf("#  tf = (0x%x,0x%x,0x%x)\n",
			ccp->tf_r, ccp->tf_g, ccp->tf_b);
		printVector(ccp, 1);
	}
	ccp->tf_b = 0;

	for (i = 0; i < 9; i++) {
		ccp->tf_g = 1 << i;
		printf("#  tf = (0x%x,0x%x,0x%x)\n",
			ccp->tf_r, ccp->tf_g, ccp->tf_b);
		printVector(ccp, 1);
	}
	ccp->tf_g = 0;

	for (i = 0; i < 9; i++) {
		ccp->tf_r = 1 << i;
		printf("#  tf = (0x%x,0x%x,0x%x)\n",
			ccp->tf_r, ccp->tf_g, ccp->tf_b);
		printVector(ccp, 1);
	}
	ccp->tf_r = 0;
}

static void
varyKeyValues(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i;

	initKeyMode(ccp);

	ccp->tf_r = ccp->tf_g = ccp->tf_b = 0x0;
	ccp->center_r = ccp->center_g = ccp->center_b = 0x1;
	ccp->scale_r = ccp->scale_g = ccp->scale_b = 0x80;

	for (i = 0; i < 16; i++) {
		ccp->width_r = ccp->width_g = ccp->width_b = i;
		printVector(ccp, 1);
	}
}

static void
checkCompareClamp(void)
{
	cc_t cc;
	cc_t *ccp = &cc;

	initKeyMode(ccp);

	printf("# 0 on red, 1 on green, 1 on blue\n");

	ccp->tf_r = ccp->tf_g = ccp->tf_b = 0x0;
	ccp->width_r = ccp->width_g = ccp->width_b = 0x8;

	ccp->scale_r = 0x0;
	ccp->center_r = 0x0;

	ccp->scale_g = ccp->scale_b = 0xff;
	ccp->center_g = ccp->center_b = 0x01;

	printVector(ccp, 1);

	printf("# 1 on red, 0 on green, 1 on blue\n");

	ccp->scale_g = 0x0;
	ccp->center_g = 0x0;

	ccp->scale_r = ccp->scale_b = 0xff;
	ccp->center_r = ccp->center_b = 0x01;

	printVector(ccp, 1);

	printf("# 1 on red, 1 on green, 0 on blue\n");

	ccp->scale_b = 0x0;
	ccp->center_b = 0x0;

	ccp->scale_r = ccp->scale_g = 0xff;
	ccp->center_r = ccp->center_g = 0x01;

	printVector(ccp, 1);

	printf("# 1 on red, -1 on green, -1 on blue\n");

	ccp->tf_r = 0x0;
	ccp->scale_r = 0xff;
	ccp->center_r = 0x01;
	ccp->width_r = 0x8;

	ccp->tf_g = ccp->tf_b = 0xf;
	ccp->scale_g = ccp->scale_b = 0xff;
	ccp->center_g = ccp->center_b = 0x0;
	ccp->width_g = ccp->width_b = 0x1e7;

	printVector(ccp, 1);

	printf("# -1 on red, 1 on green, -1 on blue\n");

	ccp->tf_g = 0x0;
	ccp->scale_g = 0xff;
	ccp->center_g = 0x01;
	ccp->width_g = 0x8;

	ccp->tf_r = ccp->tf_b = 0xf;
	ccp->scale_r = ccp->scale_b = 0xff;
	ccp->center_r = ccp->center_b = 0x0;
	ccp->width_r = ccp->width_b = 0x1e7;

	printVector(ccp, 1);

	printf("# -1 on red, -1 on green, 1 on blue\n");

	ccp->tf_b = 0x0;
	ccp->scale_b = 0xff;
	ccp->center_b = 0x01;
	ccp->width_b = 0x8;

	ccp->tf_r = ccp->tf_g = 0xf;
	ccp->scale_r = ccp->scale_g = 0xff;
	ccp->center_r = ccp->center_g = 0x0;
	ccp->width_r = ccp->width_g = 0x1e7;

	printf("# 0xff on red, 0x100 on green, 0x100 on blue\n");

	ccp->tf_r = ccp->tf_g = ccp->tf_b = 0x0;
	ccp->center_r = ccp->center_g = ccp->center_b = 0x1;
	ccp->width_r = ccp->width_g = ccp->width_b = 0x10;

	ccp->scale_r = 0x7f;
	ccp->scale_g = 0x80;
	ccp->scale_b = 0x80;

	printVector(ccp, 1);

	printf("# 0x100 on red, 0xff on green, 0x100 on blue\n");

	ccp->scale_r = 0x80;
	ccp->scale_g = 0x7f;
	ccp->scale_b = 0x80;

	printVector(ccp, 1);

	printf("# 0x100 on red, 0x100 on green, 0xff on blue\n");

	ccp->scale_r = 0x80;
	ccp->scale_g = 0x80;
	ccp->scale_b = 0x7f;

	printVector(ccp, 1);

	printf("# 0x100 on red, 0x7ff0 on green, 0x7ff0 on blue\n");

	ccp->tf_r = ccp->tf_g = ccp->tf_b = 0x0;
	ccp->center_r = ccp->center_g = ccp->center_b = 0x1;
	ccp->scale_r = ccp->scale_g = ccp->scale_b = 0x80;

	ccp->width_r = 0x10;
	ccp->width_g = 0x7ff;
	ccp->width_b = 0x7ff;

	printVector(ccp, 1);

	printf("# 0x7ff0 on red, 0x100 on green, 0x7ff0 on blue\n");

	ccp->width_r = 0x7ff;
	ccp->width_g = 0x10;
	ccp->width_b = 0x7ff;

	printVector(ccp, 1);

	printf("# 0x7ff0 on red, 0x7ff0 on green, 0x100 on blue\n");

	ccp->width_r = 0x7ff;
	ccp->width_g = 0x7ff;
	ccp->width_b = 0x10;

	printVector(ccp, 1);

	printf("# 0x7ff0 on red, 0x7ff0 on green, 0x7ff0 on blue\n");

	ccp->width_r = 0x7ff;
	ccp->width_g = 0x7ff;
	ccp->width_b = 0x7ff;

	printVector(ccp, 1);
}

static void
boundaryValues(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i, j, k, l;
	static int tf_values[]     = {0x000, 0x001, 0x100, 0x101 };
	static int scale_values[]  = {0x00, 0x01, 0x80, 0x81 };
	static int center_values[] = {0x00, 0x01, 0x80, 0x81 };
	static int width_values[]  = {0x00, 0x01, 0x800, 0x801 };

	printf("# Boundary values\n");

	initKeyMode(ccp);

	for (i = 0; i < sizeof(tf_values)/sizeof(int); i++) {
	    ccp->tf_r = ccp->tf_g = ccp->tf_b = tf_values[i];
	    for (j = 0; j < sizeof(scale_values)/sizeof(int); j++) {
		ccp->scale_r = ccp->scale_g = ccp->scale_b = scale_values[j];
		for (k = 0; k < sizeof(center_values)/sizeof(int); k++) {
		    ccp->center_r = ccp->center_g = ccp->center_b =
			center_values[k];
		    for (l = 0; l < sizeof(width_values)/sizeof(int); l++) {
			ccp->width_r = ccp->width_g = ccp->width_b = 
				width_values[l];

			printf("#  tf 0x%x scale 0x%x center 0x%x width 0x%x\n",
				ccp->tf_r, ccp->scale_r,
				ccp->center_r, ccp->width_r);
			printVector(ccp, 1);
		    }
		}
	    }
	}
}

static void
monteCarlo(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i;

	printf("# Monte Carlo\n");

	srandom(1);

	initKeyMode(ccp);

	printf("# Vary r,g,b components separately\n");

	for (i = 0; i < 30; i++) {
		ccp->tf_r = random() & 0x1ff;
		ccp->tf_g = random() & 0x1ff;
		ccp->tf_b = random() & 0x1ff;
		ccp->scale_r = random() & 0xff;
		ccp->scale_g = random() & 0xff;
		ccp->scale_b = random() & 0xff;
		ccp->center_r = random() & 0xff;
		ccp->center_g = random() & 0xff;
		ccp->center_b = random() & 0xff;
		ccp->width_r = random() & 0xfff;
		ccp->width_g = random() & 0xfff;
		ccp->width_b = random() & 0xfff;

		printVector(ccp, 1);
	}

	printf("# Vary (r,g) and b components separately\n");

	for (i = 0; i < 30; i++) {
		ccp->tf_r = ccp->tf_g = random() & 0x1ff;
		ccp->tf_b = random() & 0x1ff;

		ccp->scale_r = ccp->scale_g = random() & 0xff;
		ccp->scale_b = random() & 0xff;

		ccp->center_r = ccp->center_g = random() & 0xff;
		ccp->center_b = random() & 0xff;

		ccp->width_r = ccp->width_g = random() & 0xfff;
		ccp->width_b = random() & 0xfff;

		printVector(ccp, 1);
	}

	printf("# Vary (r,b) and g components separately\n");

	for (i = 0; i < 30; i++) {
		ccp->tf_r = ccp->tf_b = random() & 0x1ff;
		ccp->tf_g = random() & 0x1ff;

		ccp->scale_r = ccp->scale_b = random() & 0xff;
		ccp->scale_g = random() & 0xff;

		ccp->center_r = ccp->center_b = random() & 0xff;
		ccp->center_g = random() & 0xff;

		ccp->width_r = ccp->width_b = random() & 0xfff;
		ccp->width_g = random() & 0xfff;

		printVector(ccp, 1);
	}

	printf("# Vary (g,b) and r components separately\n");

	for (i = 0; i < 30; i++) {
		ccp->tf_g = ccp->tf_b = random() & 0x1ff;
		ccp->tf_r = random() & 0x1ff;

		ccp->scale_g = ccp->scale_b = random() & 0xff;
		ccp->scale_r = random() & 0xff;

		ccp->center_g = ccp->center_b = random() & 0xff;
		ccp->center_r = random() & 0xff;

		ccp->width_g = ccp->width_b = random() & 0xfff;
		ccp->width_r = random() & 0xfff;

		printVector(ccp, 1);
	}

	printf("# Vary r,g,b components together\n");

	for (i = 0; i < 30; i++) {
		ccp->tf_r = ccp->tf_g = ccp->tf_b = random() & 0x1ff;
		ccp->scale_r = ccp->scale_g = ccp->scale_b = random() & 0xff;
		ccp->center_r = ccp->center_g = ccp->center_b = random() & 0xff;
		ccp->width_r = ccp->width_g = ccp->width_b = random() & 0xfff;

		printVector(ccp, 1);
	}
}

static void
initKeyMode(cc_t *ccp)
{
	bzero(ccp, sizeof(*ccp));

	ccp->ncyc = 0;		/* single cycle mode */
	ccp->key_en = 1;	/* enable keying */

	/* Initialize color selects to (texel 1, center, scale, texel 1) */

	ccp->cc_x_sel_1_r = CC_SUBA_TEX_1;
	ccp->cc_y_sel_1_r = CC_SUBB_CENTER;
	ccp->cc_a_sel_1_r = CC_MULT_SCALE;
	ccp->cc_c_sel_1_r = CC_ADD_TEX_1;

	/* Initialize alpha selects to (0,0,0,0) */

	ccp->cc_x_sel_1_a = CC_SUBA_ZERO_ALPHA;
	ccp->cc_y_sel_1_a = CC_SUBB_ZERO_ALPHA;
	ccp->cc_a_sel_1_a = CC_MULT_ZERO_ALPHA;
	ccp->cc_c_sel_1_a = CC_ADD_ZERO_ALPHA;
}