Exemplo n.º 1
0
        internal void Init(DnaDrawing drawing, JobInfo info)
        {
            Points = new List <DnaPoint>();

            //int count = info.GetRandomNumber(3, 3);
            var origin = new DnaPoint();

            origin.Init(drawing, info);

            if (drawing.Polygons.Count < 1)
            {
                origin.X = info.SourceImage.Width / 2;
                origin.Y = info.SourceImage.Height / 2;
            }

            for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++)
            {
                var point = new DnaPoint
                {
                    X =
                        Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)),
                                 info.SourceImage.Width),
                    Y =
                        Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)),
                                 info.SourceImage.Height)
                };

                Points.Add(point);
            }

            Brush = new DnaBrush();
            Brush.Init(info);
        }
Exemplo n.º 2
0
        internal void Init(DnaDrawing drawing, JobInfo info)
        {
            Points = new List<DnaPoint>();

            //int count = info.GetRandomNumber(3, 3);
            var origin = new DnaPoint();
            origin.Init(drawing, info);

            if (drawing.Polygons.Count < 1)
            {
                origin.X = info.SourceImage.Width / 2;
                origin.Y = info.SourceImage.Height / 2;
            }

            for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++)
            {
                var point = new DnaPoint
                                {
                                    X =
                                        Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)),
                                                 info.SourceImage.Width),
                                    Y =
                                        Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)),
                                                 info.SourceImage.Height)
                                };

                Points.Add(point);
            }

            Brush = new DnaBrush();
            Brush.Init(info);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Convert a DnaBrush to a System.Windows.Media.SolidColorBrush
 /// </summary>
 private static SolidColorBrush GetSolidColorBrush(DnaBrush b)
 {
     return new SolidColorBrush(Color.FromArgb(
           Convert.ToByte(b.Alpha)
         , Convert.ToByte(b.Red)
         , Convert.ToByte(b.Green)
         , Convert.ToByte(b.Blue)));
 }
Exemplo n.º 4
0
        //Convert a DnaBrush to a System.Drawing.Brush
        private static Brush GetGdiBrush(DnaBrush b)
        {
            //var pb = new PathGradientBrush(points);
            //pb.CenterColor = Color.FromArgb(b.Alpha, b.Red, b.Green, b.Blue);
            //pb.SurroundColors = new Color[] {Color.Transparent};

            //return pb;

            return new SolidBrush(Color.FromArgb(b.Alpha, b.Red, b.Green, b.Blue));
        }
Exemplo n.º 5
0
        public void Init()
        {
            Center = new DnaPoint();
            Center.Init();

            // TODO: Test random number
            Radius = Tools.GetRandomNumber(0, Tools.MaxWidth);

            Brush = new DnaBrush();
            Brush.Init();
        }
Exemplo n.º 6
0
        public void Init(DnaDrawing drawing, JobInfo info)
        {
            Points = new List <DnaPoint>();

            //int count = info.GetRandomNumber(3, 3);
            var origin = new DnaPoint();

            origin.Init(drawing, info);

            if (drawing.Polygons.Count < 1)
            {
                origin.X = info.SourceImage.Width / 2;
                origin.Y = info.SourceImage.Height / 2;
            }

            for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++)
            {
                var point = new DnaPoint
                {
                    X =
                        Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)),
                                 info.SourceImage.Width),
                    Y =
                        Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)),
                                 info.SourceImage.Height)
                };

                Points.Add(point);
            }

            bool findNew = true;

            if (info.Settings.MuteCurvePolygon &&
                info.Settings.MuteLinePolygon &&
                info.Settings.MuteCurveFillPolygon &&
                info.Settings.MuteLineFillPolygon)
            {
                findNew = false;
            }

            Width = info.GetRandomNumber(1, 8);

            while (findNew)
            {
                bool splines = (info.GetRandomNumber(0, 2) == 1) ? true : false;
                bool filled  = (info.GetRandomNumber(0, 2) == 1) ? true : false;
                findNew = !SetSplinesAndFilled(info.Settings, splines, filled);
            }

            Brush = new DnaBrush();
            Brush.Init(info);
        }
Exemplo n.º 7
0
        public void Init(DnaDrawing drawing, JobInfo info)
        {
            Points = new List<DnaPoint>();

            //int count = info.GetRandomNumber(3, 3);
            var origin = new DnaPoint();
            origin.Init(drawing, info);

            if (drawing.Polygons.Count < 1)
            {
                origin.X = info.SourceImage.Width / 2;
                origin.Y = info.SourceImage.Height / 2;
            }

            for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++)
            {
                var point = new DnaPoint
                                {
                                    X =
                                        Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)),
                                                 info.SourceImage.Width),
                                    Y =
                                        Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)),
                                                 info.SourceImage.Height)
                                };

                Points.Add(point);
            }

            bool findNew = true;

            if (info.Settings.MuteCurvePolygon &&
                info.Settings.MuteLinePolygon &&
                info.Settings.MuteCurveFillPolygon &&
                info.Settings.MuteLineFillPolygon)
                findNew = false;

            Width = info.GetRandomNumber(1, 8);

            while (findNew)
            {
                bool splines = (info.GetRandomNumber(0, 2) == 1) ? true : false;
                bool filled = (info.GetRandomNumber(0, 2) == 1) ? true : false;
                findNew = !SetSplinesAndFilled(info.Settings, splines, filled);
            }

            Brush = new DnaBrush();
            Brush.Init(info);
        }
Exemplo n.º 8
0
        public void Init()
        {
            Points = new List <DnaPoint>();
            //int count = Tools.GetRandomNumber(3, 3);
            var origin = new DnaPoint();

            origin.Init();

            for (int i = 0; i < Settings.ActivePointsPerPolygonMin; i++)
            {
                var point = new DnaPoint();
                point.X = Math.Min(Math.Max(0, origin.X + Tools.GetRandomNumber(-3, 3)), Tools.MaxWidth);
                point.Y = Math.Min(Math.Max(0, origin.Y + Tools.GetRandomNumber(-3, 3)), Tools.MaxHeight);
                Points.Add(point);
            }

            Brush = new DnaBrush();
            Brush.Init();
        }
Exemplo n.º 9
0
        public void Init()
        {
            Points = new List<DnaPoint>();

            //int count = Tools.GetRandomNumber(3, 3);
            var origin = new DnaPoint();
            origin.Init();

            for (int i = 0; i < Settings.ActivePointsPerPolygonMin; i++)
            {
                var point = new DnaPoint();
                point.X = Math.Min(Math.Max(0, origin.X + Tools.GetRandomNumber(-3, 3)), Tools.MaxWidth);
                point.Y = Math.Min(Math.Max(0, origin.Y + Tools.GetRandomNumber(-3, 3)), Tools.MaxHeight);

                Points.Add(point);
            }

            Brush = new DnaBrush();
            Brush.Init();
        }
Exemplo n.º 10
0
        public void Init()
        {
            Points = new List<DnaPoint>();

            //int count = Tools.GetRandomNumber(3, 3);
            var origin = new DnaPoint();
            origin.Init();

            for (int i = 0; i < Settings.ActivePointsPerPolygonMin; i++) //adds the minimum (3) number of points to the polygon, and gives them random positions
            {
                var point = new DnaPoint();
                point.X = Math.Min(Math.Max(0, origin.X + Tools.GetRandomNumber(-3, 3)), Tools.MaxWidth);
                point.Y = Math.Min(Math.Max(0, origin.Y + Tools.GetRandomNumber(-3, 3)), Tools.MaxHeight);

                Points.Add(point);
            }

            Brush = new DnaBrush(); //gives the shape some colour
            Brush.Init();
        }
Exemplo n.º 11
0
 //Convert a DnaBrush to a System.Drawing.Brush
 private static Brush GetGdiBrush(DnaBrush b)
 {
     return new SolidBrush(Color.FromArgb(b.Alpha, b.Red, b.Green, b.Blue));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Convert a DnaBrush to a System.Windows.Media.SolidColorBrush
 /// </summary>
 private static string GetColorString(DnaBrush b)
 {
     return "#" + b.Alpha.ToString("X").PadLeft(2, '0') + b.Red.ToString("X").PadLeft(2, '0') + b.Green.ToString("X").PadLeft(2, '0') + b.Blue.ToString("X").PadLeft(2, '0');
 }
Exemplo n.º 13
0
 /// <summary>
 /// Convert a DnaBrush to a System.Windows.Media.SolidColorBrush
 /// </summary>
 private static string GetOpacityString(DnaBrush b)
 {
     return (b.Alpha / 256.0).ToString();
 }
        public void decompress()
        {
            QuickLZ qlz = new QuickLZ();
            byte[] decompressed = qlz.Decompress(File.ReadAllBytes(InputFile));
            Console.WriteLine("dec" + decompressed.Length.ToString());
            BitArray bits = new BitArray(decompressed);
            Console.WriteLine("bits" + bits.Length.ToString());
            int progress = 0;
            BitArray width = new BitArray(16); //Max width
            bitArrayCopy(bits, progress, width, 0, 16);
            Tools.MaxWidth = unwritebits(width); //create maxwidth
            progress += 16;
            BitArray height = new BitArray(16); //Max height
            bitArrayCopy(bits, progress, height, 0, 16);
            Tools.MaxHeight = unwritebits(height); //create maxheight
            progress += 16;
            BitArray avgreds = new BitArray(8); //red colour average
            bitArrayCopy(bits, progress, avgreds, 0, 8);
            int avgred = unwritebits(avgreds);
            progress += 8;
            BitArray avggreens = new BitArray(8); //green colour average
            bitArrayCopy(bits, progress, avggreens, 0, 8);
            int avggreen = unwritebits(avggreens);
            progress += 8;
            BitArray avgblues = new BitArray(8); //blue colour average
            bitArrayCopy(bits, progress, avgblues, 0, 8);
            int avgblue = unwritebits(avgblues);
            progress += 8;
            Tools.avgColour = System.Drawing.Color.FromArgb(avgred, avggreen, avgblue); //create average colour
            DnaDrawing newDrawing = new DnaDrawing(); //Create dnadrawing
            //newDrawing.Init();
            BitArray polynumbers = new BitArray(10); //number of polygons
            bitArrayCopy(bits, progress, polynumbers, 0, 10);
            int polynumber = unwritebits(polynumbers);
            progress += 10;
            newDrawing.Polygons = new List<DnaPolygon>();
            for (int i = 0; i < polynumber; i++)
            {
                Console.WriteLine(i);
                DnaPolygon polygon = new DnaPolygon(); //create dnapolygon
                polygon.Points = new List<DnaPoint>();
                BitArray pointnumbers = new BitArray(5); //number of points
                bitArrayCopy(bits, progress, pointnumbers, 0, 5);
                int pointnumber = unwritebits(pointnumbers);
                progress += 5;
                BitArray alphas = new BitArray(8); //alpha colour
                bitArrayCopy(bits, progress, alphas, 0, 8);
                int alpha = unwritebits(alphas);
                progress += 8;
                BitArray reds = new BitArray(8); //red colour
                bitArrayCopy(bits, progress, reds, 0, 8);
                int red = unwritebits(reds);
                progress += 8;
                BitArray greens = new BitArray(8); //green colour
                bitArrayCopy(bits, progress, greens, 0, 8);
                int green = unwritebits(greens);
                progress += 8;
                BitArray blues = new BitArray(8); //blue colour
                bitArrayCopy(bits, progress, blues, 0, 8);
                int blue = unwritebits(blues);
                progress += 8;
                DnaBrush brush = new DnaBrush(); //create dnabrush
                brush.Alpha=alpha;
                brush.Red = red;
                brush.Green = green;
                brush.Blue=blue;
                polygon.Brush=brush; //assign brush
                for (int j = 0; j < pointnumber; j++)
                {
                    DnaPoint point = new DnaPoint();
                    BitArray Xs = new BitArray(12); //x position
                    bitArrayCopy(bits, progress, Xs, 0, 12);
                    int x = unwritebits(Xs);
                    progress += 12;
                    point.X = x;
                    BitArray Ys = new BitArray(12); //y position
                    bitArrayCopy(bits, progress, Ys, 0, 12);
                    int y = unwritebits(Ys);
                    progress += 12;
                    point.Y = y;
                    polygon.Points.Add(point);
                }
                newDrawing.Polygons.Add(polygon);
            }
            int[,] DiffArray = new int[Tools.MaxWidth * Tools.MaxWidth, 4];
            int[,] refArray = new int[Tools.MaxWidth * Tools.MaxWidth, 5];
            for (int i = 0; i < Tools.MaxWidth * Tools.MaxWidth; i++)
            {
                BitArray firsts = new BitArray(1); //normal or reference
                bitArrayCopy(bits, progress, firsts, 0, 1);
                int first = unwritebits(firsts);
                progress += 1;
                if (first == 1)
                {
                    BitArray reffs = new BitArray(11); //reference number
                    bitArrayCopy(bits, progress, reffs, 0, 11);
                    int reff = unwritebits(reffs);
                    progress += 11;
                    refArray[i,4]=reff;
                }
                else
                {
                    //BitArray asizes = new BitArray(3); //alpha size
                    //bitArrayCopy(bits, progress, asizes, 0, 3);
                    int asize = 9;//unwritebits(asizes);
                    //progress += 3;
                    //BitArray rsizes = new BitArray(3); //red size
                    //bitArrayCopy(bits, progress, rsizes, 0, 3);
                    int rsize = 9;//unwritebits(rsizes);
                    //progress += 3;
                    //BitArray gsizes = new BitArray(3); //green size
                    //bitArrayCopy(bits, progress, gsizes, 0, 3);
                    int gsize = 9;//unwritebits(gsizes);
                    //progress += 3;
                    //BitArray bsizes = new BitArray(3); //blue size
                    //bitArrayCopy(bits, progress, bsizes, 0, 3);
                    int bsize = 9;//unwritebits(bsizes);
                    //progress += 3;

                    BitArray a = new BitArray(asize); //alpha
                    bitArrayCopy(bits, progress, a, 0, asize);
                    int alpha = unwritebits(a);
                    progress += asize;
                    DiffArray[i, 0] = alpha-256;
                    BitArray r = new BitArray(rsize); //red
                    bitArrayCopy(bits, progress, r, 0, rsize);
                    int red = unwritebits(r);
                    progress += rsize;
                    DiffArray[i, 1] = red-256;
                    BitArray g = new BitArray(gsize); //green
                    bitArrayCopy(bits, progress, g, 0, gsize);
                    int green = unwritebits(g);
                    progress += gsize;
                    DiffArray[i, 2] = green-256;
                    BitArray b = new BitArray(bsize); //blue
                    bitArrayCopy(bits, progress, b, 0, bsize);
                    int blue = unwritebits(b);
                    progress += bsize;
                    DiffArray[i, 3] = blue-256;
                }
            }
            //int[,] fullArray = (int[,]) refArray.Clone();
            for (int k = 0; k < refArray.Length / 5; k++)
            {
                if (refArray[k, 4] != 0)
                {
                    DiffArray[k, 0] = refArray[k - refArray[k, 4], 0];
                    DiffArray[k, 1] = refArray[k - refArray[k, 4], 1];
                    DiffArray[k, 2] = refArray[k - refArray[k, 4], 2];
                    DiffArray[k, 3] = refArray[k - refArray[k, 4], 3];
                    Console.WriteLine(refArray[k, 1]);
                }
            }

            Console.WriteLine(newDrawing.Polygons.Count);
            Console.WriteLine("done with drawing");

            Bitmap _bmp;
            Graphics _g;
            _bmp = new System.Drawing.Bitmap(Tools.MaxWidth, Tools.MaxHeight);
            _g = Graphics.FromImage(_bmp);
            Renderer.Render(newDrawing, _g, 1);
            BitmapData bd = _bmp.LockBits(new System.Drawing.Rectangle(0, 0, Tools.MaxWidth, Tools.MaxHeight), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            _bmp.Save("finally.png", System.Drawing.Imaging.ImageFormat.Png);
            _bmp.UnlockBits(bd);

            Bitmap _bmp2 = new System.Drawing.Bitmap(Tools.MaxWidth, Tools.MaxHeight);
            int arraycounter2 = 0;
            for (int y = 0; y < Tools.MaxHeight; y++)
            {
                for (int x = 0; x < Tools.MaxWidth; x++)
                {
                    System.Drawing.Color c1 = _bmp.GetPixel(x, y);
                    int a = c1.A + DiffArray[arraycounter2, 0];
                    int r = c1.R + DiffArray[arraycounter2, 1];
                    int g = c1.G + DiffArray[arraycounter2, 2];
                    int b = c1.B + DiffArray[arraycounter2, 3];
                    System.Drawing.Color c3 = System.Drawing.Color.FromArgb(a, r, g, b);
                    _bmp2.SetPixel(x, y, c3);
                    arraycounter2++;
                }
            }
            _bmp2.Save("success.png", System.Drawing.Imaging.ImageFormat.Png);
            System.Diagnostics.Process.Start(@"success.png");
        }