# Colormatrix bug or is my math buggy? RSS

Last post Apr 03, 2007 01:19 AM by atsofttech

Member

11 Points

415 Posts

### Colormatrix bug or is my math buggy?

Howdie y'all,

I've encountered some strange problem... To create a good negative of an image I draw the image one time with a compression matrix to get rid of the 0 values since they don't convert and get black, and one time with the -1 to each color. It's ridiculous to draw the image twice but as soon as I multiply the two matrixes and apply that one matrix, I get a completely black image. Can some of you guys/girls tell me where I'm going wrong? Here's the working code:

```ColorMatrix cm = new ColorMatrix(new float[][]{
new float[] {0.992f,     0f,     0f, 0f, 0f},
new float[] {    0f, 0.992f,     0f, 0f, 0f},
new float[] {    0f,     0f, 0.992f, 0f, 0f},
new float[] {    0f,     0f,     0f, 1f, 0f},
new float[] {0.004f, 0.004f, 0.004f, 0f, 1f}});

ApplyColorMatrix(b, cm);

cm = new ColorMatrix(new float[][]{
new float[] {-1f,  0f,  0f, 0f, 0f},
new float[] { 0f, -1f,  0f, 0f, 0f},
new float[] { 0f,  0f, -1f, 0f, 0f},
new float[] { 0f,  0f,  0f, 1f, 0f},
new float[] { 0f,  0f,  0f, 0f, 1f}});

ApplyColorMatrix(b, cm);
```

And here's the code that should do the same thing - according to my math which I'm not good at - but allways delivers me a completely black image.

```ColorMatrix cm = new ColorMatrix(new float[][]{
new float[] {-0.992f,      0f,      0f, 0f, 0f},
new float[] {     0f, -0.992f,      0f, 0f, 0f},
new float[] {     0f,      0f, -0.992f, 0f, 0f},
new float[] {     0f,      0f,      0f, 1f, 0f},
new float[] {-0.004f, -0.004f, -0.004f, 0f, 1f}});

ApplyColorMatrix(b, cm);
```

Can some of you please please please help me out on this one? It's driving me crazy...

Cheers,

Wes

Listen carefully, I will say this only once...

Member

361 Points

264 Posts