예제 #1
0
        public ComplexData GetData(ref int x, ref int y, ref double[,] res, ref double[,] ims, ref double[,] other, ref UInt64[,] height)
        {
            m_hasOne.WaitOne();
            x = m_tileX;
            y = m_tileY;
            res = m_res;
            ims = m_ims;
            other = m_other;
            height = m_height;
            ComplexData ret = m_data;
            m_gotOne.Set();

            if (ret == null)
            {
                m_thread.Join();
                m_thread = null;
            }

            m_tileX = 0;
            m_tileY = 0;
            m_data = null;
            m_res = null;
            m_ims = null;
            m_other = null;
            m_height = null;

            return ret;
        }
예제 #2
0
        public static ComplexData LoadFile(string file, int width, int height)
        {
            ComplexData ret = new ComplexData();

            ret.InternalLoadFile(file, width, height);

            return ret;
        }
예제 #3
0
        public static ColorD AvgRange48(ComplexData data, int x, int y, int size)
        {
            AvgColor avg = AvgColor.Factory();

            for (int xOff = 0; xOff < size; xOff++)
            {
                for (int yOff = 0; yOff < size; yOff++)
                {
                    avg.Add(data.GetPoint(x + xOff, y + yOff));
                }
            }

            return avg.GetAvg48();
        }
예제 #4
0
        public void RunStep(ComplexData data, int a, int b, string msg)
        {
            if (a >= m_tileX * m_perTile &&
                b >= m_tileY * m_perTile &&
                a < (m_tileX + 1) * m_perTile &&
                b < (m_tileY + 1) * m_perTile)
            {
                MyConsole.WriteLine(msg);

                VisualizeWorker.CopyRect(
                    new Rectangle(0, 0, 8192, 8192),
                    new Rectangle(
                        (a - m_tileX * m_perTile) * (256 / m_perTile),
                        (b - m_tileY * m_perTile) * (256 / m_perTile),
                        (256 / m_perTile),
                        (256 / m_perTile)),
                    data,
                    m_bit, false);

                m_bit.Save(Helpers.GetFinal(m_level, m_tileX, m_tileY), false);
            }
        }
예제 #5
0
        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;
                    }
                }

                foreach (var cur in steps)
                {
                    cur.Finish();
                }
            }
        }
예제 #6
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);
                        }
                    }
                }
            }
        }
예제 #7
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));
        }
예제 #8
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));
                    }
                }
            }
        }
예제 #9
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);
                        }
                    }
                }
            }
        }
예제 #10
0
 public Helper(ComplexData parent)
 {
     m_parent = parent;
 }
예제 #11
0
        void Worker()
        {
            for (int tileX = 0; tileX < Settings.Main_Tiles_PerSide; tileX++)
            {
                for (int tileY = 0; tileY < Settings.Main_Tiles_PerSide; tileY++)
                {
                    string file = Helpers.GetName(tileX, tileY, 0);

                    if (Helpers.SaveExists(file))
                    {
                        MyConsole.WriteLine("Loading " + tileX + " x " + tileY);

                        Helpers.LoadSave(file, 8192, 8192, ref m_height, ref m_res, ref m_ims, ref m_other);
                        ComplexData data = null;
                        if (m_height != null)
                        {
                            data = new ComplexData(m_res, m_ims, m_other, m_height);
                        }

                        if (data.Loaded)
                        {
                            m_tileX = tileX;
                            m_tileY = tileY;
                            m_data = data;
                            m_hasOne.Set();
                            m_gotOne.WaitOne();
                        }
                    }
                }
            }

            m_data = null;
            m_tileX = 0;
            m_tileY = 0;
            m_hasOne.Set();
        }