News:

11 March 2016 - Forum Rules

Main Menu

GBA raw graphics function

Started by Madsiur, August 31, 2014, 01:55:59 PM

Previous topic - Next topic

Madsiur

I've been working on a graphic editor for FF6A for some times now. The graphics are appearing fine in the editor with the correct palettes and colors but when I save them they appears as this in the game:



This happens even when I make no changes to the portraits. I figured it had something to do with the function that change the WriteableBitmap in a byte array. I took the function from an open source GBA graphic editor that already exists and modified it a bit. Here's the function:


        static public byte[] toGbaRaw(WriteableBitmap wBmp, int emptyGraphBlocks, List<Color> pal)
        {
            byte[] result = new byte[wBmp.PixelWidth * wBmp.PixelHeight * (int)bpp / 8 - emptyGraphBlocks * 8 * (int)bpp];

            for (int i = 0; i < result.Length; i++)
            {
                // bpp value is 4
                Point coord = tiledCoord(i * 8 / (int)bpp, wBmp.PixelWidth, 8);
                Color color1 = wBmp.GetPixel((int)coord.X, (int)coord.Y);
                Color color2 = wBmp.GetPixel((int)coord.X + 1, (int)coord.Y);

                byte value = 0x00;

                // if not transparency
                if(!color1.Equals(Color.FromArgb(0x00, 0x00, 0x00, 0x00)))
                {
                    value = (byte)(pal.IndexOf(color1) & 0xF);
                }

                // if not transparency
                if (!color2.Equals(Color.FromArgb(0x00, 0x00, 0x00, 0x00)))
                {
                    value += (byte)(pal.IndexOf(color2) & 0xF);
                }

                result[i] = value;
            }

            return result;
        }


I've been trying different things to solve this problem in the last few day but nothing seems to work. :banghead: Does anyone has an idea what would be wrong? Thanks in advance

For the record here's the function that takes a byte array and transform it into a bitmap. This one works correctly:


        static public unsafe WriteableBitmap toBmp(byte* graph, int length, int width, Color[] pal, out int emptyGraphPlocks)
        {
            int height, add;
            add = 0;

            if (length % (32 * width) != 0)
                add = 1;

            height = (((length / 32) - (length / 32) % width) / width + add);
            emptyGraphPlocks = (width * height) - (length / 32);

            BitmapPalette bPal = new BitmapPalette(pal);
            WriteableBitmap wBmp = new WriteableBitmap(width * 8, height * 8, 96, 96, PixelFormats.Pbgra32, null);

            for (int i = 0; i < length; i++)
            {
                Point pt = tiledCoord(i * 2, width * 8, 8);
                wBmp.SetPixel((int)pt.X, (int)pt.Y, bPal.Colors[*(graph + i) & 0xF]);
                wBmp.SetPixel((int)(pt.X + 1), (int)pt.Y, bPal.Colors[(*(graph + i) >> 4) & 0xF]);
            }

            return wBmp;
        }

KC

You need to shift the second index left by four bits.

value |= (byte)((pal.IndexOf(color2) & 0xF) << 4);

Madsiur

Yes! That did it! Thanks a lot KC!