예제 #1
0
            /// <summary>
            /// Fills the bottom right quadrant with all the colors producible by converting iterating over a uint and unpacking it.
            /// A better algorithm could be used but it works
            /// </summary>
            private static void Rainbow(Buffer2D <TPixel> pixels)
            {
                int left   = pixels.Width / 2;
                int right  = pixels.Width;
                int top    = pixels.Height / 2;
                int bottom = pixels.Height;

                int    pixelCount    = left * top;
                uint   stepsPerPixel = (uint)(uint.MaxValue / pixelCount);
                TPixel c             = default;
                var    t             = new Rgba32(0);

                for (int x = left; x < right; x++)
                {
                    for (int y = top; y < bottom; y++)
                    {
                        t.PackedValue += stepsPerPixel;
                        var v = t.ToVector4();

                        // v.W = (x - left) / (float)left;
                        c.FromVector4(v);
                        pixels[x, y] = c;
                    }
                }
            }
예제 #2
0
        public void Color_Types_To_Vector4_Produce_Equal_OutPut()
        {
            Rgba32     color       = new Rgba32(24, 48, 96, 192);
            RgbaVector colorVector = new RgbaVector(24, 48, 96, 192);

            Assert.Equal(color.ToVector4(), colorVector.ToVector4());
        }
예제 #3
0
        public void Color_Types_To_Vector4_Produce_Equal_OutPut()
        {
            var color       = new Rgba32(24, 48, 96, 192);
            var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);

            Assert.Equal(color.ToVector4(), colorVector.ToVector4());
        }
예제 #4
0
        public void TestAlphaCompositionModes(Rgba32 backdrop, Rgba32 source, float opacity, PixelAlphaCompositionMode mode, Rgba32 expectedResult)
        {
            PixelBlender <Rgba32> blender = PixelOperations <Rgba32> .Instance.GetPixelBlender(PixelColorBlendingMode.Normal, mode);

            Rgba32 actualResult = blender.Blend(backdrop, source, opacity);

            // var str = actualResult.Rgba.ToString("X8"); // used to extract expectedResults
            Assert.Equal(actualResult.ToVector4(), expectedResult.ToVector4());
        }
예제 #5
0
        private static Rgba32 MultiplyColorWithScalar(Rgba32 color, float influence, bool includeA = false)
        {
            var colorVector = Vector4.Multiply(influence, color.ToVector4());

            if (includeA)
            {
                colorVector.W = 255;
            }

            return(new Rgba32(colorVector));
        }
예제 #6
0
        /// <summary>
        /// Writes a run length encoded tga image to the stream.
        /// </summary>
        /// <typeparam name="TPixel">The pixel type.</typeparam>
        /// <param name="stream">The stream to write the image to.</param>
        /// <param name="image">The image to encode.</param>
        private void WriteRunLengthEncodedImage <TPixel>(Stream stream, ImageFrame <TPixel> image)
            where TPixel : struct, IPixel <TPixel>
        {
            Rgba32            color  = default;
            Buffer2D <TPixel> pixels = image.PixelBuffer;
            int totalPixels          = image.Width * image.Height;
            int encodedPixels        = 0;

            while (encodedPixels < totalPixels)
            {
                int    x            = encodedPixels % pixels.Width;
                int    y            = encodedPixels / pixels.Width;
                TPixel currentPixel = pixels[x, y];
                currentPixel.ToRgba32(ref color);
                byte equalPixelCount = this.FindEqualPixels(pixels, x, y);

                // Write the number of equal pixels, with the high bit set, indicating ist a compressed pixel run.
                stream.WriteByte((byte)(equalPixelCount | 128));
                switch (this.bitsPerPixel)
                {
                case TgaBitsPerPixel.Pixel8:
                    int luminance = GetLuminance(currentPixel);
                    stream.WriteByte((byte)luminance);
                    break;

                case TgaBitsPerPixel.Pixel16:
                    var bgra5551 = new Bgra5551(color.ToVector4());
                    BinaryPrimitives.TryWriteInt16LittleEndian(this.buffer, (short)bgra5551.PackedValue);
                    stream.WriteByte(this.buffer[0]);
                    stream.WriteByte(this.buffer[1]);

                    break;

                case TgaBitsPerPixel.Pixel24:
                    stream.WriteByte(color.B);
                    stream.WriteByte(color.G);
                    stream.WriteByte(color.R);
                    break;

                case TgaBitsPerPixel.Pixel32:
                    stream.WriteByte(color.B);
                    stream.WriteByte(color.G);
                    stream.WriteByte(color.R);
                    stream.WriteByte(color.A);
                    break;
                }

                encodedPixels += equalPixelCount + 1;
            }
        }
예제 #7
0
        public Rgba32 GetRandomColourNearby(Rgba32 zColour, float zVariation)
        {
            Vector4 data = zColour.ToVector4();

            float variation = zVariation / 2.0f;

            //float lowerW = data.W - variation;
            //float upperW = data.W + variation;
            //float w = Random_Float(lowerW, upperW);
            //data.W = Euclid.Limit(ref w, 0.0f, 1.0f);

            float lowerX = data.X - variation;
            float upperX = data.X + variation;
            float x = GetRandomSingle(lowerX, upperX);
            data.X = MathsUtils.Limit(ref x, 0.0f, 1.0f);

            float lowerY = data.Y - variation;
            float upperY = data.Y + variation;
            float y = GetRandomSingle(lowerY, upperY);
            data.Y = MathsUtils.Limit(ref y, 0.0f, 1.0f);

            float lowerZ = data.Z - variation;
            float upperZ = data.Z + variation;
            float z = GetRandomSingle(lowerZ, upperZ);
            data.Z = MathsUtils.Limit(ref z, 0.0f, 1.0f);

            Rgba32 col = new Rgba32(data.X, data.Y, data.Z, data.W);
            return col;
        }
예제 #8
0
 public void PackFromRgba32(Rgba32 source)
 {
     this.PackFromVector4(source.ToVector4());
 }
예제 #9
0
 public RaytraceMaterial(Rgba32 color, float albedoFactor, Rgba32 emmitance, float emmitingFactor)
 {
     Albedo    = color.ToVector4() * albedoFactor;
     Emittance = emmitance.ToVector4() * emmitingFactor;
 }
예제 #10
0
 public RaytraceMaterial(Rgba32 color)
 {
     Albedo    = color.ToVector4();
     Emittance = Vector4.Zero;
 }