Example #1
0
        public TopImageStep(int level, int perTile, int tileX, int tileY)
        {
            m_level = level;
            m_perTile = perTile;
            m_tileX = tileX;
            m_tileY = tileY;

            m_bit = new BitBits(256, 256);
            m_bit.Save(Helpers.GetFinal(m_level, m_tileX, m_tileY), false);
        }
Example #2
0
        public static void CopyRect(Rectangle src, Rectangle dest, ComplexData from, BitBits to, bool use48)
        {
            if (from != null && from.Loaded)
            {
                if (src.Width > dest.Width)
                {
                    int xScale = src.Width / dest.Width;
                    int yScale = src.Height / dest.Height;

                    if (Settings.Main_Shrink_AveragePixel)
                    {
                        for (int x = 0; x < src.Width; x += xScale)
                        {
                            for (int y = 0; y < src.Height; y += yScale)
                            {
                                ColorD cd = AvgRange(from, x + src.X, y + src.Y, xScale);
                                Color c = Utils.Dither(cd);
                                if (use48)
                                {
                                    to.Set(x / xScale + dest.X, y / yScale + dest.Y, c, cd);
                                }
                                else
                                {
                                    to.Set(x / xScale + dest.X, y / yScale + dest.Y, c);
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int x = 0; x < src.Width; x += xScale)
                        {
                            for (int y = 0; y < src.Height; y += yScale)
                            {
                                ColorD cd = from.GetPoint(x + src.X, y + src.Y);
                                Color c = Utils.Dither(cd);
                                if (use48)
                                {
                                    to.Set(x / xScale + dest.X, y / yScale + dest.Y, c, cd);
                                }
                                else
                                {
                                    to.Set(x / xScale + dest.X, y / yScale + dest.Y, c);
                                }
                            }
                        }
                    }
                }
                else if (src.Width == dest.Width)
                {
                    for (int x = 0; x < src.Width; x++)
                    {
                        for (int y = 0; y < src.Height; y++)
                        {
                            ColorD cd = from.GetPoint(x + src.X, y + src.Y);
                            Color c = Utils.Dither(cd);
                            if (use48)
                            {
                                to.Set(x + dest.X, y + dest.Y, c, cd);
                            }
                            else
                            {
                                to.Set(x + dest.X, y + dest.Y, c);
                            }
                        }
                    }
                }
                else if (src.Width < dest.Width)
                {
                    int xScale = dest.Width / src.Width;
                    int yScale = dest.Height / src.Height;

                    for (int x = 0; x < src.Width; x++)
                    {
                        for (int y = 0; y < src.Height; y++)
                        {
                            ColorD cd = from.GetPoint(x + src.X, y + src.Y);
                            Color c = Utils.Dither(cd);

                            for (int xOff = 0; xOff < xScale; xOff++)
                            {
                                for (int yOff = 0; yOff < yScale; yOff++)
                                {
                                    if (use48)
                                    {
                                        to.Set(x * xScale + dest.X + xOff, y * yScale + dest.Y + yOff, c, cd);
                                    }
                                    else
                                    {
                                        to.Set(x * xScale + dest.X + xOff, y * yScale + dest.Y + yOff, c);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Color c1 = Color.FromArgb(204, 204, 204);
                Color c2 = Color.FromArgb(255, 255, 255);
                ColorD cd1 = (ColorD)c1;
                ColorD cd2 = (ColorD)c2;

                for (int x = 0; x < dest.Width; x++)
                {
                    for (int y = 0; y < dest.Height; y++)
                    {
                        Color temp;
                        ColorD tempd;

                        if ((((x / 8) % 2) == 0) ^ (((y / 8) % 2) == 0))
                        {
                            temp = c1;
                            tempd = cd1;
                        }
                        else
                        {
                            temp = c2;
                            tempd = cd2;
                        }

                        if (use48)
                        {
                            to.Set(x + dest.X, y + dest.Y, temp, tempd);
                        }
                        else
                        {
                            to.Set(x + dest.X, y + dest.Y, temp);
                        }
                    }
                }
            }
        }
Example #3
0
        static void CreateLargeImage()
        {
            BitBits bit = new BitBits(2048, 2048, false);

            int size = 2048 / Settings.Main_Tiles_PerSide;

            CopyRect(
                new Rectangle(0, 0, 2048, 2048),
                new Rectangle(0, 0, 2048, 2048),
                null, bit, false);

            for (int a = 0; a < Settings.Main_Tiles_PerSide; a++)
            {
                for (int b = 0; b < Settings.Main_Tiles_PerSide; b++)
                {
                    string bitsFile = Helpers.GetBig(a, b, false) + ".bits";
                    if (File.Exists(bitsFile))
                    {
                        MyConsole.WriteLine("Using cache for " + a + " x " + b + " (" + 0 + ")");
                        bit.LoadBits(a * size, b * size, size, size, bitsFile);
                    }
                    else
                    {
                        ComplexData data = new ComplexData(a, b, 0);

                        if (data.Loaded)
                        {
                            BitBits bitBig = null;
                            BitBits bitHuge = null;

                            if (!File.Exists(Helpers.GetBig(a, b, false)))
                            {
                                bitBig = new BitBits(2048, 2048, false);
                                bitHuge = new BitBits(8192, 8192, false);
                            }

                            CopyRect(
                                new Rectangle(0, 0, 8192, 8192),
                                new Rectangle(a * size, b * size, size, size),
                                data,
                                bit, false);

                            bit.SaveBits(a * size, b * size, size, size, bitsFile);

                            if (bitBig != null)
                            {
                                CopyRect(
                                    new Rectangle(0, 0, 8192, 8192),
                                    new Rectangle(0, 0, 2048, 2048),
                                    data,
                                    bitBig, false);

                                bitBig.Save(Helpers.GetBig(a, b, false));

                                if (Settings.Main_Action_DrawFullSizeTiles)
                                {
                                    CopyRect(
                                        new Rectangle(0, 0, 8192, 8192),
                                        new Rectangle(0, 0, 8192, 8192),
                                        data,
                                        bitHuge, false);

                                    bitHuge.Save(Helpers.GetBig(a, b, true));
                                }
                            }

                            bit.Save(Helpers.GetBig(-1, -1, false), false);
                        }
                    }
                }
            }

            bit.Save(Helpers.GetBig(-1, -1, false));
        }
Example #4
0
        static void CreateImages(int a, int b, ComplexData data, int level, int size, int tileOff)
        {
            using (var indent = MyConsole.Indent("Creating level " + (level + 1) + " for " + a + " x " + b))
            {
                for (int tileX = 0; tileX < tileOff; tileX++)
                {
                    for (int tileY = 0; tileY < tileOff; tileY++)
                    {
                        MyConsole.WriteLine("Level " + (level + 1) + " for " + a + " x " + b + ": " + tileX + " x " + tileY);

                        Rectangle src = new Rectangle(tileX * size, tileY * size, size, size);
                        Rectangle dest = new Rectangle(0, 0, 256, 256);

                        BitBits bit = new BitBits(256, 256);

                        CopyRect(src, dest, data, bit, false);

                        bit.Save(Helpers.GetFinal(level, tileX + tileOff * a, tileY + tileOff * b));
                    }
                }
            }
        }
Example #5
0
        static void CopyRect48(Rectangle src, Rectangle dest, ComplexData from, BitBits to)
        {
            if (from.Loaded)
            {
                if (src.Width > dest.Width)
                {
                    int xScale = src.Width / dest.Width;
                    int yScale = src.Height / dest.Height;

                    for (int x = 0; x < src.Width; x += xScale)
                    {
                        for (int y = 0; y < src.Height; y += yScale)
                        {
                            ColorD c = AvgRange48(from, x + src.X, y + src.Y, xScale);
                            to.Set(x / xScale + dest.X, y / yScale + dest.Y, Utils.Dither(c), c);
                        }
                    }
                }
                else if (src.Width == dest.Width)
                {
                    for (int x = 0; x < src.Width; x++)
                    {
                        for (int y = 0; y < src.Height; y++)
                        {
                            ColorD cd = from.GetPoint(x + src.X, y + src.Y);
                            Color c = Utils.Dither(cd);
                            to.Set(x + dest.X, y + dest.Y, c, cd);
                        }
                    }
                }
                else if (src.Width < dest.Width)
                {
                    int xScale = dest.Width / src.Width;
                    int yScale = dest.Height / src.Height;

                    for (int x = 0; x < src.Width; x++)
                    {
                        for (int y = 0; y < src.Height; y++)
                        {
                            ColorD cd = from.GetPoint(x + src.X, y + src.Y);

                            for (int xOff = 0; xOff < xScale; xOff++)
                            {
                                for (int yOff = 0; yOff < yScale; yOff++)
                                {
                                    Color c = Utils.Dither(cd);
                                    to.Set(x * xScale + dest.X + xOff, y * yScale + dest.Y + yOff, c, cd);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Color c1 = Color.FromArgb(204, 204, 204);
                Color c2 = Color.FromArgb(255, 255, 255);

                for (int x = 0; x < dest.Width; x++)
                {
                    for (int y = 0; y < dest.Height; y++)
                    {
                        if ((((x / 8) % 2) == 0) ^ (((y / 8) % 2) == 0))
                        {
                            to.Set(x + dest.X, y + dest.Y, c1, c1);
                        }
                        else
                        {
                            to.Set(x + dest.X, y + dest.Y, c2, c2);
                        }
                    }
                }
            }
        }
Example #6
0
        public static unsafe void MainWorker()
        {
            if (Settings.Test_Run)
            {
                int w = Settings.Test_Width;
                int h = Settings.Test_Height;
                Helpers.Mode = Helpers.Modes.TriBuddha;
                FindLimit(Settings.Test_Source, w, h);
                BitBits bit = new BitBits(w, h, true);
                ComplexData data = ComplexData.LoadFile(Settings.Test_Source, w, h);
                CopyRect48(new Rectangle(0, 0, w, h), new Rectangle(0, 0, w, h), data, bit);

                bit.Save(Settings.Test_Source + "_test_.png");

                Image image = Image.FromFile(Settings.Test_Source + "_test_.png");
                PreviewForm form = new PreviewForm(null, (Bitmap)image);
                Application.Run(form);
            }

            if (Settings.Split_Run)
            {
                Helpers.SplitImage();
            }

            if (Settings.Main_Action_DrawBuddha)
            {
                using (var indent = MyConsole.Indent("Buddhabrot"))
                {
                    Helpers.Mode = Helpers.Modes.Buddha;
                    FindLimit(null, 8192, 8192);
                    MainWorkerInternal();
                }
            }

            if (Settings.Main_Action_DrawTriBuddha)
            {
                using (var indent = MyConsole.Indent("TriBuddha"))
                {
                    Helpers.Mode = Helpers.Modes.TriBuddha;
                    FindLimit(null, 8192, 8192);
                    MainWorkerInternal();
                }
            }

            if (Settings.Main_Action_DrawMandel)
            {
                using (var indent = MyConsole.Indent("Mandelbrot"))
                {
                    Helpers.Mode = Helpers.Modes.Mandel;
                    MainWorkerInternal();
                }
            }
        }
        static void MainWorkerInternal()
        {
            using (var indent = MyConsole.Indent("Creating large image"))
            {
                CreateLargeImage();
            }

            if (Settings.Main_Action_FakeTiles)
            {
                int level = 0;
                int side = 1;
                using (StringFormat format = (StringFormat)StringFormat.GenericDefault.Clone())
                using (Font font = new Font("Tahoma", 15, FontStyle.Regular))
                {
                    format.LineAlignment = StringAlignment.Center;
                    format.Alignment = StringAlignment.Center;

                    while (level < Settings.Main_Tiles_Levels && level <= Settings.Main_Tiles_LevelLimit)
                    {
                        for (int a = 0; a < side; a++)
                        {
                            for (int b = 0; b < side; b++)
                            {
                                MyConsole.WriteLine(level + " - " + a + " x " + b);
                                string file = Helpers.GetFinal(level, a, b);

                                using (Bitmap bitmap = new Bitmap(256, 256, PixelFormat.Format24bppRgb))
                                {
                                    using (Graphics g = Graphics.FromImage(bitmap))
                                    {
                                        g.Clear(Color.White);
                                        g.DrawString(
                                            "Level: " + (level + 1) + "\n" +
                                            a + "x" + b,
                                            font,
                                            Brushes.Black,
                                            new Rectangle(0, 0, 256, 256), format);
                                    }
                                    bitmap.Save(file);
                                }
                            }
                        }

                        level++;
                        side *= 2;
                    }
                }
            }
            else if (!Settings.Main_Action_LargeImageOnly)
            {
                int dim = Settings.Main_Tiles_PerSide * 8192;
                int levels = 1;
                int temp = dim;
                while (temp >= 256)
                {
                    levels++;
                    temp /= 2;
                }

                if (Settings.Main_Tiles_Levels != levels)
                {
                    Console.WriteLine("I calced a different number of levels at " + levels);
                    return;
                }

                int tiles = 1;
                int perTile = Settings.Main_Tiles_PerSide;
                int targetLevel = 0;
                List<TopImageStep> steps = new List<TopImageStep>();
                for (int level = 0; level < levels; level++)
                {
                    foreach (var cur in CreateTopImages(level, tiles, perTile))
                    {
                        if (level < Settings.Main_Tiles_LevelLimit)
                        {
                            steps.Add(cur);
                        }
                    }

                    if (perTile == 2)
                    {
                        targetLevel = level + 1;
                        break;
                    }
                    else
                    {
                        perTile /= 2;
                    }
                    tiles *= 2;
                }

                List<Point> todo = new List<Point>();
                for (int x = 0; x < Settings.Main_Tiles_PerSide; x++)
                {
                    Add(todo, x, x);
                }
                for (int x = 0; x < Settings.Main_Tiles_PerSide; x++)
                {
                    Add(todo, x + 1, x);
                }
                for (int x = 0; x < Settings.Main_Tiles_PerSide; x++)
                {
                    Add(todo, x, 0);
                }
                for (int x = 0; x < Settings.Main_Tiles_PerSide; x++)
                {
                    Add(todo, Settings.Main_Tiles_PerSide - 1, x);
                }
                for (int x = 0; x < Settings.Main_Tiles_PerSide; x++)
                {
                    Add(todo, (Settings.Main_Tiles_PerSide - 1) - x, Settings.Main_Tiles_PerSide - 1);
                }
                for (int x = 0; x < Settings.Main_Tiles_PerSide; x++)
                {
                    Add(todo, 0, (Settings.Main_Tiles_PerSide - 1) - x);
                }
                for (int a = 0; a < Settings.Main_Tiles_PerSide; a++)
                {
                    for (int b = 0; b < Settings.Main_Tiles_PerSide; b++)
                    {
                        Add(todo, a, b);
                    }
                }

                foreach (var pt in todo)
                {
                    ComplexData data = new ComplexData(pt.X, pt.Y, 0);
                    int idx = 1;
                    foreach (var cur in steps)
                    {
                        cur.RunStep(data, pt.X, pt.Y, "Shrinking " + pt.X + " x " + pt.Y + ": " + idx + " / " + steps.Count);
                        idx++;
                    }

                    perTile = 1;
                    int size = 8192;
                    for (int cur = targetLevel; cur < levels; cur++)
                    {
                        if (cur < Settings.Main_Tiles_LevelLimit)
                        {
                            MyConsole.WriteLine("Level " + cur + " for " + pt.X + " x " + pt.Y);
                            CreateImages(pt.X, pt.Y, data, cur, size, perTile);
                        }

                        perTile *= 2;
                        size /= 2;
                    }

                    if (Settings.Main_Action_DrawFullSizeTiles)
                    {
                        BitBits bit = new BitBits(8192, 8192, true);
                        CopyRect48(new Rectangle(0, 0, 8192, 8192), new Rectangle(0, 0, 8192, 8192), data, bit);
                        bit.Save(Helpers.GetBig(pt.X, pt.Y));
                    }
                }

                foreach (var cur in steps)
                {
                    cur.Finish();
                }
            }
        }