コード例 #1
0
ファイル: Pintar.cs プロジェクト: Nilphy/6671sistemasgraficos
        public static void RellenarPoligonoScanLine(IList vertices, ColorRGB color)
        {
            //Algoritmo scanline para relleno de polígonos
            Dictionary<int, ArrayList> segmentos = new Dictionary<int, ArrayList>();
            double dySegmentoActual;
            double dySegmentoAnterior;
            Punto puntoInicial;
            Punto puntoAnterior;
            if (vertices.Count < 3) return;

            puntoAnterior = (Punto)vertices[vertices.Count - 2];
            puntoInicial = (Punto)vertices[vertices.Count - 1];
            foreach (Punto puntoFinal in vertices)
            {
                dySegmentoActual = puntoFinal.GetYEntero() - puntoInicial.GetYEntero();
                dySegmentoAnterior = puntoInicial.GetYEntero() - puntoAnterior.GetYEntero();

                if (dySegmentoActual != 0)
                {
                    //agrego el vértice una vez
                    agregarPunto(segmentos, puntoInicial.GetXEntero(), puntoInicial.GetYEntero());
                    if (dySegmentoAnterior < 0 && dySegmentoActual > 0 || dySegmentoAnterior > 0 && dySegmentoActual < 0)
                    {
                        //tengo un máximo local, agrego el punto 2 veces
                        agregarPunto(segmentos, puntoInicial.GetXEntero(), puntoInicial.GetYEntero());
                    }
                    procesarSegmento(puntoInicial, puntoFinal, segmentos);
                }
                puntoAnterior = puntoInicial;
                puntoInicial = puntoFinal;
            }

            /*for (int i = 0; i < vertices.Count; i++)
            {
                dySegmentoActual = vertices[(i + 1) % vertices.Count].GetYEntero() - vertices[i].GetYEntero();
                dySegmentoAnterior = vertices[i].GetYEntero() - vertices[(i - 1 + vertices.Count) % vertices.Count].GetYEntero();
                if (dySegmentoActual != 0)
                {
                    //agrego el vértice una vez
                    agregarPunto(segmentos, vertices[i].GetXEntero(), vertices[i].GetYEntero());
                    if (dySegmentoAnterior < 0 && dySegmentoActual > 0 || dySegmentoAnterior > 0 && dySegmentoActual < 0)
                    {
                        //tengo un máximo local, agrego el punto 2 veces
                        agregarPunto(segmentos, vertices[i].GetXEntero(), vertices[i].GetYEntero());
                    }
                    procesarSegmento(vertices[i], vertices[(i + 1) % vertices.Count], segmentos);
                }
            }*/

            foreach (int y in segmentos.Keys)
            {
                segmentos[y].Sort();
                for (int i = 0; i < segmentos[y].Count; i += 2)
                {
                    pintar((int)segmentos[y][i], (int)segmentos[y][(i + 1) % segmentos[y].Count], y, color);
                }
            }
        }
コード例 #2
0
        public void RGBIsContrastingColor()
        {
            var rgb      = ColorRGB.FromRGB(178, 83, 83);
            var rgbLight = ColorRGB.FromRGB(247, 242, 242);
            var rgbDark  = ColorRGB.FromRGB(5, 5, 5);

            Assert.AreEqual(rgb.IsContrastingColor(rgb), false);
            Assert.AreEqual(rgb.IsContrastingColor(ColorRGB.White), true);

            Assert.AreEqual(rgbLight.IsContrastingColor(ColorRGB.White), false);
            Assert.AreEqual(rgbLight.IsContrastingColor(ColorRGB.Black), true);

            Assert.AreEqual(rgbDark.IsContrastingColor(ColorRGB.White), true);
            Assert.AreEqual(rgbDark.IsContrastingColor(ColorRGB.Black), false);
        }
コード例 #3
0
ファイル: TracerTest.cs プロジェクト: obimmatimothy/raytracer
        public void TestTraceRay_NotNullHitInfo_AndNoObjectsInTheScene()
        {
            //Arrange
            sceneTestInstance = new SceneTestInstance(winFrame);
            sceneTestInstance.SetValue(2);
            Point3D  zeroOrigin = new Point3D(0);
            Vector3D zeroVector = new Vector3D(0);
            Ray      testRay    = new Ray(zeroOrigin, zeroVector);

            testTracer = new Tracer(sceneTestInstance);
            //Act
            ColorRGB colorResult = testTracer.TraceRay(testRay);

            Assert.IsTrue(sceneTestInstance.GetBackgroundColor().Equals(colorResult));
        }
コード例 #4
0
ファイル: Extensions.cs プロジェクト: newcat/LedMusic
        public static ColorRGB Overlay(this ColorRGB a, ColorRGB b)
        {
            double alphaA = a.getColorHSV().V;
            double alphaB = a.getColorHSV().V;
            byte   red    = Convert.ToByte(alphaA * a.R + (1 - alphaA) * b.R);
            byte   green  = Convert.ToByte(alphaA * a.G + (1 - alphaA) * b.G);
            byte   blue   = Convert.ToByte(alphaA * a.B + (1 - alphaA) * b.B);

            return(new ColorRGB(red, green, blue));
            //double alpha = a.A + (1 - a.A) * b.A;
            //byte red = Convert.ToByte((1 / alpha) * (a.A * a.R + (1 - a.A) * b.A * b.R));
            //byte green = Convert.ToByte((1 / alpha) * (a.A * a.G + (1 - a.A) * b.A * b.G));
            //byte blue = Convert.ToByte((1 / alpha) * (a.A * a.B + (1 - a.A) * b.A * b.B));
            //return new ColorRGB(alpha, red, green, blue);
        }
コード例 #5
0
        public void TestGetColor()
        {
            //Arrange
            HitInfo hitInfo  = new HitInfo();
            Point3D hitPoint = new Point3D(0);

            hitInfo.hitPoint = hitPoint;

            ColorRGB expectedColor = (100.0 / lightPosition.GetDistance(hitPoint)) * lightColor * intensity;
            //Act
            ColorRGB actualColor = testLight.GetColor(hitInfo);

            //Assert
            Assert.IsTrue(actualColor.Equals(expectedColor));
        }
コード例 #6
0
        public void IsAffordanceAvailableTestCheckDeviceActionGroupInDeviceActionGroup()
        {
            // Location: device action group
            // affordance: device Action Group
            Config.IsInUnitTesting = true;
            var col           = new ColorRGB(255, 0, 0);
            var deviceActions = new ObservableCollection <DeviceAction>();
            var aff           = new Affordance("bla", null, null, false, PermittedGender.All, 1, col, string.Empty, null,
                                               string.Empty, string.Empty,
                                               true, true, 0, 100, false, ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
            var rd1 = new RealDevice("rd1", 1, string.Empty, null, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid());

            var dg = new DeviceActionGroup("group", string.Empty, string.Empty, Guid.NewGuid().ToStrGuid());
            var da = new DeviceAction("device action 1", null, "blub", string.Empty, dg, rd1, Guid.NewGuid().ToStrGuid());

            deviceActions.Add(da);
            var devices = new ObservableCollection <RealDevice>
            {
                rd1
            };
            // check if it works with a device category that has the device
            var dc1 = new DeviceCategory("dc1", 0, string.Empty, false, devices, Guid.NewGuid().ToStrGuid(), null, true);

            rd1.DeviceCategory = dc1;
            dc1.RefreshSubDevices();
            (dc1.SubDevices.Count).Should().Be(1);
            var connectionString = string.Empty;
            var lt = new VLoadType("lt", string.Empty, "bla", "blub", 1, 1, new TimeSpan(0, 1, 0), 1, connectionString,
                                   LoadTypePriority.Mandatory, true, Guid.NewGuid().ToStrGuid());
            var tbp = new TimeBasedProfile("name", 1, connectionString, TimeProfileType.Absolute, "data source", Guid.NewGuid().ToStrGuid());

            aff.AffordanceDevices.Add(new AffordanceDevice(dg, tbp, null, 0, null,
                                                           new ObservableCollection <RealDevice>(),
                                                           new ObservableCollection <DeviceCategory>(), "name", lt, string.Empty, 1, Guid.NewGuid().ToStrGuid()));
            var allDevices3 = new List <IAssignableDevice>
            {
                dg
            };

            if (da.DeviceActionGroup == null)
            {
                throw new LPGException("device action group was null");
            }
            var relevantDeviceActionGroup = da.DeviceActionGroup.GetDeviceActions(deviceActions);

            (relevantDeviceActionGroup.Count).Should().Be(1);
            (aff.IsAffordanceAvailable(allDevices3, deviceActions)).Should().BeTrue();
        }
コード例 #7
0
ファイル: Scene.cs プロジェクト: obimmatimothy/raytracer
        public Scene(Scene sceneObj)
        {
            SetLights(sceneObj.lightsList);
            SetObjects(sceneObj.objectsList);

            if (sceneObj.background != null)
            {
                background = new ColorRGB(sceneObj.GetBackgroundColor());
            }

            winFrame    = sceneObj.winFrame;
            finalPixels = new ColorRGB[winFrame.width, winFrame.height];
            tracer      = sceneObj.tracer;
            camera      = sceneObj.camera;
            sampler     = sceneObj.sampler;
        }
コード例 #8
0
    // Start is called before the first frame update
    void Start()
    {
        puzzleManager = GetComponent <PillarPuzzleManager>();
        colorToPillar = pillarColors.ToDictionary(x => x.Color);

        pillars = new Pillar[transform.childCount];
        for (int i = 0; i < transform.childCount; i++)
        {
            Transform child = transform.GetChild(i);
            string    name  = child.name;
            ColorRGB  color = name[0] == 'R' ? ColorRGB.Red : name[0] == 'B' ? ColorRGB.Blue : ColorRGB.Green;
            pillars[i] = new Pillar(child, color);
        }

        timer = initialTime;
    }
コード例 #9
0
        private void SetColor(int x, int y, ColorRGB c)
        {
            OpenGL gl = openGLControl.OpenGL;

            byte[] pixel = new byte[3];
            pixel[0] = c.r;
            pixel[1] = c.g;
            pixel[2] = c.b;

            gl.Begin(OpenGL.GL_POINTS);
            gl.Color(c.r, c.g, c.b);
            gl.Vertex(x, y);
            gl.End();

            gl.Flush();
        }
コード例 #10
0
ファイル: ProjectLS.cs プロジェクト: ivynetca/lapsestudio
        private unsafe void BaseProcess(ColorRGB c, double exposure)
        {
            //TODO: Make processing better (highlight and dark preserve)
            fixed(double *pt = c.ValueArray)
            {
                ((RGBSpace)c.Space).ToLinear(pt, pt);
            }

            c.R = Math.Exp(exposure * ln2) * c.R;
            c.G = Math.Exp(exposure * ln2) * c.G;
            c.B = Math.Exp(exposure * ln2) * c.B;
            fixed(double *pt = c.ValueArray)
            {
                ((RGBSpace)c.Space).ToNonLinear(pt, pt);
            }
        }
コード例 #11
0
        /// <summary>
        /// Initialise la liste des couleurs
        /// </summary>
        private void InitializeColorList()
        {
            //Entier de granularité : indique le nombre de couleur qui sera introduite dans la grille à partir de toute la gamme possible
            int colorGranularity = 50;

            for (int i = 0; i < colorGranularity; i++) //On crée un certain nombre de couleur
            {
                //Création d'une couleur à partir de la teinte:
                //  Teinte: 1.0 / colorGranularity * i : la teinte doit être entrée en % dans la classe ColorRGB (0->1). On crée des paliers qui vont de 0->1 en fonction de colorGranularity
                //  Saturation : 1 : Couleur vive
                //  Luminosité : 0.5 : Couleur moyenne entre noir et blanc (luminosité 0->noir, luminosité 1->blanc)
                ColorRGB        colorRGB = ColorRGB.FromHSL(1.0 / colorGranularity * i, 1, 0.5);
                SolidColorBrush brush    = new SolidColorBrush(colorRGB); //Création du pinceau représentant une couleur
                this.colorBrushes.Add(brush);                             //Ajout de ce pinceau à la liste
            }
        }
コード例 #12
0
        public void RGBtoHSLConversion()
        {
            var rgb          = ColorRGB.FromHex("#6653B2");
            var hsl          = (ColorHSL)ColorHSL.FromColor(rgb);
            var rgbConverter = (ColorRGB)hsl.ToRgb();

            // HSL
            Assert.AreEqual(hsl.Hue, 252);
            Assert.AreEqual(hsl.Saturation, 38.15);
            Assert.AreEqual(hsl.Luminance, 51.18);

            // RGB Converted
            Assert.AreEqual(rgbConverter.Red, 102);
            Assert.AreEqual(rgbConverter.Green, 83);
            Assert.AreEqual(rgbConverter.Blue, 178);
        }
コード例 #13
0
        public void RGBtoHSBConversion()
        {
            var rgb          = ColorRGB.FromHex("#6653B2");
            var hsb          = (ColorHSB)ColorHSB.FromColor(rgb);
            var rgbConverted = (ColorRGB)hsb.ToRgb();

            // HSL
            Assert.AreEqual(hsb.Hue, 252);
            Assert.AreEqual(hsb.Saturation, 53.37);
            Assert.AreEqual(hsb.Brightness, 69.8);

            // RGB Converted
            Assert.AreEqual(rgbConverted.Red, 102);
            Assert.AreEqual(rgbConverted.Green, 83);
            Assert.AreEqual(rgbConverted.Blue, 178);
        }
コード例 #14
0
        static string Unity_ReplaceColor(
            [Slot(0, Binding.None)] Vector3 In,
            [Slot(1, Binding.None)] ColorRGB From,
            [Slot(2, Binding.None)] ColorRGB To,
            [Slot(3, Binding.None)] Vector1 Range,
            [Slot(5, Binding.None)] Vector1 Fuzziness,
            [Slot(4, Binding.None)] out Vector3 Out)
        {
            Out = Vector3.zero;
            return
                (@"
{
    {precision} Distance = distance(From, In);
    Out = lerp(To, In, saturate((Distance - Range) / max(Fuzziness, 1e-5f)));
}");
        }
コード例 #15
0
        public void TestCirlesEllipses()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));

            Canvas canvas = document.Pages[0].Canvas;
            Path   path   = new Path();

            path.AddEllipse(50, 50, document.Pages[0].Width - 100, document.Pages[0].Height - 100);
            canvas.SetClip(path);
            canvas.DrawPath(new SolidPen(), path);
            path.Reset();

            Random rand = new Random();

            for (int i = 0; i < 200; ++i)
            {
                float x = (float)rand.NextDouble() * (document.Pages[0].Width - 100 + 1);
                float y = (float)rand.NextDouble() * (document.Pages[0].Height - 100 + 1);
                float s = (float)rand.NextDouble() * (150 + 1);

                if (i % 2 == 0)
                {
                    path.AddCircle(x, y, s);
                }
                else
                {
                    float k = (float)rand.NextDouble() * (150 + 1);
                    path.AddEllipse(x, y, s, k);
                }
                Color color = new ColorRGB((Byte)rand.Next(256), (Byte)rand.Next(256), (Byte)rand.Next(256));
                canvas.DrawPath(new SolidPen(color), new SolidBrush(color), path);
                path.Reset();
            }

            path.AddEllipse(50, 50, document.Pages[0].Width - 100, document.Pages[0].Height - 100);
            canvas.SetClip(path);
            SolidPen pen = new SolidPen();

            pen.Width = 2.5f;
            canvas.DrawPath(pen, path);

            document.Save(OutputFolder + @"\TestCirclesEllipses.pdf");

            //Process.Start("TestCirclesEllipses.pdf");
        }
コード例 #16
0
        public void TestTransformAndPie()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            Canvas      canvas = document.Pages[0].Canvas;
            DeviceColor red    = new ColorRGB(255, 0, 0);
            DeviceColor green  = new ColorRGB(0, 255, 0);
            DeviceColor blue   = new ColorRGB(0, 0, 255);

            SolidBrush brush = new SolidBrush(red);
            SolidPen   pen   = new SolidPen();

            pen.Width = 3;

            canvas.TranslateTransform(100, 200);
            canvas.DrawPie(brush, 0, 0, 50, 50, -90, 120);
            brush.Color = green;
            canvas.DrawPie(brush, 0, 0, 50, 50, 30, 120);
            brush.Color = blue;
            canvas.DrawPie(pen, brush, 0, 0, 50, 50, -90, -120);

            canvas.TranslateTransform(150, 0);
            canvas.ScaleTransform(1.5f, 1.5f);
            canvas.RotateTransform(90);

            brush.Color = red;
            canvas.DrawPie(brush, 0, 0, 50, 50, -90, 120);
            brush.Color = green;
            canvas.DrawPie(brush, 0, 0, 50, 50, 30, 120);
            brush.Color = blue;
            canvas.DrawPie(pen, brush, 0, 0, 50, 50, -90, -120);

            canvas.TranslateTransform(0, -150);
            canvas.ScaleTransform(1.5f, 1.5f);
            canvas.RotateTransform(45);

            brush.Color = red;
            canvas.DrawPie(brush, 0, 0, 50, 50, -90, 120);
            brush.Color = green;
            canvas.DrawPie(brush, 0, 0, 50, 50, 30, 120);
            brush.Color = blue;
            canvas.DrawPie(pen, brush, 0, 0, 50, 50, -90, -120);

            document.Save(OutputFolder + @"\TestTransformAndPie.pdf");
            document.Dispose();
        }
コード例 #17
0
ファイル: Pon.cs プロジェクト: auchiyam/osb-generator
        public void DrawTileBackground(double starttime, double endtime)
        {
            //The background colors of tiles
            Sprite tback1 = Util.Line(450, 220, Origin.TopRight);
            Sprite tback2 = Util.Line(450, 220, Origin.TopLeft);
            Sprite tside1 = Util.Line(450, 20, Origin.TopRight);
            Sprite tside2 = Util.Line(450, 20, Origin.TopLeft);

            tback1.Move(starttime, 320, 240);
            tback2.Move(starttime, 320, 240);
            tside1.Move(starttime, 320, 460);
            tside2.Move(starttime, 320, 460);

            Color red   = new ColorRGB(210, 210, 210);
            Color sred  = (Color)(red - 30);
            Color blue  = new ColorRGB(45, 45, 45);
            Color sblue = (Color)(blue - 30);

            Color black = new ColorRGB(0, 0, 0);

            double fadestart = endtime - beat * 4;
            double fadeend   = endtime;

            tback1.Color(starttime, red);
            tback1.Color(fadestart, fadeend, red, black);

            tside1.Color(starttime, sred);
            tside1.Color(fadestart, fadeend, sred, black);

            tback2.Color(starttime, blue);
            tback2.Color(fadestart, fadeend, blue, black);

            tside2.Color(starttime, sblue);
            tside2.Color(fadestart, fadeend, sblue, black);

            tback1.Fade(starttime, starttime + beat * 1.5, 0, 1);
            tback2.Fade(starttime, starttime + beat * 1.5, 0, 1);
            tside1.Fade(starttime, starttime + beat * 1.5, 0, 1);
            tside2.Fade(starttime, starttime + beat * 1.5, 0, 1);

            tback1.Fade(fadestart, fadeend, 1, 0);
            tback2.Fade(fadestart, fadeend, 1, 0);
            tside1.Fade(fadestart, fadeend, 1, 0);
            tside2.Fade(fadestart, fadeend, 1, 0);

            Layers.AddSprite("kiai tiles", tback1, tback2, tside1, tside2);
        }
コード例 #18
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            ColorRGB blueColor = new ColorRGB(0, 0, 255);
            ColorRGB grayColor = new ColorRGB(128, 128, 128);

            // Create tiling brush and paint on it
            UncoloredTilingBrush tilingBrush1 = new UncoloredTilingBrush(10, 12);
            Canvas brushCanvas = tilingBrush1.Canvas;

            brushCanvas.DrawCircle(new SolidPen(blueColor), 0, 6, 6);
            tilingBrush1.Color = blueColor;

            // Create second tiling brush and paint on it using the first brush
            ColoredTilingBrush tilingBrush2 = new ColoredTilingBrush(70, 50);

            brushCanvas = tilingBrush2.Canvas;
            brushCanvas.DrawEllipse(new SolidPen(grayColor), tilingBrush1, 0, 0, 60, 20);

            // Draw rectangle and fill it with combined tiling brush
            page.Canvas.DrawRectangle(new SolidPen(), tilingBrush2, 100, 100, 400, 400);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
コード例 #19
0
        public static void TextMarkup11()
        {
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            // Create the Shapes that will hold the text
            var s1  = page.DrawRectangle(0, 0, 8.5, 11);
            var tnr = page.Document.Fonts["Times New Roman"];

            var e1        = new VisioAutomation.Models.Text.TextElement();
            var color_red = new ColorRGB(0xff0000);

            e1.CharacterFormatting.Color = color_red.ToFormula();
            e1.CharacterFormatting.Font  = tnr.ID;
            e1.CharacterFormatting.Font  = "20pt";
            e1.AddText("Hello World");
            e1.SetText(s1);
        }
コード例 #20
0
        /// <summary>
        /// Get the WPF color from a RGB color definition
        /// </summary>
        private (Color, GraphicColorPrecision) GetColor(ColorRGB rgbColor)
        {
            Color color;

            if (isProfileAvailable)
            {
                float[] colorValues = { (float)(rgbColor.R / 255.0), (float)(rgbColor.G / 255.0), (float)(rgbColor.B / 255.0) };

                color = Color.FromValues(colorValues, GetProfileUri());
            }
            else
            {
                color = Color.FromRgb((byte)rgbColor.R, (byte)rgbColor.G, (byte)rgbColor.B);
            }

            return(color, GraphicColorPrecision.Precise);
        }
コード例 #21
0
ファイル: Statistics.cs プロジェクト: belzecue/Common
        public static ColorRGB Mean(ColorRGB[,] data)
        {
            int width  = data.GetLength(0);
            int height = data.GetLength(1);

            ColorRGB u = new ColorRGB();

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    u += data[i, j];
                }
            }

            return(u / (width * height));
        }
コード例 #22
0
ファイル: Game1.cs プロジェクト: LaurieCheers/GifScript
        void DrawCube(GifCube cube, int frame, ColorRGB highlightPos, Vector2 pos, Vector2 size)
        {
            for (int x = 0; x < 16; ++x)
            {
                DrawString("" + GetHexChar(x), new Vector2(pos.X + 16 + x * size.X, pos.Y - 20), new Color(x * 16, 0, 0));
                DrawString("" + GetHexChar(x), new Vector2(pos.X + 16 + x * size.X, pos.Y + 10 + 16 * size.Y), showingPosition.B16 == x? Color.Yellow: new Color(0, 0, x * 16));
            }

            for (int y = 0; y < 16; ++y)
            {
                DrawString("" + GetHexChar(y), new Vector2(pos.X - 16, pos.Y + 10 + y * size.Y), new Color(0, y * 16, 0));
            }
            Vector2 size_ = size;

            DrawRectangle(pos.ToRectangle(size_ * 16), Color.Black);
            size_ = size;
            DrawRectangle(new Vector2(pos.X + highlightPos.R16 * size_.X - 1, pos.Y + highlightPos.G16 * size_.Y - 1).ToRectangle(new Vector2(size_.X + 2, size_.Y + 2)), Color.White);
            for (int x = 0; x < 16; ++x)
            {
                for (int y = 0; y < 16; ++y)
                {
                    DrawCell(cube, x, y, frame, new Vector2(pos.X + x * size.X, pos.Y + y * size.Y), new Vector2(size.X - 1, size.Y - 1));
                }
            }

            foreach (Breakpoint b in breakpoints)
            {
                if (b.cube == showingCube && b.position.B16 == showingPosition.B16)
                {
                    DrawImage(breakpointTexture, new Vector2(pos.X + b.position.R16 * size.X + 35, pos.Y + b.position.G16 * size.Y + 18));
                }
            }

            foreach (ColorRGB register in interestingRegisters)
            {
                GifCube registerCube = gifScriptState.GetRegisterTarget(register);
                if (cube == registerCube)
                {
                    ColorRGB registerPos = gifScriptState.GetRegisterPosition(register);
                    if (registerPos.B16 == frame)
                    {
                        DrawPointer(register, new Vector2(pos.X + registerPos.R16 * size.X, pos.Y + registerPos.G16 * size.Y), size);
                    }
                }
            }
        }
コード例 #23
0
    // Use this for initialization
    void Start()
    {
        rt = GetComponent <RectTransform>();

        CRGB = GetComponentInChildren <ColorRGB>();
        CP   = GetComponentInChildren <ColorPanel>();
        CC   = GetComponentInChildren <ColorCircle>();

        sliderCRGB.onValueChanged.AddListener(OnCRGBValueChanged);

        CC.getPos += CC_getPos;

        _closeButton.onClick.AddListener(() =>
        {
            Destroy(this.gameObject);
        });
    }
コード例 #24
0
        public object ConvertBack(object value, [CanBeNull] Type targetType, object parameter,
                                  [CanBeNull] CultureInfo culture)
        {
            if (targetType != typeof(Brush))
            {
                throw new NotImplementedException();
            }

            if (value == null)
            {
                return(null);
            }
            ColorRGB rgb = (ColorRGB)value;
            Color    c   = Color.FromRgb(rgb.R, rgb.G, rgb.B);

            return(new SolidColorBrush(c));
        }
コード例 #25
0
        static string Unity_ColorMask(
            [Slot(0, Binding.None)] Vector3 In,
            [Slot(1, Binding.None)] ColorRGB MaskColor,
            [Slot(2, Binding.None)] Vector1 Range,
            [Slot(3, Binding.None)] out Vector3 Out)
        {
            Out = Vector3.zero;
            return
                (@"
{
    {precision}3 col = {precision}3(0, 0, 0);
    {precision} Distance = distance(MaskColor, In);
    if(Distance <= Range)
        col = {precision}3(1, 1, 1);
    Out = col;
}");
        }
コード例 #26
0
        /// <summary>
        /// Given a Color (RGB Struct) in range of 0-255. Return a HEX string starts with #.
        /// </summary>
        /// <param name="rgb">The <see cref="T:DotNetCommonTools.ColorHelper.ColorRGB" /> to convert.</param>
        /// <returns></returns>
        public static string RGB2HEX(ColorRGB rgb)
        {
            string rs = DecimalToHexadecimal(rgb.r);
            string gs = DecimalToHexadecimal(rgb.g);
            string bs = DecimalToHexadecimal(rgb.b);

            if (rs.Substring(0, 1).Equals(rs.Substring(1, 1)) &&
                gs.Substring(0, 1).Equals(gs.Substring(1, 1)) &&
                bs.Substring(0, 1).Equals(bs.Substring(1, 1))
                )
            {
                rs = rs.Substring(0, 1);
                bs = bs.Substring(0, 1);
                gs = gs.Substring(0, 1);
            }
            return('#' + rs + gs + bs);
        }
コード例 #27
0
        public static MonochromaticColorScheme FromColor(ColorRGB color)
        {
            //if (flatten) {
            //	var labColors = ColorScheme.GenerateColors (24, 0, .66, .81);
            //	color = color.NearestFlatColor (labColors);
            //}

            var lab = (ColorLAB)ColorLAB.FromColor(color);

            var dark      = new Swatch(DarkColorID, ColorLAB.ToColor(lab.L - 20, lab.A, lab.B));
            var darkened  = new Swatch(DarkenedColorID, ColorLAB.ToColor(lab.L - 10, lab.A, lab.B));
            var primary   = new Swatch(PrimaryColorID, color);
            var lightened = new Swatch(LightenedColorID, ColorLAB.ToColor(lab.L + 10, lab.A, lab.B));
            var light     = new Swatch(LightColorID, ColorLAB.ToColor(lab.L + 20, lab.A, lab.B));

            return(new MonochromaticColorScheme(new Swatch [] { dark, darkened, primary, lightened, light }));
        }
コード例 #28
0
            public void ShouldReturnTheCorrectValueWhenInstanceIsNull()
            {
                var color = new ColorRGB(0, 0, 0);

                Assert.False(color is null);
                Assert.True(color != null);
                Assert.False(color < null);
                Assert.False(color <= null);
                Assert.True(color > null);
                Assert.True(color >= null);
                Assert.False(null == color);
                Assert.True(null != color);
                Assert.True(null < color);
                Assert.True(null <= color);
                Assert.False(null > color);
                Assert.False(null >= color);
            }
コード例 #29
0
ファイル: ColorHSV.cs プロジェクト: saveenr/Colorspace
        public ColorHSV(ColorRGB rgb)
        {
            double maxc = System.Math.Max(rgb.R, System.Math.Max(rgb.G, rgb.B));
            double minc = System.Math.Min(rgb.R, System.Math.Min(rgb.G, rgb.B));

            double h = double.NaN;
            double s = double.NaN;
            double v = double.NaN;

            // Handle case for r,g,b all have the same value
            if (maxc == minc)
            {
                // Black, White, or some shade of Gray -> No Chroma
                this._alpha = rgb.Alpha;
                this._h     = double.NaN;
                this._s     = double.NaN;
                this._v     = maxc;
                return;
            }

            // At this stage, we know R,G,B are not all set to the same value - i.e. there is Chromatic data
            double delta = maxc - minc;

            s = delta / maxc;
            v = maxc;

            if (rgb.R == maxc)
            {
                h = 0.0 + ((rgb.G - rgb.B) / delta);
            }
            else if (rgb.G == maxc)
            {
                h = 2.0 + ((rgb.B - rgb.R) / delta);
            }
            else
            {
                h = 4.0 + ((rgb.R - rgb.G) / delta);
            }

            h = ColorUtil.NormalizeHue(h / 6.0);

            this._alpha = rgb.Alpha;
            this._h     = h;
            this._s     = s;
            this._v     = v;
        }
コード例 #30
0
        /// <summary>
        /// Sets up everything necessary for "party mode". All of the colours.
        /// </summary>
        public Feature_Party_Mode()
        {
            // Initialize "Diamond in The Sky"
            string[] File_List = Directory.GetFiles(Environment.CurrentDirectory + @"\dvdroot\bgm\", "*.adx");

            for (int x = 0; x < File_List.Length; x++)
            {
                // If "Diamong in the Sky" is present within the strings.
                if (File_List[x].Contains("SR_Partymode.adx"))
                {
                    // Get the file name of the track (just in case).
                    string File_Name_Only = Path.GetFileName(File_List[x]); // Get File Name Only.

                    // Get the bytes to be written into game memory & allocate memory.
                    byte[] Memory_Bytes  = Encoding.ASCII.GetBytes(File_Name_Only);                          // Get bytes to write file name in memory.
                    IntPtr Write_Address = Program.Sonic_Heroes_Process.AllocateMemory(Memory_Bytes.Length); // Memory address.

                    // Write the file onto game memory.
                    Program.Sonic_Heroes_Process.WriteMemory(Write_Address, Memory_Bytes); // Write the file name to memory.

                    // Store address
                    Pointer_DiamondInTheSky = (int)Write_Address;

                    // Break out from the loop.
                    break;
                }
            }

            // Defines the starting colour at which the colour cycling begins at;
            ColorRGB BaseColour    = new ColorRGB(1F, 0F, 0F);
            ColorHSV BaseColourHSV = new ColorHSV(BaseColour); // Convert to HSV

            // Precalculate cycle values (CPU Saving)
            for (int z = 0; z < 256; z++)
            {
                // Obtain HUE Values
                byte BaseColour_Hue = (byte)((BaseColourHSV.H * 255.0F) + z); // Convert to max 255 and increment 1.

                // Cycle Hue                                       // Back to out of 1.
                ColorHSV Current_BaseColour_Hue = new ColorHSV(BaseColour_Hue / 255.0F, BaseColourHSV.S, BaseColourHSV.V);

                // Convert back to RGB
                BaseColour_Colours[z] = new ColorRGB(Current_BaseColour_Hue);
            }
        }
コード例 #31
0
        static string Unity_ReplaceColor(
            [Slot(0, Binding.None)] Vector3 In,
            [Slot(1, Binding.None)] ColorRGB From,
            [Slot(2, Binding.None)] ColorRGB To,
            [Slot(3, Binding.None)] Vector1 Range,
            [Slot(4, Binding.None)] out Vector3 Out)
        {
            Out = Vector2.zero;
            return
                (@"
{
    {precision}3 col = In;
    {precision} Distance = distance(From, In);
    if(Distance <= Range)
        col = To;
    Out = col;
}");
        }
コード例 #32
0
        public Bitmap ProcessBitmap(Bitmap source)
        {
            if (HueMode == AdjustmentMode.None && SaturationMode == AdjustmentMode.None && LightnessMode == AdjustmentMode.None && AA == 1)
                return source;

            Bitmap result = new Bitmap(source.Width, source.Height);

            if (m_aa == 0)
                return result;

            for (int ix = 0; ix < result.Width; ix++)
            {
                for (int iy = 0; iy < result.Height; iy++)
                {
                        Color pixel = source.GetPixel(ix, iy);

                        if (pixel.A == 0) continue;

                        ColorRGB pixelEX = new ColorRGB(pixel);

                        pixelEX = TransformColor(pixelEX);
                        pixelEX.A = (byte)Coerce(pixel.A * m_aa, 0, 255);
                        result.SetPixel(ix, iy, pixelEX);
                }
            }

            return result;
        }
コード例 #33
0
 public ColorRGB TransformColor(ColorRGB source)
 {
     if (source.H > m_baseColor.H + m_step || source.H < m_baseColor.H - m_step)
         return source;
     else
         return ColorRGB.FromHSLA(
                     Adjust(source.H, HA, m_hm),
                     Adjust(source.S, SA, m_sm),
                     Adjust(source.L, LA, m_lm),
                     source.A);
 }
コード例 #34
0
        protected internal unsafe Bitmap ComputeAlpha(Bitmap source, out Bitmap alpha)
        {
            int width = source.Width;
            int height = source.Height;
            alpha = new Bitmap(width, height);
            Bitmap img = new Bitmap(width, height);

            BitmapData imgBitmapData = img.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb
            );
            BitmapData alphaBitmapData = alpha.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb
            );

            BitmapData sourceBitmapData = source.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb
            );

            ColorRGB* imgStartingPosition = (ColorRGB*)imgBitmapData.Scan0;
            ColorARGB* sourceStartingPosition = (ColorARGB*)sourceBitmapData.Scan0;
            ColorARGB* alphaStartingPosition = (ColorARGB*)alphaBitmapData.Scan0;


            for (int i = 0; i < height; i++)
                for (int j = 0; j < width; j++)
                {
                    ColorARGB* sourcePosition = sourceStartingPosition + j + i * width;
                    ColorARGB* alphaPosition = alphaStartingPosition + j + i * width;
                    ColorRGB* imgPosition = imgStartingPosition + j + i * width;
                    *imgPosition = new ColorRGB(sourcePosition);
                    *alphaPosition = new ColorARGB(255, sourcePosition->A, sourcePosition->A, sourcePosition->A);
                }
            try
            {
                img.UnlockBits(imgBitmapData);
                alpha.UnlockBits(alphaBitmapData);
                source.UnlockBits(sourceBitmapData);
                return img;
            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return new Bitmap(new MemoryStream(this.rawData));
            }
        }
コード例 #35
0
ファイル: Pintar.cs プロジェクト: Nilphy/6671sistemasgraficos
 private static void pintar(int xInicial, int xFinal, int y, ColorRGB color)
 {
     Gl.glBegin(Gl.GL_LINES);
     Gl.glColor3f(color.Red, color.Green, color.Blue);
     //desde xInicial+1 para no pintar el borde
     int x = xInicial + 1;
     //hasta xFinal-1 para no pintar el borde
     while (x < xFinal)
     {
         Gl.glVertex2i(x, y);
         x++;
     }
     Gl.glEnd();
 }
コード例 #36
0
ファイル: Project.cs プロジェクト: ivynetca/lapsestudio
        private void BrCalc_Advanced()
        {
            #region Variables

            BitmapEx bmp1, bmp2, bmp3;
            const int min = 5;
            const int max = 250;

            bmp1 = GetThumb(0, true);

            int isdark, xS, yS;
            const uint ThumbWidth = 300;
            const uint ThumbHeight = 200;
            uint x, y, rowstride, n = bmp1.ChannelCount;
            long index, count;
            double br1, br2, br3, newBr, maxiBrDiff;

            double[,] BrightChangeMask = new double[ThumbWidth, ThumbHeight];
            bool[,] NonUseMask = new bool[ThumbWidth, ThumbHeight];
            double[][] PixelBrightness = new double[ThumbWidth * ThumbHeight][];

            ColorRGB c;

            #endregion

            //TODO: make calculation parallel

            for (int f = 0; f < Frames.Count; f += 2)
            {
                if (MainWorker.CancellationPending) { return; }

                #region Variables

                if (f == 0) { f++; }
                if (f + 2 >= Frames.Count) { f = Frames.Count - 2; }

                bmp1 = GetThumb(f - 1, false).Scale(ThumbWidth, ThumbHeight);
                bmp2 = GetThumb(f, false).Scale(ThumbWidth, ThumbHeight);
                bmp3 = GetThumb(f + 1, false).Scale(ThumbWidth, ThumbHeight);
                rowstride = bmp1.Stride;

                n = bmp1.ChannelCount;
                index = count = isdark = 0;
                br1 = br2 = br3 = newBr = maxiBrDiff = 0;
                RGBSpace space = new RGBColorspacesRGB();

                #endregion

                unsafe
                {
                    bmp1.LockBits();
                    bmp2.LockBits();
                    bmp3.LockBits();

                    byte* pix1 = (byte*)bmp1.Scan0;
                    byte* pix2 = (byte*)bmp2.Scan0;
                    byte* pix3 = (byte*)bmp3.Scan0;

                    #region Mask

                    for (y = 0; y < ThumbHeight; y++)
                    {
                        for (x = 0; x < rowstride; x += n)
                        {
                            index = y * rowstride + x;

                            c = new ColorRGB(pix1[index], pix1[index + 1], pix1[index + 2], space);
                            fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
                            br1 = (c.R + c.G + c.B) * 255d / 3d;
                            c = new ColorRGB(pix2[index], pix2[index + 1], pix2[index + 2], space);
                            fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
                            br2 = (c.R + c.G + c.B) * 255d / 3d;
                            c = new ColorRGB(pix3[index], pix3[index + 1], pix3[index + 2], space);
                            fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
                            br3 = (c.R + c.G + c.B) * 255d / 3d;

                            if (br1 > min && br2 > min && br3 > min && br1 < max && br2 < max && br3 < max) { NonUseMask[x / n, y] = false; }
                            else { NonUseMask[x / n, y] = true; }
                        }
                    }

                    List<double> brightnessDiff1;
                    List<double> brightnessDiff2;

                    for (y = 0; y < ThumbHeight; y++)
                    {
                        for (x = 0; x < bmp1.Stride; x += n)
                        {
                            if (NonUseMask[x / n, y] == false)
                            {
                                count = 0;
                                brightnessDiff1 = new List<double>();
                                brightnessDiff2 = new List<double>();

                                for (yS = -1; yS <= 1; yS++)
                                {
                                    if (y + yS < ThumbHeight && y + yS >= 0)
                                    {
                                        for (xS = -1; xS <= 1; xS++)
                                        {
                                            if (x + xS < rowstride && x + xS >= 0)
                                            {
                                                if (NonUseMask[(x + xS) / n, y + yS] == false)
                                                {
                                                    index = (y + yS) * rowstride + x + xS;

                                                    c = new ColorRGB(pix1[index], pix1[index + 1], pix1[index + 2], space);
                                                    fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
                                                    br1 = (c.R + c.G + c.B) * 255d / 3d;
                                                    c = new ColorRGB(pix2[index], pix2[index + 1], pix2[index + 2], space);
                                                    fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
                                                    br2 = (c.R + c.G + c.B) * 255d / 3d;
                                                    c = new ColorRGB(pix3[index], pix3[index + 1], pix3[index + 2], space);
                                                    fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
                                                    br3 = (c.R + c.G + c.B) * 255d / 3d;

                                                    brightnessDiff1.Add(Math.Abs(br1 - br2));
                                                    brightnessDiff2.Add(Math.Abs(br2 - br3));

                                                    count++;
                                                }
                                            }
                                        }
                                    }
                                }

                                if (count > 0) { BrightChangeMask[x / n, y] = Math.Max(brightnessDiff1.Average(), brightnessDiff2.Average()); }
                                else { BrightChangeMask[x / n, y] = 0; }

                                if (maxiBrDiff < BrightChangeMask[x / n, y]) { maxiBrDiff = BrightChangeMask[x / n, y]; }
                            }
                            else { BrightChangeMask[x / n, y] = 0; }
                        }
                    }
                    bmp1.UnlockBits();
                    bmp2.UnlockBits();
                    bmp3.UnlockBits();

                    for (y = 0; y < ThumbHeight; y++)
                    {
                        for (x = 0; x < ThumbWidth; x++)
                        {
                            if (NonUseMask[x, y] == false)
                            {
                                if (maxiBrDiff > 0)
                                {
                                    newBr = (BrightChangeMask[x, y] * 100) / maxiBrDiff;
                                    if (newBr > 100) { newBr = 100; }
                                    BrightChangeMask[x, y] = Math.Abs(newBr - 100);
                                }
                                else { BrightChangeMask[x, y] = 100; }
                            }
                            else { BrightChangeMask[x, y] = 0; }

                            if (BrightChangeMask[x, y] < 0.5) { isdark++; }
                        }
                    }

                    if ((isdark * 100) / (ThumbHeight * ThumbWidth) > 97) { throw new ImageTooDarkException(); }
                    if (this.GetType() == typeof(ProjectLS)) { ((FrameLS)Frames[f]).UsageMask = BrightChangeMask; }

                    #endregion

                    MainWorker.ReportProgress(0, new ProgressChangeEventArgs((f + 1) * 100 / (Frames.Count - 1), ProgressType.CalculateBrightness));

                    #region Brightness

                    count = 0;

                    for (y = 0; y < ThumbHeight; y++)
                    {
                        for (x = 0; x < rowstride; x += n)
                        {
                            index = y * rowstride + x;
                            c = new ColorRGB(pix1[index], pix1[index + 1], pix1[index + 2], space);
                            fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
                            br1 = (c.R + c.G + c.B) * 255d / 3d;
                            c = new ColorRGB(pix2[index], pix2[index + 1], pix2[index + 2], space);
                            fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
                            br2 = (c.R + c.G + c.B) * 255d / 3d;
                            c = new ColorRGB(pix3[index], pix3[index + 1], pix3[index + 2], space);
                            fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
                            br3 = (c.R + c.G + c.B) * 255d / 3d;

                            double factor = BrightChangeMask[x / n, y] / 100;
                            PixelBrightness[count] = new double[3] { br1 * factor, br2 * factor, br3 * factor };
                            count++;
                        }
                    }

                    double val0 = (PixelBrightness.Average(p => p[0]));
                    double val1 = (PixelBrightness.Average(p => p[1]));
                    double val2 = (PixelBrightness.Average(p => p[2]));

                    if (f == 1) { Frames[0].OriginalBrightness = val0; }
                    double val1P = (val1 * 100) / val0;
                    Frames[f].OriginalBrightness = (Frames[f - 1].OriginalBrightness * val1P) / 100;
                    double val2P = (val2 * 100) / val0;
                    Frames[f + 1].OriginalBrightness = (Frames[f - 1].OriginalBrightness * val2P) / 100;

                    Frames[f - 1].AlternativeBrightness = Frames[f - 1].OriginalBrightness;
                    Frames[f].AlternativeBrightness = Frames[f].OriginalBrightness;
                    Frames[f + 1].AlternativeBrightness = Frames[f + 1].OriginalBrightness;

                    Frames[f - 1].NewBrightness = Frames[f - 1].OriginalBrightness;
                    Frames[f].NewBrightness = Frames[f].OriginalBrightness;
                    Frames[f + 1].NewBrightness = Frames[f + 1].OriginalBrightness;

                    #endregion
                }
            }

            //LTODO: write statistic/BV-value check
            #region Statistics/BV-Values Check

            /*Status = CalcState.Statistics;

                for (int f = 1; f < filecount; f++)
                {
                    if (AllFiles[f].HasExif)
                    {
                        double EvP = (Math.Min(AllFiles[f].Brightness, AllFiles[f - 1].Brightness) * 100) / Math.Max(AllFiles[f].Brightness, AllFiles[f - 1].Brightness);
                        double bv1 = Math.Abs(AllFiles[f - 1].Bv);
                        double bv2 = Math.Abs(AllFiles[f].Bv);
                        double BvP = (Math.Min(bv1, bv2) * 100) / Math.Max(bv1, bv2);
                        if (bv1 < bv2) { BvP *= -1; }
                        double res = BvP - EvP;
                        if (AllFiles[f].Brightness < AllFiles[f - 1].Brightness) { res *= -1; }
                        AllFiles[f].StatisticalError = res;
                    }
                    else
                    {
                        //do statistical check
                    }

                    CalcWorker[0].ReportProgress((int)((((double)f / (double)filecount)) * 100f), Status);
                }*/

            #endregion Statistics/BV-Values Check
        }
コード例 #37
0
ファイル: Project.cs プロジェクト: ivynetca/lapsestudio
        protected virtual void ThumbProcessing()
        {
            double ld = Math.Log(2);
            long index = 0;
            ColorRGB crgb = new ColorRGB(new RGBColorspacesRGB());
            ColorLab cl = new ColorLab();
            ConversionRoutine routLab = ColorConverter.FindRoutine(crgb, cl);
            ConversionRoutine routRGB = ColorConverter.FindRoutine(cl, crgb);
            BitmapEx bmp, bmpE;

            using (ColorConverter Converter = new ColorConverter())
            {
                for (int i = 0; i < Frames.Count; i++)
                {
                    double exposure = Math.Log(Frames[i].NewBrightness / Frames[i].AlternativeBrightness, 2);
                    bmp = GetThumb(i, false);
                    bmpE = GetThumbEdited(i, false);

                    unsafe
                    {
                        bmp.LockBits();
                        bmpE.LockBits();
                        byte* pix1 = (byte*)bmp.Scan0;
                        byte* pix2 = (byte*)bmpE.Scan0;

                        for (uint y = 0; y < bmp.Height; y++)
                        {
                            for (uint x = 0; x < bmp.Stride; x += bmp.ChannelCount)
                            {
                                index = y * bmp.Stride + x;

                                //LTODO: doesn't calculate correctly
                                crgb.R = pix1[index] / 255d; crgb.G = pix1[index + 1] / 255d; crgb.B = pix1[index + 2] / 255d;
                                Converter.Convert(crgb, cl, routLab);
                                if (exposure < 0) { cl.L = (cl.L < 0.94) ? cl.L : Math.Exp(exposure * ld) * cl.L; }
                                else if (exposure > 0) { cl.L = (cl.L > 0.06) ? cl.L : Math.Exp(exposure * ld) * cl.L; }
                                Converter.Convert(cl, crgb, routRGB);

                                pix2[index] = (byte)(crgb.R * byte.MaxValue);
                                pix2[index + 1] = (byte)(crgb.G * byte.MaxValue);
                                pix2[index + 2] = (byte)(crgb.B * byte.MaxValue);
                            }
                        }
                        bmp.UnlockBits();
                        bmpE.UnlockBits();
                    }

                    SetThumbEdited(i, bmpE);
                    MainWorker.ReportProgress(0, new ProgressChangeEventArgs(i * 100 / (Frames.Count - 1), ProgressType.ProcessingThumbs));
                }
            }
        }
コード例 #38
0
ファイル: ProjectLS.cs プロジェクト: ivynetca/lapsestudio
 private unsafe void BaseProcess(ColorRGB c, double exposure)
 {
     //TODO: Make processing better (highlight and dark preserve)
     fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToLinear(pt, pt); }
     c.R = Math.Exp(exposure * ln2) * c.R;
     c.G = Math.Exp(exposure * ln2) * c.G;
     c.B = Math.Exp(exposure * ln2) * c.B;
     fixed (double* pt = c.ValueArray) { ((RGBSpace)c.Space).ToNonLinear(pt, pt); }
 }
コード例 #39
0
ファイル: ProjectLS.cs プロジェクト: ivynetca/lapsestudio
        private Bitmap Process8bit(ref Bitmap input, double exposure, RGBSpace cspace)
        {
            int index, factor;
            if (input.PixelFormat == PixelFormat.Format24bppRgb) { factor = 3; }
            else { factor = 4; }

            Bitmap output = (Bitmap)input.Clone();
            System.Drawing.Rectangle rec = new System.Drawing.Rectangle(0, 0, input.Width, input.Height);
            BitmapData bmdIn = input.LockBits(rec, ImageLockMode.ReadOnly, input.PixelFormat);
            BitmapData bmdOut = output.LockBits(rec, ImageLockMode.ReadOnly, output.PixelFormat);

            unsafe
            {
                for (int y = 0; y < input.Height; y++)
                {
                    byte* row1 = (byte*)bmdIn.Scan0 + (y * bmdIn.Stride);
                    byte* row2 = (byte*)bmdOut.Scan0 + (y * bmdOut.Stride);

                    for (int x = 0; x < input.Width; x++)
                    {
                        index = x * factor;
                        ColorRGB c = new ColorRGB(row1[index + 2], row1[index + 1], row1[index], cspace);
                        BaseProcess(c, exposure);

                        row2[index + 2] = (byte)(c.R * byte.MaxValue);
                        row2[index + 1] = (byte)(c.G * byte.MaxValue);
                        row2[index] = (byte)(c.B * byte.MaxValue);
                    }
                }

            }
            input.UnlockBits(bmdIn);
            output.UnlockBits(bmdOut);
            return output;
        }
コード例 #40
0
ファイル: Progress2.cs プロジェクト: jeyboy/downloader
            // Given a Color (RGB Struct) in range of 0-255
            // Return H,S,L in range of 0-1
            public static void RGB2HSL(ColorRGB rgb, out double h, out double s, out double l)
            {
                double r = rgb.R / 255.0;
                double g = rgb.G / 255.0;
                double b = rgb.B / 255.0;
                double v;
                double m;
                double vm;
                double r2, g2, b2;

                h = 0; // default to black
                s = 0;
                l = 0;

                v = Math.Max(r, g);
                v = Math.Max(v, b);

                m = Math.Min(r, g);
                m = Math.Min(m, b);

                l = (m + v) / 2.0;

                if (l <= 0.0)
                    return;

                vm = v - m;
                s = vm;

                if (s > 0.0)
                    s /= (l <= 0.5) ? (v + m) : (2.0 - v - m);
                else
                    return;

                r2 = (v - r) / vm;
                g2 = (v - g) / vm;
                b2 = (v - b) / vm;

                if (r == v)
                    h = (g == m ? 5.0 + b2 : 1.0 - g2);
                else if (g == v)
                    h = (b == m ? 1.0 + r2 : 3.0 - b2);
                else
                    h = (r == m ? 3.0 + g2 : 5.0 - r2);

                h /= 6.0;
            }
コード例 #41
0
ファイル: Project.cs プロジェクト: ivynetca/lapsestudio
        private void BrCalc_Lab()
        {
            BitmapEx bmp1, bmp2, bmp3;
            const int min = 5;
            const int max = 95;

            bmp1 = GetThumb(0, true);

            const uint ThumbWidth = 300;
            const uint ThumbHeight = 200;
            uint rowstride;
            int n = bmp1.ChannelCount;

            long index = 0;
            uint x, y;
            int x1, y1, maxCol = 8;
            double fact, d1, d2;
            List<double[]> PixelBrightness;
            bool[,] NonUseMask = new bool[ThumbWidth, ThumbHeight];

            using (ColorConverter Converter = new ColorConverter())
            {
                ColorLab[,] labimg1 = new ColorLab[ThumbWidth, ThumbHeight];
                ColorLab[,] labimg2 = new ColorLab[ThumbWidth, ThumbHeight];
                ColorLab[,] labimg3 = new ColorLab[ThumbWidth, ThumbHeight];
                ColorRGB colrgb = new ColorRGB(new RGBColorspacesRGB());
                ConversionRoutine rout = ColorConverter.FindRoutine(colrgb, labimg1[0, 0]);

                for (int f = 1; f < Frames.Count; f += 2)
                {
                    if (MainWorker.CancellationPending) { return; }

                    if (f + 2 >= Frames.Count) { f = Frames.Count - 2; }

                    bmp1 = GetThumb(f - 1, false).Scale(ThumbWidth, ThumbHeight);
                    bmp2 = GetThumb(f, false).Scale(ThumbWidth, ThumbHeight);
                    bmp3 = GetThumb(f + 1, false).Scale(ThumbWidth, ThumbHeight);
                    rowstride = bmp1.Stride;

                    unsafe
                    {
                        bmp1.LockBits();
                        bmp2.LockBits();
                        bmp3.LockBits();

                        byte* pix1 = (byte*)bmp1.Scan0;
                        byte* pix2 = (byte*)bmp2.Scan0;
                        byte* pix3 = (byte*)bmp3.Scan0;

                        //Non use Mask and Lab conversion
                        for (y = 0; y < ThumbHeight; y++)
                        {
                            for (x = 0; x < ThumbWidth; x++)
                            {
                                index = y * rowstride + (x * n);

                                colrgb.R = pix1[index];
                                colrgb.G = pix1[index + 1];
                                colrgb.B = pix1[index + 2];
                                Converter.Convert(colrgb, labimg1[x, y], rout);
                                colrgb.R = pix2[index];
                                colrgb.G = pix2[index + 1];
                                colrgb.B = pix2[index + 2];
                                Converter.Convert(colrgb, labimg2[x, y], rout);
                                colrgb.R = pix3[index];
                                colrgb.G = pix3[index + 1];
                                colrgb.B = pix3[index + 2];
                                Converter.Convert(colrgb, labimg3[x, y], rout);

                                if (labimg1[x, y].L < min || labimg1[x, y].L > max || labimg2[x, y].L < min || labimg2[x, y].L > max || labimg3[x, y].L < min || labimg3[x, y].L > max ||
                                    Math.Abs(labimg2[x, y].a - labimg1[x, y].a) > maxCol || Math.Abs(labimg3[x, y].a - labimg2[x, y].a) > maxCol ||
                                    Math.Abs(labimg2[x, y].b - labimg1[x, y].b) > maxCol || Math.Abs(labimg3[x, y].b - labimg2[x, y].b) > maxCol)
                                {
                                    NonUseMask[x, y] = true;
                                }
                            }
                        }
                        bmp1.UnlockBits();
                        bmp2.UnlockBits();
                        bmp3.UnlockBits();
                    }

                    PixelBrightness = new List<double[]>();

                    //Brightness calculation
                    for (y = 0; y < ThumbHeight; y++)
                    {
                        for (x = 0; x < ThumbWidth; x++)
                        {
                            if (!NonUseMask[x, y])
                            {
                                fact = 0;
                                if (y > 0 && x > 0 && y < ThumbHeight - 1 && x < ThumbWidth - 1)
                                {
                                    d1 = 0;
                                    d2 = 0;
                                    for (y1 = -1; y1 <= 1; y1++)
                                    {
                                        for (x1 = -1; x1 <= 1; x1++)
                                        {
                                            d1 += Math.Abs(labimg1[x, y].L - labimg2[x, y].L);
                                            d2 += Math.Abs(labimg2[x, y].L - labimg3[x, y].L);
                                        }
                                    }
                                    fact = Math.Max(d1 / 9d, d2 / 9d);
                                }
                                if (fact > 0.2) PixelBrightness.Add(new double[] { fact * Math.Log(labimg1[x, y].L), fact * Math.Log(labimg2[x, y].L), fact * Math.Log(labimg3[x, y].L) });
                            }
                        }
                    }

                    Frames[f - 1].OriginalBrightness = PixelBrightness.Average(p => p[0]);
                    Frames[f].OriginalBrightness = PixelBrightness.Average(p => p[1]);
                    Frames[f + 1].OriginalBrightness = PixelBrightness.Average(p => p[2]);

                    Frames[f - 1].AlternativeBrightness = Frames[f - 1].OriginalBrightness;
                    Frames[f].AlternativeBrightness = Frames[f].OriginalBrightness;
                    Frames[f + 1].AlternativeBrightness = Frames[f + 1].OriginalBrightness;

                    Frames[f - 1].NewBrightness = Frames[f - 1].OriginalBrightness;
                    Frames[f].NewBrightness = Frames[f].OriginalBrightness;
                    Frames[f + 1].NewBrightness = Frames[f + 1].OriginalBrightness;

                    MainWorker.ReportProgress(0, new ProgressChangeEventArgs(f * 100 / (Frames.Count - 1), ProgressType.CalculateBrightness));
                }
            }
        }
コード例 #42
0
ファイル: Color.cs プロジェクト: sladen/openbve2
 /// <summary>Creates a new instance of this structure.</summary>
 /// <param name="color">The base color.</param>
 /// <param name="alpha">The alpha component.</param>
 public ColorRGBA(ColorRGB color, float alpha)
 {
     this.R = color.R;
     this.G = color.G;
     this.B = color.B;
     this.A = alpha;
 }