[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Double hires mode color artifacts



Dirk Thierbach wrote:

> I've tried to do the Fourier projection myself, but I arrive at different
> values. Do you assume any phase shift between the square waves of the
> bit pattern and the sine/cosine base functions?

Maybe it's the most simple solution if I just post my code. I wrote this
a good while ago so I'm a bit foggy about the details.

--cut here--

#include <stdio.h>
#include <math.h>

static double angle[16];
static double satur[16];

static double y[16];
static double cb[16];
static double cr[16];

static double r[16];
static double g[16];
static double b[16];

int main(void)
{
    int i, j;
    double s2;
    double pi;
	
    s2 = sqrt(0.5);
    pi = atan(1.0) * 4.0;

    angle [0] =  0; angle [5] =   0; angle[10] =   0; angle[15] =   0;
    angle [1] = 90; angle [2] =   0; angle [4] = 270; angle [8] = 180;
    angle[11] = 90; angle [7] =   0; angle[14] = 270; angle[13] = 180;
    angle [3] = 45; angle [6] = 315; angle[12] = 225; angle [9] = 135;

    for (i = 0; i < 16; i++) {
        angle[i] *= (pi / 180.0);
    }

    satur [0] =  0; satur [5] =  0; satur[10] =  0; satur[15] =  0;
    satur [3] =  1; satur [6] =  1; satur [9] =  1; satur[12] =  1;
    satur [1] = s2; satur [2] = s2; satur [4] = s2; satur [8] = s2;
    satur[11] = s2; satur [7] = s2; satur[14] = s2; satur[13] = s2;

    for (i = 0; i < 16; i++) {
        satur[i] /= (pi / 2);
    }

    for (i = 0; i < 16; i++) {
	y[i] = 0;
        for (j = 0; j < 4; j++) {
            if (i & (1 << j)) y[i] += 0.25;
        }
    }

    for (i = 0; i < 16; i++) {
        cb[i] = satur[i] * cos(angle[i]) / 2.0 + 0.5;
        cr[i] = satur[i] * sin(angle[i]) / 2.0 + 0.5;
    }

    for (i = 0; i < 16; i++) {
	printf ("Y, Cb, Cr [%d] = %.10f, %.10f, %.10f\n",
                i,
                y[i],
                cb[i],
                cr[i]);
    }

    printf ("\n");

    for (i = 0; i < 16; i++) {
        r[i] = y[i]
               +    701.0 /    500.0 * (cr[i] - 0.5);
        g[i] = y[i]
               -  25251.0 /  73375.0 * (cb[i] - 0.5)
               - 209599.0 / 293500.0 * (cr[i] - 0.5);
        b[i] = y[i]
               +    443.0 / 250.0    * (cb[i] - 0.5);

	if (r[i] < 0.0) r[i] = 0.0;
	if (r[i] > 1.0) r[i] = 1.0;
	if (g[i] < 0.0) g[i] = 0.0;
	if (g[i] > 1.0) g[i] = 1.0;
	if (b[i] < 0.0) b[i] = 0.0;
	if (b[i] > 1.0) b[i] = 1.0;

    }

    for (i = 0; i < 16; i++) {
	printf ("R, G, B [%2d] = 0x%2.2x%2.2x%2.2x\n",
                i,
               (int) (r[i]*255+.5),
               (int) (g[i]*255+.5),
               (int) (b[i]*255+.5));
    }

    printf ("\n");

    return 0;
}