コード例 #1
0
        UnsettedBlock[,] ConvertCPP(ref Image sourceImage, ArtType type)
        {
            stateLabel?.BeginInvoke(new Action(() => { stateLabel.Text = "Serialization"; }));
            UnsettedBlock[,] result = new UnsettedBlock[sourceImage.Width, sourceImage.Height];
            int[] image1 = new int[sourceImage.Width * sourceImage.Height * 3];
            int   h      = sourceImage.Height;
            int   w      = sourceImage.Width;

            using (FBitmap fbmp = new FBitmap((Bitmap)sourceImage, true))
                for (int i = 0; i < h; ++i)
                {
                    for (int j = 0; j < w; ++j)
                    {
                        Color pixel = fbmp.GetPixel(j, i);
                        image1[i * w * 3 + j * 3 + 0] = pixel.R;
                        image1[i * w * 3 + j * 3 + 1] = pixel.G;
                        image1[i * w * 3 + j * 3 + 2] = pixel.B;
                    }
                }
            List <int> notes1 = new List <int>(_colors.Count * 4);

            foreach (ColorNote col in _colors)
            {
                if (col.Use)
                {
                    notes1.Add(col.ColorID);
                    notes1.Add(col.LightColor.R);
                    notes1.Add(col.LightColor.G);
                    notes1.Add(col.LightColor.B);
                }
            }
            stateLabel?.BeginInvoke(new Action(() => { stateLabel.Text = "Converting"; }));
            fixed(int *image = image1)
            fixed(int *notes = notes1.ToArray())
            {
                int *res = Convert(image, image1.Length, (int)type, Properties.Settings.Default.ConvertingMethod == 1, notes, notes1.Count,
                                   () => { progress.BeginInvoke(new Action(() => { progress?.Increment(1); })); },
                                   (e) =>
                {
                    for (int j = 0; j < _colors.Count; ++j)
                    {
                        _colors[j].Uses = e[j];
                    }
                });
                int i = 0;

                for (int x = 0; x < h; ++x)
                {
                    for (int y = 0; y < w; ++y)
                    {
                        result[y, x].ID  = res[i++];
                        result[y, x].Set = (ColorType)res[i++];
                    }
                }
            }
            return(result);
        }
コード例 #2
0
        SettedBlock[] GenerateSegmentedLayer(int layerNum, out int MaxHeight)
        {
            SettedBlock[] layer = new SettedBlock[rawScheme.GetLength(1) + 1];
            MaxHeight = 0;

            List <MBlock> mBlocks = new List <MBlock>();
            UnsettedBlock last    = new UnsettedBlock {
                ID = -1, Set = ColorType.Normal
            };
            MBlock curMBlock = new MBlock();

            curMBlock.Add(new UnsettedBlock {
                ID = -1, Set = ColorType.Normal
            });
            bool isUp = rawScheme[layerNum, 0].Set == ColorType.Light;

            for (int i = 0; i < rawScheme.GetLength(1); ++i)
            {
                if (!isUp)
                {
                    if (rawScheme[layerNum, i].Set == ColorType.Dark || rawScheme[layerNum, i].Set == ColorType.Normal)
                    {
                        curMBlock.Add(rawScheme[layerNum, i]);
                    }
                    else
                    {
                        isUp = true;
                        curMBlock.Add(rawScheme[layerNum, i]);
                    }
                }
                else
                {
                    if (rawScheme[layerNum, i].Set == ColorType.Light || rawScheme[layerNum, i].Set == ColorType.Normal)
                    {
                        curMBlock.Add(rawScheme[layerNum, i]);
                    }
                    else
                    {
                        isUp = false;
                        mBlocks.Add(curMBlock.Clone() as MBlock);
                        curMBlock = new MBlock();
                        curMBlock.Add(rawScheme[layerNum, i]);
                    }
                }
            }
            mBlocks.Add(curMBlock.Clone() as MBlock);
            foreach (MBlock mb in mBlocks)
            {
                mb.Calculate();
            }
            int minH = 0;

            for (int j = 1; j < mBlocks.Count; ++j)
            {
                if (mBlocks[j].StartH >= mBlocks[j - 1].EndH)
                {
                    mBlocks[j].Shift = mBlocks[j].StartH - mBlocks[j - 1].EndH + 1;
                    if (minH > mBlocks[j].Shift)
                    {
                        minH = mBlocks[j].Shift;
                    }
                    for (int k = j - 1; k >= 0; --k)
                    {
                        if (mBlocks[k].EndH <= mBlocks[k + 1].StartH)
                        {
                            mBlocks[k].Shift += mBlocks[k + 1].StartH - mBlocks[k].EndH + 1;
                        }
                    }
                }
            }
            int curPos = -1;

            for (int j = 0; j < mBlocks.Count; ++j)
            {
                if (MaxHeight < mBlocks[j].StartH)
                {
                    MaxHeight = mBlocks[j].StartH;
                }
                if (MaxHeight < mBlocks[j].EndH)
                {
                    MaxHeight = mBlocks[j].EndH;
                }
                SettedBlock[] cur = mBlocks[j].Get();
                for (int k = 0; k < cur.Length; ++k)
                {
                    layer[++curPos] = cur[k];
                }
            }
            return(layer);
        }