示例#1
0
        /// <summary>
        /// Extracts the two water autotiles from provided chipset.
        /// </summary>
        /// <param name="chipsetBitmap">The chipset bitmap.</param>
        /// <returns>Autotile bitmaps in XP format.</returns>
        private List <Bitmap> ExtractWaterAutotiles(Bitmap chipsetBitmap)
        {
            List <Bitmap> waterAutotilesBitmaps = new List <Bitmap>();

            for (int waterAutotileIndex = 0; waterAutotileIndex < 2; waterAutotileIndex++)
            {
                Bitmap destinationBitmap = new Bitmap(AnimatedAutotile2000Width, AnimatedAutotile2000Height);

                using (Graphics graphics = GraphicsUtils.GetGraphicsForScaling(destinationBitmap))
                {
                    for (int frameIndex = 0; frameIndex < 3; frameIndex++)
                    {
                        foreach (BitmapRelationMap bitmapRelationMap in waterAutotilesBitmapRelationMaps)
                        {
                            Rectangle calculatedSourceRectangle = bitmapRelationMap.SourceRectangle;
                            calculatedSourceRectangle.X += (frameIndex * TileSize);

                            // If source is absolute it means that water autotile index should not be taken as part of calculations because it is in fixed location
                            if (!bitmapRelationMap.SourceAbsolute)
                            {
                                calculatedSourceRectangle = new Rectangle(
                                    bitmapRelationMap.SourceRectangle.X + (waterAutotileIndex * 48) + (frameIndex * TileSize),
                                    bitmapRelationMap.SourceRectangle.Y,
                                    bitmapRelationMap.SourceRectangle.Width,
                                    bitmapRelationMap.SourceRectangle.Height);
                            }

                            // Destination should change depending on frame
                            Rectangle calculatedDestinationRectangle =
                                new Rectangle(
                                    bitmapRelationMap.DestinationRectangle.X + (frameIndex * 48),
                                    bitmapRelationMap.DestinationRectangle.Y,
                                    bitmapRelationMap.DestinationRectangle.Width,
                                    bitmapRelationMap.DestinationRectangle.Height);


                            Bitmap temporaryBitmap = chipsetBitmap.Clone(calculatedSourceRectangle, PixelFormat.DontCare);

                            graphics.DrawImage(temporaryBitmap, calculatedDestinationRectangle);

                            temporaryBitmap.Dispose();
                        }
                    }
                }

                // XP tiles are twice the size of 2000 tiles so they need to scaled up
                Bitmap scaledBitmap = new Bitmap(AnimatedAutotile2000Width * 2, AnimatedAutotile2000Height * 2);

                using (Graphics scaleGraphics = GraphicsUtils.GetGraphicsForScaling(scaledBitmap))
                {
                    scaleGraphics.DrawImage(destinationBitmap, new Rectangle(0, 0, AnimatedAutotile2000Width * 2, AnimatedAutotile2000Height * 2));
                }

                destinationBitmap.Dispose();

                waterAutotilesBitmaps.Add(scaledBitmap);
            }

            return(waterAutotilesBitmaps);
        }
        /// <summary>
        /// Convert single RPG Maker 2000 character set bitmap to xp format.
        /// </summary>
        /// <param name="singleCharacterBitmap">The single character bitmap.</param>
        /// <param name="frameWidth">Width of the frame.</param>
        /// <param name="frameHeight">Height of the frame.</param>
        private RPGMakerXPCharset Convert2000ToXpFormat(Bitmap singleCharacterBitmap, int frameWidth, int frameHeight)
        {
            // XP characters sets are 4x4 frames and twice as big in resolution
            int xpCharsetHeight = frameHeight * 4 * 2;
            int xpCharsetWidth  = frameWidth * 4 * 2;

            Color topLeftColor = singleCharacterBitmap.GetPixel(0, 0);

            RPGMakerXPCharset xpCharset = new RPGMakerXPCharset {
                Bitmap = new Bitmap(xpCharsetWidth, xpCharsetHeight)
            };

            using (Graphics graphics = GraphicsUtils.GetGraphicsForScaling(xpCharset.Bitmap))
            {
                // Looping through every frame of the character set
                for (int y = 0; y < 4; y++)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        // Checking where in the XP character set frame should be positioned
                        foreach (List <int> mapValue in rpgMaker2000CharPositionToXPMap)
                        {
                            if (mapValue[0] != x || mapValue[1] != y)
                            {
                                continue;
                            }

                            Bitmap originalFrameBitmap = singleCharacterBitmap.Clone(new Rectangle(x * frameWidth, y * frameHeight, frameWidth, frameHeight),
                                                                                     PixelFormat.DontCare);

                            originalFrameBitmap.MakeTransparent(topLeftColor);

                            // Calculating position and size for where frame should be drawn
                            int destinationX      = mapValue[2] * (frameWidth * 2);
                            int destinationY      = mapValue[3] * (frameHeight * 2);
                            int scaledFrameWidth  = frameWidth * 2;
                            int scaledFrameHeight = frameHeight * 2;

                            // Draw to new bitmap and scale twice as big
                            graphics.DrawImage(originalFrameBitmap, new Rectangle(
                                                   destinationX,
                                                   destinationY,
                                                   scaledFrameWidth,
                                                   scaledFrameHeight)
                                               );

                            originalFrameBitmap.Dispose();
                        }
                    }
                }
            }

            return(xpCharset);
        }
示例#3
0
        /// <summary>
        /// Extracts the animations from chipset and convert them to XP charset animation sheet.
        /// </summary>
        /// <param name="chipsetBitmap">The chipset bitmap.</param>
        /// <returns>Animation in XP character set format.</returns>
        private Bitmap ExtractAnimationSheet(Bitmap chipsetBitmap)
        {
            // There is four frames per animation and animation sheet should be chipset sized
            Bitmap destinationBitmap = new Bitmap(TileSize * 4, TileSize * 4);

            using (Graphics graphics = GraphicsUtils.GetGraphicsForScaling(destinationBitmap))
            {
                // There is three animations in chipset
                for (int animationIndex = 0; animationIndex < 3; animationIndex++)
                {
                    foreach (BitmapRelationMap bitmapRelationMap in animationBitmapRelationMaps)
                    {
                        Rectangle calculatedSourceRectangle = bitmapRelationMap.SourceRectangle;
                        calculatedSourceRectangle.X += (animationIndex * TileSize);

                        // Destination should change depending on frame
                        Rectangle calculatedDestinationRectangle =
                            new Rectangle(
                                bitmapRelationMap.DestinationRectangle.X,
                                bitmapRelationMap.DestinationRectangle.Y + (animationIndex * TileSize),
                                bitmapRelationMap.DestinationRectangle.Width,
                                bitmapRelationMap.DestinationRectangle.Height);

                        Bitmap temporaryBitmap = chipsetBitmap.Clone(calculatedSourceRectangle, PixelFormat.DontCare);

                        graphics.DrawImage(temporaryBitmap, calculatedDestinationRectangle);

                        temporaryBitmap.Dispose();
                    }
                }
            }

            // XP tiles are twice the size of 2000 tiles so they need to scaled up
            Bitmap scaledBitmap = new Bitmap(TileSize * 4 * 2, TileSize * 4 * 2);

            using (Graphics scaleGraphics = GraphicsUtils.GetGraphicsForScaling(scaledBitmap))
            {
                scaleGraphics.DrawImage(destinationBitmap, new Rectangle(0, 0, TileSize * 4 * 2, TileSize * 4 * 2));
            }

            destinationBitmap.Dispose();

            return(scaledBitmap);
        }
示例#4
0
        /// <summary>
        /// Extracts the deep water autotile from chipset.
        /// </summary>
        /// <param name="chipsetBitmap">The chipset bitmap.</param>
        /// <returns>Autotile bitmap in XP format.</returns>
        private Bitmap ExtractDeepWaterAutotile(Bitmap chipsetBitmap)
        {
            Bitmap destinationBitmap = new Bitmap(AnimatedAutotile2000Width, AnimatedAutotile2000Height);

            using (Graphics graphics = GraphicsUtils.GetGraphicsForScaling(destinationBitmap))
            {
                for (int frameIndex = 0; frameIndex < 3; frameIndex++)
                {
                    foreach (BitmapRelationMap bitmapRelationMap in deepWaterAutotileBitmapRelationMaps)
                    {
                        Rectangle calculatedSourceRectangle = bitmapRelationMap.SourceRectangle;
                        calculatedSourceRectangle.X += (frameIndex * TileSize);

                        // Destination should change depending on frame
                        Rectangle calculatedDestinationRectangle =
                            new Rectangle(
                                bitmapRelationMap.DestinationRectangle.X + (frameIndex * 48),
                                bitmapRelationMap.DestinationRectangle.Y,
                                bitmapRelationMap.DestinationRectangle.Width,
                                bitmapRelationMap.DestinationRectangle.Height);


                        Bitmap temporaryBitmap = chipsetBitmap.Clone(calculatedSourceRectangle, PixelFormat.DontCare);

                        graphics.DrawImage(temporaryBitmap, calculatedDestinationRectangle);

                        temporaryBitmap.Dispose();
                    }
                }
            }

            // XP tiles are twice the size of 2000 tiles so they need to scaled up
            Bitmap scaledBitmap = new Bitmap(AnimatedAutotile2000Width * 2, AnimatedAutotile2000Height * 2);

            using (Graphics scaleGraphics = GraphicsUtils.GetGraphicsForScaling(scaledBitmap))
            {
                scaleGraphics.DrawImage(destinationBitmap, new Rectangle(0, 0, AnimatedAutotile2000Width * 2, AnimatedAutotile2000Height * 2));
            }

            destinationBitmap.Dispose();

            return(scaledBitmap);
        }
示例#5
0
        /// <summary>
        /// Extracts 12 autotiles from chipset to XP format.
        /// </summary>
        /// <param name="chipsetBitmap">The chipset bitmap.</param>
        /// <returns>Autotile bitmaps in XP format.</returns>
        private List <Bitmap> ExtractAutotiles(Bitmap chipsetBitmap)
        {
            List <Bitmap> autotileBitmaps = new List <Bitmap>();

            foreach (BitmapRelationMap bitmapRelationMap in autotilesBitmapRelationMaps)
            {
                Bitmap destinationBitmap = new Bitmap(Autotile2000Width * 2, Autotile2000Height * 2);

                using (Graphics scaleGraphics = GraphicsUtils.GetGraphicsForScaling(destinationBitmap))
                {
                    Bitmap temporaryBitmap = chipsetBitmap.Clone(bitmapRelationMap.SourceRectangle, PixelFormat.DontCare);

                    scaleGraphics.DrawImage(temporaryBitmap, new Rectangle(0, 0, Autotile2000Width * 2, Autotile2000Height * 2));

                    temporaryBitmap.Dispose();
                }

                autotileBitmaps.Add(destinationBitmap);
            }

            return(autotileBitmaps);
        }
示例#6
0
        /// <summary>
        /// Extracts the tileset.
        /// </summary>
        /// <param name="chipsetBitmap">The chipset bitmap.</param>
        /// <returns>Tileset in XP format.</returns>
        private Bitmap ExtractTileset(Bitmap chipsetBitmap)
        {
            // There is own background color tiles in chipset for top and low layers
            Color lowLayerBackgroundColor = chipsetBitmap.GetPixel(368, 112);
            Color topLayerBackgroundColor = chipsetBitmap.GetPixel(288, 128);

            Bitmap destinationBitmap = new Bitmap(128, 768);

            using (Graphics graphics = GraphicsUtils.GetGraphicsForScaling(destinationBitmap))
            {
                // Low layer tiles
                Bitmap temporaryBitmap = chipsetBitmap.Clone(new Rectangle(192, 0, 96, 256), PixelFormat.DontCare);
                temporaryBitmap.MakeTransparent(lowLayerBackgroundColor);

                graphics.DrawImage(temporaryBitmap, new Rectangle(0, 0, 96, 256));

                temporaryBitmap.Dispose();

                temporaryBitmap = chipsetBitmap.Clone(new Rectangle(288, 0, 96, 128), PixelFormat.DontCare);
                temporaryBitmap.MakeTransparent(lowLayerBackgroundColor);

                graphics.DrawImage(temporaryBitmap, new Rectangle(0, 256, 96, 128));

                temporaryBitmap.Dispose();

                // Top layer tiles
                temporaryBitmap = chipsetBitmap.Clone(new Rectangle(288, 128, 96, 128), PixelFormat.DontCare);
                temporaryBitmap.MakeTransparent(topLayerBackgroundColor);

                graphics.DrawImage(temporaryBitmap, new Rectangle(0, 384, 96, 128));

                temporaryBitmap.Dispose();

                temporaryBitmap = chipsetBitmap.Clone(new Rectangle(384, 0, 96, 256), PixelFormat.DontCare);
                temporaryBitmap.MakeTransparent(topLayerBackgroundColor);

                graphics.DrawImage(temporaryBitmap, new Rectangle(0, 512, 96, 256));

                temporaryBitmap.Dispose();

                // Adding center tiles from autotiles for easier use
                foreach (BitmapRelationMap bitmapRelationMap in tilesBitmapRelationMaps)
                {
                    temporaryBitmap = chipsetBitmap.Clone(bitmapRelationMap.SourceRectangle, PixelFormat.DontCare);
                    graphics.DrawImage(temporaryBitmap, bitmapRelationMap.DestinationRectangle);

                    temporaryBitmap.Dispose();
                }
            }

            // XP tiles are twice the size of 2000 tiles so they need to scaled up
            Bitmap scaledBitmap = new Bitmap(256, 768 * 2);

            using (Graphics scaleGraphics = GraphicsUtils.GetGraphicsForScaling(scaledBitmap))
            {
                scaleGraphics.DrawImage(destinationBitmap, new Rectangle(0, 0, 256, 768 * 2));
            }

            destinationBitmap.Dispose();

            return(scaledBitmap);
        }