Пример #1
0
        public override Color32BppArgb[] RenderPixels()
        {
            if (Palette is null)
            {
                return(new Color32BppArgb[0]);
            }

            var tileWidth  = TileWidth;
            var tileHeight = TileHeight;

            var width = Width;

            var pixelsPerRow = width * tileHeight;

            var viewWidth     = ViewWidth;
            var viewHeight    = ViewHeight;
            var viewTileCount = TileMap.VisibleGridTileCount;

            if (viewTileCount == 0)
            {
                return(new Color32BppArgb[0]);
            }

            var imageHeight = (((viewTileCount - 1) / viewWidth) + 1)
                              * tileHeight;

            var result        = new Color32BppArgb[width * imageHeight];
            var gridStartTile = TileMap.GetGridTileIndex(TileMap.Origin);

            Parallel.For(0, viewTileCount, DrawSquare);
            return(result);

            void DrawSquare(int viewTileIndex)
            {
                var tileX     = viewTileIndex % viewWidth;
                var tileY     = viewTileIndex / viewWidth;
                var destIndex = (tileX * TileWidth) + (tileY * pixelsPerRow);
                var color     = GetPaletteColor(gridStartTile + viewTileIndex);

                for (var y = 0; y < tileHeight; y++)
                {
                    for (var x = 0; x < tileWidth; x++)
                    {
                        result[destIndex + x] = color;
                    }

                    destIndex += width;
                }
            }
        }
Пример #2
0
        public Color32BppArgb[] GetPalette(
            int areaIndex,
            bool isLuigiBonusArea)
        {
            var result   = new Color32BppArgb[0x100];
            var srcIndex = PaletteRowIndexTableAddress + (areaIndex << 4);

            for (var destIndex = 0; destIndex < 0x100;)
            {
                var paletteRowIndex = Rom.ReadByte(srcIndex++);

                var paletteIndex = Rom.ReadInt16(
                    PaletteIndexTableAddress + (paletteRowIndex << 1));

                var address = PaletteDataAddress + paletteIndex;

                for (var i = 0; i < 0x20; i += 2)
                {
                    var color = Rom.ReadInt16(address + i);
                    result[destIndex++] = Color32BppArgb.FromSnesColor(color);
                }
            }

            if (isLuigiBonusArea)
            {
                var address = LuigiBonusAreaPaletteAddress;
                for (var i = 0; i < 0x10; i++)
                {
                    var color = Rom.ReadInt16(address + (i << 1));
                    result[LuigiBonusAreaPaletteIndex + i] =
                        Color32BppArgb.FromSnesColor(color);
                }
            }

            return(result);
        }
Пример #3
0
        public override unsafe Color32BppArgb[] RenderPixels()
        {
            if (Gfx is null)
            {
                return(new Color32BppArgb[0]);
            }

            var colors = new Color32BppArgb[0x100];

            for (var i = 0; i < Math.Min(colors.Length, Palette.Count); i++)
            {
                colors[i] = Palette[i];
            }

            var tileWidth  = TileWidth;
            var tileHeight = TileHeight;

            var width = Width;

            var pixelsPerRow = width * tileHeight;

            var viewWidth     = ViewWidth;
            var viewHeight    = ViewHeight;
            var viewTileCount = TileMap.VisibleGridTileCount;

            if (viewTileCount == 0)
            {
                return(new Color32BppArgb[0]);
            }

            var imageHeight = (((viewTileCount - 1) / viewWidth) + 1)
                              * tileHeight;

            var pixelY = new int[tileHeight];

            for (var y = 0; y < tileHeight; y++)
            {
                pixelY[y]  = y * GfxTile.PixelsPerPlane / tileHeight;
                pixelY[y] *= GfxTile.PlanesPerTile;
            }

            var pixelX = new int[tileWidth];

            for (var x = 0; x < tileWidth; x++)
            {
                pixelX[x] = x * GfxTile.PixelsPerPlane / tileWidth;
            }

            var result        = new Color32BppArgb[width * imageHeight];
            var gridTileIndex = TileMap.GetGridTileIndex(TileMap.Origin);

            for (var tileIndex = 0; tileIndex < viewTileCount; tileIndex++)
            {
                var tileX     = tileIndex % viewWidth;
                var tileY     = tileIndex / viewWidth;
                var destIndex = (tileX * TileWidth) + (tileY * pixelsPerRow);

                var tile  = Gfx[gridTileIndex];
                var alpha = GetAlpha();
                for (var y = 0; y < tileHeight; y++)
                {
                    var pixelHeight = pixelY[y];
                    for (var x = 0; x < tileWidth; x++)
                    {
                        var colorIndex = tile.Pixels[pixelHeight + pixelX[x]];
                        var color      = colors[colorIndex];

                        color.Alpha           = alpha;
                        result[destIndex + x] = color;
                    }

                    destIndex += width;
                }

                gridTileIndex++;
            }

            return(result);

            byte GetAlpha()
            {
                return((byte)(SelectionContainsTile(gridTileIndex)
                    ? 0xFF
                    : Math.Max(
                                  Byte.MaxValue - (CurrentSelection.Count / 2),
                                  0x80)));
            }
        }