Exemplo n.º 1
0
 public BitmapInfo(OutputConfiguration outConfig, Bitmap bmp, Dictionary <Color, bool> colorList)
 {
     OutConfig      = outConfig;
     Original       = bmp;
     OriginalBorder = Border.GetBorders(Original, MyExtensions.GetEnabledKeys <Color>(colorList));
     ColorList      = colorList;
 }
Exemplo n.º 2
0
        private void updateBitmapPreview()
        {
            if (checkGroupBoxFontImage.Checked && m_currentLoadedBitmap != null)
            {
                int w            = (int)numericUpDownInputImageTileSizeX.Value;
                int h            = (int)numericUpDownInputImageTileSizeY.Value;
                int tilesPerLine = (int)numericUpDownInputImageTilesPerLine.Value;

                Point p = new Point(hScrollBarInputImageCharacterPos.Value % tilesPerLine * w, hScrollBarInputImageCharacterPos.Value / tilesPerLine * h);

                Rectangle r = new Rectangle(p, new Size(w, h));
                Color     c;
                if (colorList.ContainsValue(true))
                {
                    c = MyExtensions.GetEnabledKeys(colorList)[0];
                }
                else
                {
                    c = Color.Transparent;
                }
                Bitmap character = MyExtensions.Clone(m_currentLoadedBitmap, r, PixelFormat.Format32bppArgb, c);;

                Size newSize = r.Size;
                int  faktor  = 1;

                while (newSize.Height <= 32)
                {
                    newSize.Height *= 2;
                    newSize.Width  *= 2;
                    faktor         *= 2;
                }

                //convert to black white image
                character = MyExtensions.ToBitmap(MyExtensions.ToArgbArray(character).Select(argb =>
                {
                    return(colorList[Color.FromArgb(argb)] ? Color.Black.ToArgb() : Color.White.ToArgb());
                }).ToArray(), r.Size);

                pictureBoxInputImageFontCharacterPreview.Image = MyExtensions.ResizeImage(character, faktor);
                pictureBoxInputImageFontCharacterPreview.Size  = newSize;
            }
        }
Exemplo n.º 3
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));
            }
        }