Beispiel #1
0
        void TranslateImage(string ImageFileName, ref string CodeOutput, ref string HeaderOutput, string SpriteStructNamePrefix, eGFX_ImagePlaneType IPT)
        {
            CodeOutput   = "";
            HeaderOutput = "";

            if (File.Exists(ImageFileName) == false)
            {
                MessagePost("Could not open " + ImageFileName);
                return;
            }

            Bitmap NextBmp = new Bitmap(ImageFileName);

            MessagePost(ImageFileName + " is " + NextBmp.Width + " x " + NextBmp.Height + " pixels");

            string SpriteNameBase = Path.GetFileName(ImageFileName);

            string [] Splits     = SpriteNameBase.Split('.');
            string    SpriteName = Splits[0];


            #region Binary Sprite Form

            eGFX_ImagePlane NextSprite = new eGFX_ImagePlane(NextBmp.Width, NextBmp.Height, IPT);

            #region Gather Sprite Data

            for (int y = 0; y < NextBmp.Height; y++)
            {
                for (int x = 0; x < NextBmp.Width; x++)
                {
                    Color PixelColor = NextBmp.GetPixel(x, y);

                    UInt32 Y = (UInt32)((PixelColor.R * 0.299) + (PixelColor.G * 0.587) + (PixelColor.B * 0.114));

                    switch (NextSprite.Type)
                    {
                    case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_1BPP:

                        if (Y > 0x7f)
                        {
                            NextSprite.PutPixel(x, y, 0xFFFFFFFF);                  //median cut
                        }
                        else
                        {
                            NextSprite.PutPixel(x, y, 0);
                        }

                        break;

                    case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_4BPP:

                        NextSprite.PutPixel(x, y, (Y) >> 4);                    //median cut

                        break;

                    case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_8BPP:
                        NextSprite.PutPixel(x, y, Y);
                        break;
                    }
                }
            }

            #endregion

            string RawDataArrayString     = SpriteStructNamePrefix + SpriteName + "_Data";
            string SpriteStructNameString = SpriteStructNamePrefix + SpriteName;


            CodeOutput += "\r\n";
            CodeOutput += "////***************************************************************************\r\n";
            CodeOutput += "////                            " + SpriteStructNameString + "\r\n";
            CodeOutput += "////***************************************************************************\r\n";

            HeaderOutput += "\r\n";
            HeaderOutput += "////***************************************************************************\r\n";
            HeaderOutput += "////                         " + SpriteStructNameString + "\r\n";
            HeaderOutput += "////***************************************************************************\r\n\r\n";

            HeaderOutput += "\r\nextern const eGFX_ImagePlane \t" + SpriteStructNameString + ";\r\n";


            CodeOutput += "\r\nconst uint8_t " + RawDataArrayString + "[" + NextSprite.Data.Length + "] = { ";

            for (int i = 0; i < NextSprite.Data.Length; i++)
            {
                if (i % 16 == 0)
                {
                    CodeOutput += "\r\n";
                }

                CodeOutput += "0x" + String.Format("{0:X2}", NextSprite.Data[i]);
                if (i == NextSprite.Data.Length - 1)
                {
                    CodeOutput += " }; \r\n\r\n";
                }
                else
                {
                    CodeOutput += ",";
                }
            }



            CodeOutput += "const eGFX_ImagePlane " + SpriteStructNameString + " = { " + IPT.ToString() + ",(uint8_t *)&" + RawDataArrayString + ",(uint16_t)" + NextBmp.Width + ",(uint16_t)" + NextBmp.Height + "};\r\n";


            #endregion


            MessagePost(CodeOutput);
        }
Beispiel #2
0
        void TranslateImage(string ImageFileName, ref string CodeOutput, ref string HeaderOutput,string SpriteStructNamePrefix, eGFX_ImagePlaneType IPT)
        {
            CodeOutput = "";
            HeaderOutput = "";

            if (File.Exists(ImageFileName) == false)
            {
                MessagePost("Could not open " + ImageFileName);
                return;
            }

            Bitmap NextBmp = new Bitmap(ImageFileName);

            MessagePost(ImageFileName + " is " + NextBmp.Width + " x " + NextBmp.Height + " pixels");

            string SpriteNameBase = Path.GetFileName(ImageFileName);
            string [] Splits = SpriteNameBase.Split('.');
            string SpriteName = Splits[0];

               #region Binary Sprite Form

               eGFX_ImagePlane NextSprite = new eGFX_ImagePlane(NextBmp.Width, NextBmp.Height, IPT);

                    #region Gather Sprite Data

                    for (int y = 0; y < NextBmp.Height; y++)
                          {
                            for (int x = 0; x < NextBmp.Width; x++)
                            {
                                Color PixelColor = NextBmp.GetPixel(x, y);

                                UInt32 Y = (UInt32)((PixelColor.R * 0.299) + (PixelColor.G * 0.587) + (PixelColor.B * 0.114));

                                switch(NextSprite.Type)
                                {
                                    case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_1BPP:

                                        if (Y > 0x7f)
                                        {
                                            NextSprite.PutPixel(x, y, 0xFFFFFFFF);  //median cut
                                        }
                                        else
                                        {
                                            NextSprite.PutPixel(x, y, 0);
                                        }

                                        break;

                                    case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_4BPP:

                                            NextSprite.PutPixel(x, y, (Y)>>4);  //median cut

                                        break;

                                    case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_8BPP:
                                             NextSprite.PutPixel(x, y, Y);
                                        break;
                                }

                            }

                          }

                    #endregion

                    string RawDataArrayString = SpriteStructNamePrefix + SpriteName + "_Data";
                    string SpriteStructNameString = SpriteStructNamePrefix + SpriteName;

                CodeOutput += "\r\n";
                CodeOutput += "////***************************************************************************\r\n";
                CodeOutput += "////                            " +SpriteStructNameString+ "\r\n";
                CodeOutput += "////***************************************************************************\r\n";

                HeaderOutput += "\r\n";
                HeaderOutput += "////***************************************************************************\r\n";
                HeaderOutput += "////                         " + SpriteStructNameString + "\r\n";
                HeaderOutput += "////***************************************************************************\r\n\r\n";

                HeaderOutput += "\r\nextern const eGFX_ImagePlane \t" + SpriteStructNameString + ";\r\n";

                CodeOutput += "\r\nconst uint8_t " + RawDataArrayString + "[" + NextSprite.Data.Length + "] = { ";

                for(int i=0;i< NextSprite.Data.Length;i++)
                {
                    if(i%16 == 0)
                    {
                        CodeOutput += "\r\n";
                    }

                    CodeOutput += "0x" + String.Format("{0:X2}",NextSprite.Data[i]);
                    if(i == NextSprite.Data.Length - 1)
                    {
                        CodeOutput += " }; \r\n\r\n";
                    }
                    else
                    {
                        CodeOutput += ",";
                    }
                }

                CodeOutput += "const eGFX_ImagePlane " + SpriteStructNameString + " = { " + IPT.ToString() + ",(uint8_t *)&" + RawDataArrayString + ",(uint16_t)" + NextBmp.Width + ",(uint16_t)" + NextBmp.Height + "};\r\n";

                 #endregion

               MessagePost(CodeOutput);
        }