Beispiel #1
0
        void    TestChromaRanges()
        {
            ImageUtility.ColorProfile profile = new ImageUtility.ColorProfile(ImageUtility.ColorProfile.STANDARD_PROFILE.sRGB);

            float3 tempFloat3 = new float3(0, 0, 0);
            float4 tempFloat4 = new float4(0, 0, 0, 1);

            float Ygo, Cg, Co;

            ranges_t[] ranges = new ranges_t[4];
            for (int lumaIndex = 0; lumaIndex < ranges.Length; lumaIndex++)
            {
                ranges_t range = new ranges_t();
                ranges[lumaIndex] = range;

                float L = (1 + lumaIndex) / 255.0f;

                for (int R = 0; R < 256; R++)
                {
                    for (int G = 0; G < 256; G++)
                    {
                        for (int B = 0; B < 256; B++)
                        {
                            tempFloat4.x = L * R;
                            tempFloat4.y = L * G;
                            tempFloat4.z = L * B;

                            // Convert to YCoCg
//                          Ygo = 0.25f * tempFloat4.x + 0.5f * tempFloat4.y + 0.25f * tempFloat4.z;
//                          Cg = -0.25f * tempFloat4.x + 0.5f * tempFloat4.y - 0.25f * tempFloat4.z;
//                          Co =  0.50f * tempFloat4.x + 0.0f * tempFloat4.y - 0.50f * tempFloat4.z;

                            RGB2YCoCg(tempFloat4.x, tempFloat4.y, tempFloat4.z, out Ygo, out Co, out Cg);
                            YCoCg2RGB(Ygo, Co, Cg, out tempFloat3.x, out tempFloat3.y, out tempFloat3.z);
                            if (Math.Abs(tempFloat3.x - tempFloat4.x) > 1e-6)
                            {
                                throw new Exception("RHA!");
                            }
                            if (Math.Abs(tempFloat3.y - tempFloat4.y) > 1e-6)
                            {
                                throw new Exception("RHA!");
                            }
                            if (Math.Abs(tempFloat3.z - tempFloat4.z) > 1e-6)
                            {
                                throw new Exception("RHA!");
                            }

                            // Convert to xyY
                            float4 XYZ = float4.Zero;
                            profile.RGB2XYZ(tempFloat4, ref XYZ);
                            tempFloat3.x = XYZ.x;
                            tempFloat3.y = XYZ.y;
                            tempFloat3.z = XYZ.z;
                            float3 xyY = float3.Zero;
                            ImageUtility.ColorProfile.XYZ2xyY(tempFloat3, ref xyY);

                            // Update ranges
                            range.Ygo_min = Math.Min(range.Ygo_min, Ygo);
                            range.Ygo_max = Math.Max(range.Ygo_max, Ygo);
                            range.Cg_min  = Math.Min(range.Cg_min, Cg);
                            range.Cg_max  = Math.Max(range.Cg_max, Cg);
                            range.Co_min  = Math.Min(range.Co_min, Co);
                            range.Co_max  = Math.Max(range.Co_max, Co);

                            range.Y_min = Math.Min(range.Y_min, xyY.z);
                            range.Y_max = Math.Max(range.Y_max, xyY.z);
                            range.x_min = Math.Min(range.x_min, xyY.x);
                            range.x_max = Math.Max(range.x_max, xyY.x);
                            range.y_min = Math.Min(range.y_min, xyY.y);
                            range.y_max = Math.Max(range.y_max, xyY.y);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        void TestChromaRanges()
        {
            ImageUtility.ColorProfile	profile = new ImageUtility.ColorProfile(ImageUtility.ColorProfile.STANDARD_PROFILE.sRGB );

            ImageUtility.float3	tempFloat3 = new ImageUtility.float3( 0, 0, 0 );
            ImageUtility.float4	tempFloat4 = new ImageUtility.float4( 0, 0, 0, 1 );

            float	Ygo, Cg, Co;

            ranges_t[]	ranges = new ranges_t[4];
            for ( int lumaIndex=0; lumaIndex < ranges.Length; lumaIndex++ ) {

                ranges_t	range = new ranges_t();
                ranges[lumaIndex] = range;

                float	L = (1+lumaIndex) / 255.0f;

                for ( int R=0; R < 256; R++ ) {
                    for ( int G=0; G < 256; G++ ) {
                        for ( int B=0; B < 256; B++ ) {

                            tempFloat4.x = L * R;
                            tempFloat4.y = L * G;
                            tempFloat4.z = L * B;

                            // Convert to YCoCg
            // 							Ygo = 0.25f * tempFloat4.x + 0.5f * tempFloat4.y + 0.25f * tempFloat4.z;
            // 							Cg = -0.25f * tempFloat4.x + 0.5f * tempFloat4.y - 0.25f * tempFloat4.z;
            // 							Co =  0.50f * tempFloat4.x + 0.0f * tempFloat4.y - 0.50f * tempFloat4.z;

                            RGB2YCoCg( tempFloat4.x, tempFloat4.y, tempFloat4.z, out Ygo, out Co, out Cg );
                            YCoCg2RGB( Ygo, Co, Cg, out tempFloat3.x, out tempFloat3.y, out tempFloat3.z );
                            if ( Math.Abs( tempFloat3.x - tempFloat4.x ) > 1e-6 ) throw new Exception( "RHA!" );
                            if ( Math.Abs( tempFloat3.y - tempFloat4.y ) > 1e-6 ) throw new Exception( "RHA!" );
                            if ( Math.Abs( tempFloat3.z - tempFloat4.z ) > 1e-6 ) throw new Exception( "RHA!" );

                            // Convert to xyY
                            ImageUtility.float4	XYZ = profile.RGB2XYZ( tempFloat4 );
                            tempFloat3.x = XYZ.x;
                            tempFloat3.y = XYZ.y;
                            tempFloat3.z = XYZ.z;
                            ImageUtility.float3	xyY = ImageUtility.ColorProfile.XYZ2xyY( tempFloat3 );

                            // Update ranges
                            range.Ygo_min = Math.Min( range.Ygo_min, Ygo );
                            range.Ygo_max = Math.Max( range.Ygo_max, Ygo );
                            range.Cg_min = Math.Min( range.Cg_min, Cg );
                            range.Cg_max = Math.Max( range.Cg_max, Cg );
                            range.Co_min = Math.Min( range.Co_min, Co );
                            range.Co_max = Math.Max( range.Co_max, Co );

                            range.Y_min = Math.Min( range.Y_min, xyY.z );
                            range.Y_max = Math.Max( range.Y_max, xyY.z );
                            range.x_min = Math.Min( range.x_min, xyY.x );
                            range.x_max = Math.Max( range.x_max, xyY.x );
                            range.y_min = Math.Min( range.y_min, xyY.y );
                            range.y_max = Math.Max( range.y_max, xyY.y );
                        }
                    }
                }

            }
        }