示例#1
0
        private void generateOutputForFontImage(OutputConfiguration outConfig,
                                                Dictionary <Color, bool> colorList,
                                                Size tileSize,
                                                int codepage,
                                                Bitmap bitmapOriginal,
                                                StringBuilder textSource,
                                                StringBuilder textHeader)
        {
            // the name of the bitmap
            string imageName;

            Color[]    backgroundColors;
            BitmapInfo bi;

            textSource.Clear();
            textHeader.Clear();

            if (bitmapOriginal == null || txtImageName.Text == "")
            {
                textSource.Append("No image found ");
                return;
            }

            imageName        = MyExtensions.ScrubVariableName(txtImageName.Text);
            backgroundColors = MyExtensions.GetEnabledKeys <Color>(colorList);

            // check if bitmap is assigned
            if (m_currentLoadedBitmap != null)
            {
                //
                // Bitmap manipulation
                //
                bi = new BitmapInfo(m_outputConfig, m_currentLoadedBitmap, colorList);

                // try to manipulate the bitmap

                if (!bi.GenerateManipulatetBitmap(bi.OriginalBorder))
                {
                    // show error
                    MessageBox.Show("No blackground pixels found in bitmap",
                                    "Can't convert bitmap",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);

                    // stop here, failed to manipulate the bitmap for whatever reason
                    return;
                }

                // according to config
                if (m_outputConfig.addCommentVariableName)
                {
                    // add source file header
                    textSource.AppendFormat("{0}" + m_outputConfig.nl + "{1} Image data for {2}" + m_outputConfig.nl + "{3}" + m_outputConfig.nl + m_outputConfig.nl,
                                            m_outputConfig.CommentStart,
                                            m_outputConfig.CommentBlockMiddle,
                                            imageName,
                                            m_outputConfig.CommentBlockEnd);

                    // add header file header
                    textHeader.AppendFormat("{0}Bitmap info for {1}{2}" + m_outputConfig.nl,
                                            m_outputConfig.CommentStart,
                                            imageName,
                                            m_outputConfig.CommentEnd);
                }

                // bitmap varname
                string bitmapVarName = String.Format(m_outputConfig.varNfImageBitmap, imageName) + "[]";

                // add to source
                textSource.AppendFormat("{0} =" + m_outputConfig.nl + "{{" + m_outputConfig.nl, bitmapVarName);

                //
                // Bitmap to string
                //
                // page array
                bi.GeneratePageArray();

                // assign pages for fully populated 8 bits
                int pagesPerRow = MyExtensions.ConvertValueByDescriptorFormat(OutputConfiguration.DescriptorFormat.DisplayInBytes, bi.BitmapToGenerate.Width);

                // now convert to string
                bi.GenerateCharacterDataDescriptorAndVisulazer();
                textSource.Append(bi.Descriptor);

                // close
                textSource.AppendFormat("}};" + m_outputConfig.nl + m_outputConfig.nl);

                // according to config
                if (m_outputConfig.addCommentVariableName)
                {
                    // set sizes comment
                    textSource.AppendFormat("{0}Bitmap sizes for {1}{2}" + m_outputConfig.nl,
                                            m_outputConfig.CommentStart, imageName, m_outputConfig.CommentEnd);
                }

                Func <string> getImageWidthString = () =>
                {
                    const string format = "\t{2}, {0} {3}{1}{4}";
                    // display width in bytes?
                    switch (m_outputConfig.descImgWidth)
                    {
                    case OutputConfiguration.DescriptorFormat.DisplayInBytes:
                        return(string.Format(format,
                                             m_outputConfig.CommentStart,
                                             m_outputConfig.CommentEnd,
                                             pagesPerRow,
                                             "Image width in bytes (pages)",
                                             m_outputConfig.nl));

                    case OutputConfiguration.DescriptorFormat.DisplayInBits:
                        return(string.Format(format,
                                             m_outputConfig.CommentStart,
                                             m_outputConfig.CommentEnd,
                                             bi.BitmapToGenerate.Width,
                                             "Image width in pixels",
                                             m_outputConfig.nl));

                    case OutputConfiguration.DescriptorFormat.DontDisplay:
                        return("");

                    default:
                        throw new NotImplementedException();
                    }
                };

                Func <string> getImageHeigtString = () =>
                {
                    const string format = "\t{2}, {0} {3}{1}{4}";

                    switch (m_outputConfig.descImgHeight)
                    {
                    case OutputConfiguration.DescriptorFormat.DisplayInBytes:
                        return(string.Format(format,
                                             m_outputConfig.CommentStart,
                                             m_outputConfig.CommentEnd,
                                             MyExtensions.ConvertValueByDescriptorFormat(OutputConfiguration.DescriptorFormat.DisplayInBytes, bi.BitmapToGenerate.Height),
                                             "Image height in bytes (pages)",
                                             m_outputConfig.nl));

                    case OutputConfiguration.DescriptorFormat.DisplayInBits:
                        return(string.Format(format,
                                             m_outputConfig.CommentStart,
                                             m_outputConfig.CommentEnd,
                                             bi.BitmapToGenerate.Height,
                                             "Image height in pixels",
                                             m_outputConfig.nl));

                    case OutputConfiguration.DescriptorFormat.DontDisplay:
                        return("");

                    default:
                        throw new NotImplementedException();
                    }
                };

                // get var name
                string imageInfoVarName = String.Format(m_outputConfig.varNfImageInfo, imageName);

                // image info header
                textHeader.AppendFormat("extern {0};" + m_outputConfig.nl, imageInfoVarName);

                // image info source
                textSource.AppendFormat("{2} =" + m_outputConfig.nl + "{{" + m_outputConfig.nl +
                                        "{3}" +
                                        "{4}" +
                                        "\t{5}, {0} Image bitmap array{1}" + m_outputConfig.nl +
                                        "}};" + m_outputConfig.nl,
                                        m_outputConfig.CommentStart,
                                        m_outputConfig.CommentEnd,
                                        imageInfoVarName,
                                        getImageWidthString(),
                                        getImageHeigtString(),
                                        MyExtensions.GetVariableNameFromExpression(bitmapVarName));
            }
        }
示例#2
0
 // generate the bitmap we will then use to convert to string (remove pad, flip)
 public bool GenerateManipulatetBitmap(Border tightestCommonBorder)
 {
     return(bitmapInfo.GenerateManipulatetBitmap(tightestCommonBorder));
 }