Пример #1
0
        public void Write(byte[] data, CharLayout layout, uint offset, uint ch)
        {
            uint charOffset = (8 * offset) + (layout.Stride * ch);

            for (uint y = 0; y < Height; y++)
            {
                uint rowOffset = charOffset + layout.YOffset(data, y);
                for (uint x = 0; x < Width; x++)
                {
                    uint pixOffset = rowOffset + layout.XOffset(data, x);
                    uint planeBit  = 1U << (int)(layout.Planes - 1);
                    for (uint plane = 0; plane < layout.Planes; plane++, planeBit >>= 1)
                    {
                        uint bitOffset  = pixOffset + layout.PlaneOffset(data, plane);
                        uint byteOffset = bitOffset / 8;
                        //byte mask = (byte)(0x0080U >> (int)(7 - (bitOffset % 8)));
                        byte mask = (byte)(0x0080U >> (int)(bitOffset % 8));
                        if ((Pixels[x + (Width * y)] & planeBit) != 0)
                        {
                            data[byteOffset] |= mask;
                        }
                        else
                        {
                            data[byteOffset] &= (byte)(~mask);
                        }
                    }
                }
            }
        }
Пример #2
0
        public GfxElement(byte[] data, CharLayout layout, uint offset, uint ch)
        {
            Width  = layout.Width;
            Height = layout.Height;
            Pixels = new uint[Width * Height];
            uint charOffset = (8 * offset) + (layout.Stride * ch);

            for (uint y = 0; y < Height; y++)
            {
                uint rowOffset = charOffset + layout.YOffset(data, y);
                for (uint x = 0; x < Width; x++)
                {
                    uint pixOffset = rowOffset + layout.XOffset(data, x);
                    uint pixel     = 0;
                    uint planeBit  = 1U << (int)(layout.Planes - 1);
                    for (uint plane = 0; plane < layout.Planes; plane++, planeBit >>= 1)
                    {
                        uint bitOffset = pixOffset + layout.PlaneOffset(data, plane);
                        if (((data[bitOffset / 8] >> (int)(7 - (bitOffset % 8))) & 1U) != 0)
                        {
                            pixel |= planeBit;
                        }
                    }
                    Pixels[x + (Width * y)] = pixel;
                }
            }
        }
Пример #3
0
        private void importButton_Click(object sender, EventArgs e)
        {
            Classes.CharLayout layout = Profile.CharLayouts[layoutBox.SelectedIndex];
            byte[]             data   = null;
            uint offset = ParseNumber(offsetBox.Text);
            uint count;

            try
            {
                if (regionBox.SelectedIndex == 0)                                       // "Flat file" selected
                {
                    data  = File.ReadAllBytes((string)fileGrid.Rows[0].Cells[3].Value); // Only one file to open.
                    count = countButton.Checked ? ParseNumber(countBox.Text) : (uint)(8U * data.Length / layout.Stride * fracNumUpDown.Value / fracDenUpDown.Value);
                    uint max = layout.MaxElements((uint)data.Length, offset);
                    if (max < count)
                    {
                        string displayCount = countButton.Checked ? countBox.Text : count.ToString();
                        MessageBox.Show(
                            String.Format(
                                Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_FileTooSmall,
                                displayCount,
                                offsetBox.Text,
                                data.Length,
                                max),
                            Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_FileTooSmall);
                        return;
                    }
                }
                else // Load from multiple ROMs
                {
                    Classes.LoadRegion region = Profile.LoadRegions[regionBox.SelectedIndex - 1];
                    count = countButton.Checked ? ParseNumber(countBox.Text) : (uint)(8U * region.Length / layout.Stride * fracNumUpDown.Value / fracDenUpDown.Value);
                    uint max = layout.MaxElements(region.Length, offset);
                    if (max < count)
                    {
                        string displayCount = countButton.Checked ? countBox.Text : count.ToString();
                        MessageBox.Show(
                            String.Format(
                                Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_RegionTooSmall,
                                region.Name,
                                region.Length,
                                displayCount,
                                offsetBox.Text,
                                max),
                            Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_RegionTooSmall);
                        return;
                    }
                    string[] paths = new string[fileGrid.Rows.Count];
                    for (int i = 0; i < paths.Length; i++)
                    {
                        paths[i] = (string)fileGrid.Rows[i].Cells[3].Value;
                    }
                    data = region.LoadFiles(paths);
                }
            }
            catch (Classes.LoadPastEndOfFileException ex)
            {
                MessageBox.Show(
                    string.Format(
                        Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_ReadPastFileEnd,
                        ex.File.Name,
                        ex.Instruction.Offset,
                        ex.Instruction.Size,
                        ex.Read),
                    Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_ReadPastFileEnd);
                return;
            }
            catch (Classes.LoadOutsideRegionException ex)
            {
                MessageBox.Show(
                    string.Format(
                        Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_LoadBeyondRegionEnd,
                        ex.Region.Name,
                        ex.Region.Length,
                        ex.Offset,
                        ex.File.Name),
                    Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_LoadBeyondRegionEnd);
                return;
            }
            catch (Classes.FillOutsideRegionException ex)
            {
                MessageBox.Show(
                    string.Format(
                        Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_FillBeyondRegionEnd,
                        ex.Region.Name,
                        ex.Region.Length,
                        ex.Offset,
                        ex.Fill.Value),
                    Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_FillBeyondRegionEnd);
                return;
            }
            catch
            {
                MessageBox.Show(Porno_Graphic.Properties.Resources.TileImporter_ErrorReadingFile);
                return;
            }

            Classes.GfxElement[] elements = new Classes.GfxElement[count];
            Parallel.For(0, count, index => { elements[index] = new Classes.GfxElement(data, layout, offset, (uint)index); });

            Classes.TileImportMetadata metadata = new Classes.TileImportMetadata();
            if (mProfilePath != null)
            {
                metadata.ProfileFile = mProfilePath;
            }
            //metadata.ProfileFile = Path.GetFileName(mProfilePath);
            metadata.ProfileName = mProfile.Name;
            //metadata.RegionName = (string)regionBox.SelectedItem;
            //metadata.LayoutName = (string)layoutBox.SelectedItem;
            if ((regionBox.SelectedIndex - 1) < 0)
            {
                metadata.RegionName = (string)regionBox.SelectedItem;
            }
            else
            {
                metadata.RegionName = mProfile.LoadRegions[regionBox.SelectedIndex - 1].Name;
            }
            metadata.LayoutName = mProfile.CharLayouts[layoutBox.SelectedIndex].Name;
            if (offsetBox.Text.StartsWith("0x"))
            {
                metadata.Offset = offsetBox.Text.Substring(2);
            }
            metadata.Planes = layout.Planes.ToString();

            string[] romPaths = new string[fileGrid.Rows.Count];
            for (int i = 0; i < romPaths.Length; i++)
            {
                romPaths[i] = (string)fileGrid.Rows[i].Cells[3].Value;
            }
            metadata.RomFilenames = romPaths;
            Classes.GfxElementSet elementSet = new Classes.GfxElementSet();
            elementSet.Name           = "TestName";
            elementSet.ElementWidth   = layout.Width;
            elementSet.ElementHeight  = layout.Height;
            elementSet.Elements       = elements;
            elementSet.ImportMetadata = metadata;
            mParent.CreateImportProject(elementSet, (layout.Planes > 3) ? Classes.IndexedPalette.RGBI : Classes.IndexedPalette.RGB);
            Close();
        }