Example #1
0
        public static void DisplayMultiColorSprite(GR.Memory.ByteBuffer Data, Palette Palette, int Width, int Height, int BGColor, int MColor1, int MColor2, int SpriteColor, GR.Image.IImage Target, int X, int Y, bool ExpandX, bool ExpandY)
        {
            int pixelStepX = 1;
            int pixelStepY = 1;

            if (ExpandX)
            {
                pixelStepX = 2;
            }
            if (ExpandY)
            {
                pixelStepY = 2;
            }

            // multicolor
            for (int j = 0; j < Height; ++j)
            {
                for (int pp = 0; pp < pixelStepY; ++pp)
                {
                    for (int k = 0; k < Width / 8; ++k)
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            int pixelValue = (Data.ByteAt(j * 3 + k) & (3 << ((3 - i) * 2))) >> ((3 - i) * 2);

                            switch (pixelValue)
                            {
                            case 0:
                                pixelValue = BGColor;
                                break;

                            case 1:
                                pixelValue = MColor1;
                                break;

                            case 3:
                                pixelValue = MColor2;
                                break;

                            case 2:
                                pixelValue = SpriteColor;
                                break;
                            }

                            uint color = Palette.ColorValues[pixelValue];

                            Target.SetPixel(X + k * 8 * pixelStepX + i * 2 * pixelStepX, Y + j * pixelStepY + pp, color);
                            Target.SetPixel(X + k * 8 * pixelStepX + i * 2 * pixelStepX + 1, Y + j * pixelStepY + pp, color);
                            if (pixelStepX == 2)
                            {
                                Target.SetPixel(X + k * 8 * pixelStepX + i * 2 * pixelStepX + 2, Y + j * pixelStepY + pp, color);
                                Target.SetPixel(X + k * 8 * pixelStepX + i * 2 * pixelStepX + 3, Y + j * pixelStepY + pp, color);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        public static void DisplayMultiColorSprite(GR.Memory.ByteBuffer Data, int BGColor, int MColor1, int MColor2, int SpriteColor, GR.Image.IImage Target, int X, int Y, bool ExpandX, bool ExpandY)
        {
            int pixelStepX = 1;
            int pixelStepY = 1;

            if (ExpandX)
            {
                pixelStepX = 2;
            }
            if (ExpandY)
            {
                pixelStepY = 2;
            }

            // multicolor
            for (int j = 0; j < 21; ++j)
            {
                for (int pp = 0; pp < pixelStepY; ++pp)
                {
                    for (int k = 0; k < 3; ++k)
                    {
                        for (int i = 0; i < 4; ++i)
                        {
                            int pixelValue = (Data.ByteAt(j * 3 + k) & (3 << ((3 - i) * 2))) >> ((3 - i) * 2);

                            switch (pixelValue)
                            {
                            case 0:
                                //pixelValue = BackgroundColor;
                                continue;

                            case 1:
                                pixelValue = MColor1;
                                break;

                            case 3:
                                pixelValue = MColor2;
                                break;

                            case 2:
                                pixelValue = SpriteColor;
                                break;
                            }
                            Target.SetPixel(X + k * 8 * pixelStepX + i * 2 * pixelStepX, Y + j * pixelStepY + pp, (uint)pixelValue);
                            Target.SetPixel(X + k * 8 * pixelStepX + i * 2 * pixelStepX + 1, Y + j * pixelStepY + pp, (uint)pixelValue);
                            if (pixelStepX == 2)
                            {
                                Target.SetPixel(X + k * 8 * pixelStepX + i * 2 * pixelStepX + 2, Y + j * pixelStepY + pp, (uint)pixelValue);
                                Target.SetPixel(X + k * 8 * pixelStepX + i * 2 * pixelStepX + 3, Y + j * pixelStepY + pp, (uint)pixelValue);
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public static void DisplayFCMSprite(GR.Memory.ByteBuffer Data, Palette Palette, int Width, int Height, int BGColor, GR.Image.IImage Target, int X, int Y, bool ExpandX, bool ExpandY)
        {
            int pixelStepX = 1;
            int pixelStepY = 1;

            if (ExpandX)
            {
                pixelStepX = 2;
            }
            if (ExpandY)
            {
                pixelStepY = 2;
            }

            int lineBytes = (Width + 1) / 2;

            for (int j = 0; j < Height; ++j)
            {
                for (int pp = 0; pp < pixelStepY; ++pp)
                {
                    for (int i = 0; i < Width; i += 2)
                    {
                        byte pixelDuo = Data.ByteAt(j * lineBytes + i / 2);

                        byte colorToUse = (byte)BGColor;
                        if ((pixelDuo >> 4) != 0)
                        {
                            colorToUse = (byte)(pixelDuo >> 4);
                        }

                        uint color = Palette.ColorValues[colorToUse];

                        Target.SetPixel((X + i) * pixelStepX, Y + j * pixelStepY + pp, color);
                        if (pixelStepX == 2)
                        {
                            Target.SetPixel((X + i) * pixelStepX + 1, Y + j * pixelStepY + pp, color);
                        }

                        colorToUse = (byte)BGColor;
                        if ((pixelDuo & 0x0f) != 0)
                        {
                            colorToUse = (byte)(pixelDuo & 0x0f);
                        }

                        color = Palette.ColorValues[colorToUse];
                        Target.SetPixel((X + i + 1) * pixelStepX, Y + j * pixelStepY + pp, color);
                        if (pixelStepX == 2)
                        {
                            Target.SetPixel((X + i + 1) * pixelStepX + 1, Y + j * pixelStepY + pp, color);
                        }
                    }
                }
            }
        }
Example #4
0
        public static void DisplayHiResSprite(GR.Memory.ByteBuffer Data, Palette Palette, int Width, int Height, int BGColor, int SpriteColor, GR.Image.IImage Target, int X, int Y, bool ExpandX, bool ExpandY)
        {
            int pixelStepX = 1;
            int pixelStepY = 1;

            if (ExpandX)
            {
                pixelStepX = 2;
            }
            if (ExpandY)
            {
                pixelStepY = 2;
            }

            // single color
            for (int j = 0; j < Height; ++j)
            {
                for (int pp = 0; pp < pixelStepY; ++pp)
                {
                    for (int k = 0; k < Width / 8; ++k)
                    {
                        for (int i = 0; i < 8; ++i)
                        {
                            if ((Data.ByteAt(j * 3 + k) & (1 << (7 - i))) != 0)
                            {
                                uint color = Palette.ColorValues[SpriteColor];
                                Target.SetPixel(X + (k * 8 + i) * pixelStepX, Y + j * pixelStepY + pp, color);
                                if (pixelStepX == 2)
                                {
                                    Target.SetPixel(X + (k * 8 + i) * pixelStepX + 1, Y + j * pixelStepY + pp, color);
                                }
                            }
                            else
                            {
                                uint color = Palette.ColorValues[BGColor];

                                Target.SetPixel(X + (k * 8 + i) * pixelStepX, Y + j * pixelStepY + pp, color);
                                if (pixelStepX == 2)
                                {
                                    Target.SetPixel(X + (k * 8 + i) * pixelStepX + 1, Y + j * pixelStepY + pp, color);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        public static void DisplayVIC20Char(GR.Memory.ByteBuffer Data, Palette Palette, int BGColor, int MColor1, int MColor2, int CharColor, GR.Image.IImage TargetImage, int X, int Y)
        {
            // multicolor
            if (CharColor < 8)
            {
                DisplayHiResChar(Data, Palette, BGColor, CharColor, TargetImage, X, Y);
                return;
            }

            int charColor = CharColor - 8;

            for (int j = 0; j < 8; ++j)
            {
                for (int i = 0; i < 4; ++i)
                {
                    int pixelValue = (Data.ByteAt(j) & (3 << ((3 - i) * 2))) >> ((3 - i) * 2);

                    switch (pixelValue)
                    {
                    case 0:
                        pixelValue = BGColor;
                        break;

                    case 1:
                        // border color(!)
                        pixelValue = MColor1;
                        break;

                    case 2:
                        pixelValue = charColor;
                        break;

                    case 3:
                        pixelValue = MColor2;
                        break;
                    }

                    uint color = Palette.ColorValues[pixelValue];
                    TargetImage.SetPixel(X + i * 2, Y + j, color);
                    TargetImage.SetPixel(X + i * 2 + 1, Y + j, color);
                }
            }
        }
Example #6
0
 public static void DisplayMega65FCMChar(GR.Memory.ByteBuffer Data, Palette Palette, int BGColor, int CharColor, GR.Image.IImage TargetImage, int X, int Y)
 {
     for (int j = 0; j < 8; ++j)
     {
         for (int i = 0; i < 8; ++i)
         {
             int colorIndex = Data.ByteAt(i + j * 8);
             TargetImage.SetPixel(X + i, Y + j, Palette.ColorValues[colorIndex]);
         }
     }
 }
Example #7
0
        public static void DisplayHiResSprite(GR.Memory.ByteBuffer Data, int BGColor, int SpriteColor, GR.Image.IImage Target, int X, int Y, bool ExpandX, bool ExpandY)
        {
            int pixelStepX = 1;
            int pixelStepY = 1;

            if (ExpandX)
            {
                pixelStepX = 2;
            }
            if (ExpandY)
            {
                pixelStepY = 2;
            }

            // single color
            for (int j = 0; j < 21; ++j)
            {
                for (int pp = 0; pp < pixelStepY; ++pp)
                {
                    for (int k = 0; k < 3; ++k)
                    {
                        for (int i = 0; i < 8; ++i)
                        {
                            if ((Data.ByteAt(j * 3 + k) & (1 << (7 - i))) != 0)
                            {
                                //Data.Image.SetPixel( k * 8 + i, j, m_ColorValues[Data.Color] );
                                Target.SetPixel(X + (k * 8 + i) * pixelStepX, Y + j * pixelStepY + pp, (uint)SpriteColor);
                                if (pixelStepX == 2)
                                {
                                    Target.SetPixel(X + (k * 8 + i) * pixelStepX + 1, Y + j * pixelStepY + pp, (uint)SpriteColor);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        public static void DisplayHiResChar(GR.Memory.ByteBuffer Data, int BGColor, int CharColor, GR.Image.IImage TargetImage, int X, int Y)
        {
            // single color
            int colorIndex = 0;

            for (int j = 0; j < 8; ++j)
            {
                for (int i = 0; i < 8; ++i)
                {
                    if ((Data.ByteAt(j) & (1 << (7 - i))) != 0)
                    {
                        colorIndex = CharColor;
                    }
                    else
                    {
                        colorIndex = BGColor;
                    }
                    TargetImage.SetPixel(X + i, Y + j, (uint)colorIndex);
                }
            }
        }
Example #9
0
 public static void DisplayMega65NCMChar(GR.Memory.ByteBuffer Data, Palette Palette, int BGColor, int CharColor, GR.Image.IImage TargetImage, int X, int Y)
 {
     for (int j = 0; j < 8; ++j)
     {
         for (int i = 0; i < 16; ++i)
         {
             int colorIndex = Data.ByteAt(i / 2 + j * 8);
             if ((i % 2) != 0)
             {
                 colorIndex >>= 4;
             }
             else
             {
                 colorIndex &= 0x0f;
             }
             if (colorIndex == 0)
             {
                 colorIndex = BGColor;
             }
             TargetImage.SetPixel(X + i, Y + j, Palette.ColorValues[colorIndex]);
         }
     }
 }
        public void DrawTo(GR.Image.IImage TargetImage, int X, int Y, int SourceX, int SourceY, int DrawWidth, int DrawHeight)
        {
            // clip to source
            if ((SourceX >= Width) ||
                (SourceX + DrawWidth < 0) ||
                (SourceY >= Height) ||
                (SourceY + DrawHeight < 0))
            {
                return;
            }
            if (SourceX + DrawWidth > Width)
            {
                DrawWidth = Width - SourceX;
            }
            if (SourceX < 0)
            {
                DrawWidth += SourceX;
                X         += SourceX;
                SourceX    = 0;
            }
            if (SourceY + DrawHeight > Height)
            {
                DrawHeight = Height - SourceY;
            }
            if (SourceY < 0)
            {
                DrawHeight += SourceY;
                Y          += SourceY;
                SourceY     = 0;
            }

            int copyWidth  = DrawWidth;
            int copyHeight = DrawHeight;

            // clip to target
            if ((X >= TargetImage.Width) ||
                (Y >= TargetImage.Height) ||
                (X + copyWidth < 0) ||
                (Y + copyHeight < 0))
            {
                return;
            }

            if (X < 0)
            {
                SourceX   -= X;
                copyWidth += X;
                X          = 0;
            }
            if (X + copyWidth >= TargetImage.Width)
            {
                copyWidth = TargetImage.Width - X;
            }
            if (Y < 0)
            {
                SourceY    -= Y;
                copyHeight += Y;
                Y           = 0;
            }
            if (Y + copyHeight >= TargetImage.Height)
            {
                copyHeight = TargetImage.Height - Y;
            }

            if ((TargetImage.PixelFormat == PixelFormat) &&
                (BitsPerPixel >= 8))
            {
                unsafe
                {
                    byte *pTargetPos = (byte *)TargetImage.PinData();

                    pTargetPos += TargetImage.BytesPerLine * Y + X * TargetImage.BitsPerPixel / 8;

                    byte *pSourcePos = (byte *)PinData();

                    pSourcePos += BytesPerLine * SourceY + SourceX * BitsPerPixel / 8;
                    for (int y = 0; y < copyHeight; ++y)
                    {
                        CopyMemory(new IntPtr(pTargetPos), new IntPtr(pSourcePos), (uint)(copyWidth * BitsPerPixel / 8));

                        pTargetPos += TargetImage.BytesPerLine;
                        pSourcePos += BytesPerLine;
                    }
                    TargetImage.UnpinData();
                    UnpinData();
                }
            }
            else
            {
                // safe (but slow) copy
                for (int i = 0; i < copyWidth; ++i)
                {
                    for (int j = 0; j < copyHeight; ++j)
                    {
                        TargetImage.SetPixel(X + i, Y + j, GetPixel(SourceX + i, SourceY + j));
                    }
                }
            }
        }