Пример #1
0
        static int Main(string[] astrArgs)
        {
            if (astrArgs.Length < 3)
            {
                Console.WriteLine("Usage:\nbscale -scale <scale> -pal <palette.pal> <file(s) ...> -out <outdir>\n");
                return(-1);
            }

            double    nScale = 1.0;
            string    strOutDir = null, strPalette = null;
            ArrayList alFileSpecs = new ArrayList();

            for (int iarg = 0; iarg < astrArgs.Length; iarg++)
            {
                if (astrArgs[iarg][0] == '-')
                {
                    switch (astrArgs[iarg])
                    {
                    case "-scale":
                        nScale = double.Parse(astrArgs[++iarg]);
                        break;

                    case "-out":
                        strOutDir = astrArgs[++iarg];
                        break;

                    case "-pal":
                        strPalette = astrArgs[++iarg];
                        break;
                    }
                }
                else
                {
                    alFileSpecs.Add(astrArgs[iarg]);
                }
            }

            // Read in the palette

            Palette pal = new Palette(strPalette);

            if (pal == null)
            {
                Console.WriteLine("Error: unable to read the palette file {0}\n", strPalette);
                return(-1);
            }

            foreach (string strFileSpec in alFileSpecs)
            {
                Console.WriteLine("dir = " + Path.GetDirectoryName(strFileSpec) + ", file = " + Path.GetFileName(strFileSpec));
                string[] astrFiles = Directory.GetFiles(Path.GetDirectoryName(strFileSpec), Path.GetFileName(strFileSpec));

                foreach (string strFile in astrFiles)
                {
                    Console.WriteLine(strFile);
                    Bitmap bm       = new Bitmap(strFile);
                    Bitmap bmScaled = TBitmapTools.ScaleBitmap(bm, nScale, pal);
                    if (!Directory.Exists(strOutDir))
                    {
                        Directory.CreateDirectory(strOutDir);
                    }

                    bmScaled.Save(strOutDir + Path.DirectorySeparatorChar +
                                  Path.GetFileName(strFile), bm.RawFormat);
                }
            }

            return(0);
        }
Пример #2
0
        Bitmap[] GetBitmapSides(Bitmap bmUnscaled, Size sizTile)
        {
            // Maps the blues into a new hue

            Color[][] aaclr =
            {
                new Color[] {
                    // gray
                    Color.FromArgb(116, 116, 116),
                    Color.FromArgb(96, 96, 96),
                    Color.FromArgb(64, 64, 64),
                    Color.FromArgb(48, 48, 48),
                    Color.FromArgb(32, 32, 32)
                },
                new Color[] {
                    // blue
                    Color.FromArgb(0, 116, 232),                                                                                // (h: 149, s: 255, l: 116)
                    Color.FromArgb(0, 96, 196),                                                                                 // (h: 149, s: 255, l: 98)
                    Color.FromArgb(0, 64, 120),                                                                                 // (h: 147, s: 255, l: 60)
                    Color.FromArgb(0, 48, 92),                                                                                  // (h: 148, s: 255, l: 46)
                    Color.FromArgb(0, 32, 64)                                                                                   // (h: 149, s: 255, l: 32)
                },
                new Color[] {
                    // red (h: 6)
                    Color.FromArgb(232, 32, 0),
                    Color.FromArgb(196, 28, 0),
                    Color.FromArgb(128, 8, 0),
                    Color.FromArgb(92, 8, 0),
                    Color.FromArgb(64, 8, 0)
                },
                new Color[] {
                    // yellow (h: 42)
                    Color.FromArgb(232, 229, 0),
                    Color.FromArgb(196, 194, 0),
                    Color.FromArgb(120, 119, 0),
                    Color.FromArgb(92, 91, 0),
                    Color.FromArgb(64, 63, 0)
                },
                new Color[] {
                    // cyan
                    Color.FromArgb(0, 229, 232),                                                                                // (h: 128, s: 255, l: 116)
                    Color.FromArgb(0, 194, 196),                                                                                // (h: 128, s: 255, l: 98)
                    Color.FromArgb(0, 119, 120),                                                                                // (h: 128, s: 255, l: 60)
                    Color.FromArgb(0, 91, 92),                                                                                  // (h: 128, s: 255, l: 46)
                    Color.FromArgb(0, 63, 64)                                                                                   // (h: 128, s: 255, l: 32)
                },
                new Color[] {
                    // green (h: 104)
                    Color.FromArgb(0, 232, 104),
                    Color.FromArgb(0, 196, 88),
                    Color.FromArgb(0, 120, 54),
                    Color.FromArgb(0, 92, 41),
                    Color.FromArgb(0, 64, 29)
                },
            };

            // Make the side bitmaps
            m_abmSides = new Bitmap[6];
            double nScale   = (double)sizTile.Width / 16.0;
            Bitmap bmScaled = TBitmapTools.ScaleBitmap(bmUnscaled, nScale, null);

            for (int i = 0; i < 6; i++)
            {
                Bitmap bmSide = new Bitmap(bmScaled);
                MapColors(bmSide, aaclr[1], aaclr[i]);
                MapColors(bmSide, new Color[] { Color.FromArgb(156, 212, 248) }, new Color[] { Color.FromArgb(75, 0, 0, 0) });

                // HACK: Map the transparent color manually because Mono's MakeTransparent doesn't get the job done.
                MapColors(bmSide, new Color[] { Color.FromArgb(255, 0, 255) }, new Color[] { Color.FromArgb(0, 0, 0, 0) });
                // bmSide.MakeTransparent(Color.FromArgb(255, 255, 0, 255));
                m_abmSides[i] = bmSide;
            }

            return(m_abmSides);
        }
Пример #3
0
        static Strip MakeHighlightStrip(AnimDoc doc, int cxTile,
                                        Palette palFixed)
        {
            Strip stpHelp = doc.StripSet["help"];

            if (stpHelp == null)
            {
                return(null);
            }

            // This does a deep copy
            Strip stpHighlight = (Strip)stpHelp.Clone();

            stpHighlight.Name = "highlight";

            // Figure out the scaling. It would be better to pass this in as
            // a parameter.

            Frame     frT     = stpHighlight[0];
            Rectangle rcUnion = new Rectangle();

            foreach (BitmapPlacer plc in frT.BitmapPlacers)
            {
                Rectangle rc = new Rectangle();
                rc.X      = -plc.X;
                rc.Y      = -plc.Y;
                rc.Width  = plc.XBitmap.Width;
                rc.Height = plc.XBitmap.Height;
                if (rcUnion.IsEmpty)
                {
                    rcUnion = rc;
                }
                else
                {
                    rcUnion = Rectangle.Union(rcUnion, rc);
                }
            }

            // Needs to be 4 tiles high. Keep aspect ratio

            int cy = rcUnion.Height;

            if (cy < cxTile * 4)
            {
                cy = cxTile * 4;
            }
            double nScale = 1.0;

            if (cy > rcUnion.Height)
            {
                nScale = (double)cy / (double)rcUnion.Height;
            }

            // Scale

            if (nScale != 1.0)
            {
                foreach (Frame fr in stpHighlight)
                {
                    foreach (BitmapPlacer plc in fr.BitmapPlacers)
                    {
                        plc.XBitmap.Bitmap = TBitmapTools.ScaleBitmap(
                            plc.XBitmap.Bitmap, nScale, palFixed);
                        plc.X = (int)Math.Round(plc.X * nScale);
                        plc.Y = (int)Math.Round(plc.Y * nScale);
                    }

                    Point pt = new Point();
                    pt.X            = (int)Math.Round(fr.SpecialPoint.X * nScale);
                    pt.Y            = (int)Math.Round(fr.SpecialPoint.Y * nScale);
                    fr.SpecialPoint = pt;
                }
            }

            return(stpHighlight);
        }
Пример #4
0
        static void Scale(AnimDoc doc, double nScale, Palette palFixed, bool fScaleIcon)
        {
            if (nScale >= 1.5)
            {
                doc.Hires = true;
            }

            // If not scaling icon, make a clone of it so it doesn't get scaled,
            // then after scaling set this clone back in.

            Strip stpIcon      = doc.StripSet["icon"];
            Strip stpIconClone = null;

            if (!fScaleIcon && stpIcon != null)
            {
                stpIconClone = (Strip)stpIcon.Clone();
            }

            // Scale all the bitmaps

            foreach (XBitmap xbm in doc.XBitmapSet)
            {
                // Scale

                xbm.Bitmap = TBitmapTools.ScaleBitmap(xbm.Bitmap, nScale, palFixed);

                // Scale the points in the frames that use this bitmap

                foreach (Strip stp in doc.StripSet)
                {
                    foreach (Frame fr in stp)
                    {
                        foreach (BitmapPlacer plc in fr.BitmapPlacers)
                        {
                            if (plc.XBitmap == xbm)
                            {
                                plc.X = (int)Math.Round(plc.X * nScale);
                                plc.Y = (int)Math.Round(plc.Y * nScale);
                            }
                        }
                    }
                }
            }

            // Scale all special points too

            foreach (Strip stp in doc.StripSet)
            {
                foreach (Frame fr in stp)
                {
                    Point pt = new Point();
                    pt.X            = (int)Math.Round(fr.SpecialPoint.X * nScale);
                    pt.Y            = (int)Math.Round(fr.SpecialPoint.Y * nScale);
                    fr.SpecialPoint = pt;
                }
            }

            // Put the strip icon back in if it shouldn't be scaled

            if (!fScaleIcon && stpIconClone != null)
            {
                // Patch in the clone and add the images to the XBitmapSet
                // (they are not added auto-magically).

                doc.StripSet[doc.StripSet.IndexOf(stpIcon)] = stpIconClone;
                foreach (Frame fr in stpIconClone)
                {
                    foreach (BitmapPlacer plc in fr.BitmapPlacers)
                    {
                        doc.XBitmapSet.Add(plc.XBitmap);
                    }
                }
            }
        }
Пример #5
0
        static void Main(string[] astr)
        {
            // Special cases
            if (astr.Length == 0)
            {
                Usage();
                return;
            }

            bool   fRaw        = false;
            bool   fFont       = false;
            double nScale      = 1.0;
            bool   fSaveScaled = false;

            int istr = 0;

            for (; istr < astr.Length; istr++)
            {
                if (astr[istr][0] != '-')
                {
                    break;
                }
                switch (astr[istr])
                {
                case "-raw":
                    fRaw = true;
                    break;

                case "-font":
                    fFont = true;
                    break;

                case "-scale":
                    istr++;
                    nScale = double.Parse(astr[istr]);
                    break;

                case "-savescaled":
                    fSaveScaled = true;
                    break;
                }
            }

            // Params: palette outputdir filespecs
            // Get palette
            Palette pal = new Palette(astr[istr++]);

            // Get directory
            string strDir = astr[istr++];

            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (; istr < astr.Length; istr++)
            {
                string strFileT = Path.GetFileName(astr[istr]);
                string strDirT  = Path.GetDirectoryName(astr[istr]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            // Output
            if (fFont)
            {
                foreach (string strFile in alsFiles)
                {
                    string strFileFnt   = strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFile.Substring(0, strFile.Length - 4) + ".fnt");
                    string strFileAscii = Path.GetDirectoryName(strFile) + Path.DirectorySeparatorChar + Path.GetFileName(strFile.Substring(0, strFile.Length - 4) + ".txt");
                    Console.WriteLine(strFile + " -> " + strFileFnt);
                    TBitmap.SaveFont(strFile, pal, strFileAscii, strFileFnt);
                }
            }
            else
            {
                if (fRaw)
                {
                    foreach (string strFile in alsFiles)
                    {
                        string strFileRaw = strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFile.Substring(0, strFile.Length - 4) + ".rbm");
                        BitmapRaw.Save(strFile, pal, strFileRaw);
                    }
                }
                else
                {
                    foreach (string strFile in alsFiles)
                    {
                        string strFileTbm = strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFile.Substring(0, strFile.Length - 4) + ".tbm");
                        Console.WriteLine(strFile + " -> " + strFileTbm);
                        Bitmap[] abm = new Bitmap[1];
                        abm[0] = new Bitmap(strFile);
                        if (nScale != 1.0)
                        {
                            abm[0] = TBitmapTools.ScaleBitmap(abm[0], nScale, pal);
                        }
                        if (fSaveScaled)
                        {
                            abm[0].Save(Path.Combine(strDir, Path.GetFileName(strFile)), ImageFormat.Bmp);
                        }
                        else
                        {
                            TBitmap.Save(abm, pal, strFileTbm);
                        }
                    }
                }
            }
        }