Direct3D9 on Windows XP Color Conversion on the Nividia Graphics

hi,

i dont know if this is the right place to ask this question but i am working on writing a HLSL Shader to do YV12 to RGb color conversion for rendering video using Direct3d.

I am facing some issues here and i have been trying all kinds of things to resolve the same.

I have 3 Direct3D textures each loaded with y, u and v data. I have added a HLSL pixel shader to the graphics pipeline so that it does the color conversion using the below code. The output is right with minor problems where few of the colors do not come out right for eg. purple looks brown. The reds are fine but the blue looks greenish, have no clue what is impacting the color conversion. Was wondering if Direct3D is doing something or it is just the color conversion equations. I have seen that these equations are pretty standard.

Any help would be really appreciated -

struct pixel_in {

float2 texcoord1 : TEXCOORD1;

float2 texcoord2 : TEXCOORD2;

float2 texcoord3 : TEXCOORD3;

float4 color : COLOR0;

};

struct pixel_out {

float4 color : COLOR0;

};

sampler2D input : register(s0);

sampler2D input1 : register(s1);

sampler2D input2 : register(s2);

pixel_out

main (pixel_in IN)

{

pixel_out OUT;

float3 YUV = float3(tex2D (input, IN.texcoord1).x - (16.0 / 256.0) ,

tex2D (input1, IN.texcoord2).x - (128.0 / 256.0),

tex2D (input2, IN.texcoord3).x - (128.0 / 256.0));

OUT.color.r = clamp((1.164 * YUV.x + 1.596 * YUV.y),0,255);

OUT.color.g = clamp((1.164 * YUV.x - 0.813 * YUV.z - 0.391 * YUV.y), 0,255);

OUT.color.b = clamp((1.164 * YUV.x + 2.018 * YUV.z),0,255);

OUT.color.a = IN.color.a;

return OUT;

}

Sorry, this forum is for CUDA questions only.

However, from looking at your shader you seem to be assuming that the output values from the shader should be between 0 and 255, when they are usually between 0.0 and 1.0.

Hope this helps!