public static Bitmap imageLoader(GBAROM ROM, int imageOffset, int paletteOffset, int width, int height, bool isImageCompressed, bool isPaletteCompressed, bool transparent, GraphicsMode mode)
        {
            DataBuffer rawGraphics = new DataBuffer(0x8000);
            DataBuffer rawPalette = new DataBuffer(0x100);
            if (isImageCompressed)
            {
                rawGraphics.ReadCompressedData(ROM, imageOffset);
            }
            else
            {
                int gfxlength = GBAGraphics.RawGraphicsLength(new Size(width * 8, height * 8), mode);
                rawGraphics.ReadData(ROM, imageOffset, gfxlength);
            }

            if (isPaletteCompressed)
            {
                rawPalette.ReadCompressedData(ROM, paletteOffset);
            }
            else
            {
                rawPalette.ReadData(ROM, paletteOffset, 0x200);
            }

            byte[] graphics = rawGraphics.ToArray();
            int bitsPerPixel = GBAGraphics.BitsPerPixel(mode);

            int length = Math.Min(bitsPerPixel * width * height / 8, graphics.Length);
            Color[] palette;

            if (rawPalette.Length > 0 && paletteOffset != 0)
                palette = GBAPalette.ToPalette(rawPalette.ToArray(), 0, rawPalette.Length / 2);
            else
            {
                palette = new Color[16];
                for (int i = 0; i < palette.Length; i++)
                    palette[i] = Color.FromArgb(i * (256 / palette.Length), i * (256 / palette.Length), i * (256 / palette.Length));
            }

            int empty;
            if(transparent)
                palette[0] = Color.FromArgb(0, palette[0]);
            return GBAGraphics.ToBitmap(graphics, length, 0, palette, width, mode, out empty);
        }