BrashMonkeyContentPipelineExtension.SpritePacker.CopySpritesToOutput C# (CSharp) Method

CopySpritesToOutput() static private method

Once the arranging is complete, copies the bitmap data for each sprite to its chosen position in the single larger output bitmap.
static private CopySpritesToOutput ( List p_sprites, IList p_sourceSprites, ICollection p_outputSprites, int p_width, int p_height ) : Microsoft.Xna.Framework.Content.Pipeline.Graphics.BitmapContent
p_sprites List
p_sourceSprites IList
p_outputSprites ICollection
p_width int
p_height int
return Microsoft.Xna.Framework.Content.Pipeline.Graphics.BitmapContent
        static BitmapContent CopySpritesToOutput(List<ArrangedSprite> p_sprites, IList<BitmapContent> p_sourceSprites, ICollection<Rectangle> p_outputSprites, int p_width, int p_height)
        {
            BitmapContent l_output = new PixelBitmapContent<Color>(p_width, p_height);

            foreach (ArrangedSprite l_sprite in p_sprites) {
                BitmapContent l_source = p_sourceSprites[l_sprite.Index];

                int l_x = l_sprite.X;
                int l_y = l_sprite.Y;

                int l_width = l_source.Width;
                int l_height = l_source.Height;

                // Copy the main sprite data to the output sheet.
                BitmapContent.Copy(l_source, new Rectangle(0, 0, l_width, l_height), l_output, new Rectangle(l_x + 1, l_y + 1, l_width, l_height));

                // Copy a border strip from each edge of the sprite, creating
                // a one pixel padding area to avoid filtering problems if the
                // sprite is scaled or rotated.
                BitmapContent.Copy(l_source, new Rectangle(0, 0, 1, l_height), l_output, new Rectangle(l_x, l_y + 1, 1, l_height));

                BitmapContent.Copy(l_source, new Rectangle(l_width - 1, 0, 1, l_height), l_output, new Rectangle(l_x + l_width + 1, l_y + 1, 1, l_height));

                BitmapContent.Copy(l_source, new Rectangle(0, 0, l_width, 1), l_output, new Rectangle(l_x + 1, l_y, l_width, 1));

                BitmapContent.Copy(l_source, new Rectangle(0, l_height - 1, l_width, 1), l_output, new Rectangle(l_x + 1, l_y + l_height + 1, l_width, 1));

                // Copy a single pixel from each corner of the sprite,
                // filling in the corners of the one pixel padding area.
                BitmapContent.Copy(l_source, new Rectangle(0, 0, 1, 1), l_output, new Rectangle(l_x, l_y, 1, 1));

                BitmapContent.Copy(l_source, new Rectangle(l_width - 1, 0, 1, 1), l_output, new Rectangle(l_x + l_width + 1, l_y, 1, 1));

                BitmapContent.Copy(l_source, new Rectangle(0, l_height - 1, 1, 1), l_output, new Rectangle(l_x, l_y + l_height + 1, 1, 1));

                BitmapContent.Copy(l_source, new Rectangle(l_width - 1, l_height - 1, 1, 1), l_output, new Rectangle(l_x + l_width + 1, l_y + l_height + 1, 1, 1));

                // Remember where we placed this sprite.
                p_outputSprites.Add(new Rectangle(l_x + 1, l_y + 1, l_width, l_height));
            }

            return l_output;
        }