Ejemplo n.º 1
0
        Size AskTileSize()
        {
            TileSizeForm form = new TileSizeForm();

            form.ShowDialog(DocManager.GetFrameParent());
            return(form.GetTileSize());
        }
Ejemplo n.º 2
0
        Document OpenFinish(Document doc)
        {
            // This doc is being opened

            doc.IncrementOpenCount();

            // Doc is not modified

            doc.SetModified(false);

            // Make it active

            SetActiveDocument(doc);

            // Create a frame window of the desired type. It might already know what
            // view type to create, but parameterize it just in case

            if (m_typeFrame != null)
            {
                Object[] aobjT = { DocManager.GetFrameParent(), doc, m_typeView };
                System.Activator.CreateInstance(m_typeFrame, aobjT);
            }

            // The doc is ready to go

            doc.InitDone();
            return(doc);
        }
Ejemplo n.º 3
0
        private void menuItemScaleDown_Click(object sender, System.EventArgs e)
        {
            // If no template doc active, bail

            if (m_tmpdActive == null)
            {
                return;
            }

            // Make sure 24 x 24 (could actually allow any sort of conversion...)

            if (m_tmpdActive.TileSize.Width != 24 && m_tmpdActive.TileSize.Height != 24)
            {
                MessageBox.Show(DocManager.GetFrameParent(), "The current template collection must be 24 x 24 tile size");
                return;
            }

            // Get busy

            TemplateDoc tmpdDst = TemplateTools.CloneTemplateDoc(m_tmpdActive);

            TemplateTools.ScaleTemplates(tmpdDst, new Size(16, 16));
            TemplateTools.QuantizeTemplates(tmpdDst, null, 0, 0, 0);
            DocManager.SetActiveDocument(typeof(TemplateDoc), tmpdDst);
        }
Ejemplo n.º 4
0
 static public void ShowIt()
 {
     if (s_frm == null)
     {
         s_frm       = new OutputForm();
         s_frm.Owner = DocManager.GetFrameParent();
     }
     s_frm.Show();
     s_frm.BringToFront();
 }
Ejemplo n.º 5
0
        private void menuItemSavePalette_Click(object sender, System.EventArgs e)
        {
            if (m_tmpdActive == null)
            {
                return;
            }
            Palette pal = m_tmpdActive.GetPalette();

            if (pal == null)
            {
                MessageBox.Show(DocManager.GetFrameParent(), "No palette on this template collection. You need to create one!");
                return;
            }
            pal.SaveDialog();
        }
Ejemplo n.º 6
0
        private void buttonOK_Click(object sender, System.EventArgs e)
        {
            // If custom, validate

            if (radioButtonCustom.Checked)
            {
                int cx = int.Parse(textBoxWidth.Text);
                int cy = int.Parse(textBoxHeight.Text);
                if (cx <= 0 || cx > 64 || cy <= 0 || cy > 64)
                {
                    MessageBox.Show(DocManager.GetFrameParent(), "Invalid custom tile size. Try again.");
                    return;
                }
                m_sizTile = new Size(cx, cy);
            }

            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 7
0
        public static void QuantizeTemplates(TemplateDoc tmpd, Palette palFixed, int cPalEntries, int cPalEntriesFixed, int cPalEntriesBackground)
        {
            // Load the fixed palette. The result will be 24 bit templates normalized to a palette of 256 colors,
            // the "fixed" palette plus a quantized palette.

            if (palFixed == null)
            {
                palFixed = Palette.OpenDialog(null);
                if (palFixed == null)
                {
                    MessageBox.Show(DocManager.GetFrameParent(), "Must have the fixed color palette to continue!");
                    return;
                }

                switch (palFixed.Length)
                {
                case 16:
                    cPalEntries           = 16;
                    cPalEntriesFixed      = 16;
                    cPalEntriesBackground = 0;
                    break;

                case 256:
                    cPalEntries           = 256;
                    cPalEntriesFixed      = 128;
                    cPalEntriesBackground = 32;
                    break;
                }
            }

            // Quantize loop. Designed to make optimal use of the lower 128 fixed colors

            // Quantize background separately from foreground

            Template tmplBackground = tmpd.GetBackgroundTemplate();

            if (tmplBackground != null && cPalEntriesBackground != 0)
            {
                // Create a despeckled hue map of the background. We'll use this to
                // subtract background from foreground so we can quantize foreground separately

                Bitmap bmHueBackground = MakeHueMap(tmplBackground.Bitmap);
                DespeckleGrayscaleBitmap(bmHueBackground, 9, 50);

                // Calc mean and standard deviation for filtering purposes

                double nMean   = CalcGrayscaleMean(bmHueBackground);
                double nStdDev = CalcGrayscaleStandardDeviation(bmHueBackground, nMean);

                // Add extract & quantize the background pixels

                ArrayList alsColorsBackground = new ArrayList();
                AddTemplateColors(alsColorsBackground, tmplBackground.Bitmap);
                palFixed          = QuantizeColors(alsColorsBackground, palFixed, cPalEntriesFixed + cPalEntriesBackground, cPalEntriesFixed);
                cPalEntriesFixed += cPalEntriesBackground;

                // Now extract foreground pixels by first subtracting background pixels

                ArrayList  alsColorsForeground = new ArrayList();
                Template[] atmpl = tmpd.GetTemplates();
                foreach (Template tmpl in atmpl)
                {
                    if (tmpl == tmplBackground)
                    {
                        continue;
                    }
                    Bitmap bmT = MakeHueMap(tmpl.Bitmap);
                    DespeckleGrayscaleBitmap(bmT, 9, 50);
                    SubtractGrayscaleDistribution(bmT, nMean, nStdDev);
                    for (int y = 0; y < bmT.Height; y++)
                    {
                        for (int x = 0; x < bmT.Width; x++)
                        {
                            Color clr = bmT.GetPixel(x, y);
                            if (clr != Color.FromArgb(255, 0, 255))
                            {
                                bmT.SetPixel(x, y, tmpl.Bitmap.GetPixel(x, y));
                            }
                        }
                    }
                    AddTemplateColors(alsColorsForeground, bmT);
                }

                // Now quantize foreground pixels
                // Set the palette and color match

                Palette palNew = QuantizeColors(alsColorsForeground, palFixed, cPalEntries, cPalEntriesFixed);
                tmpd.SetPalette(palNew, true);
            }
            else
            {
                // No background template; just quantize everything together

                Template[] atmpl     = tmpd.GetTemplates();
                ArrayList  alsColors = new ArrayList();
                foreach (Template tmpl in atmpl)
                {
                    AddTemplateColors(alsColors, tmpl.Bitmap);
                }

                // Now quantize foreground pixels
                // Set the palette and color match

                Palette palNew = QuantizeColors(alsColors, palFixed, cPalEntries, cPalEntriesFixed);
                tmpd.SetPalette(palNew, true);
            }
        }