示例#1
0
        /** Constructs the palette from a .pal file */
        public Palette(String path)
        {
            try
            {
                if (System.IO.Path.GetExtension(path) != ".pal")
                    throw new Exception("palette must be a .pal file.");
                String[] lines = System.IO.File.ReadAllLines(path);
                if (lines.Length < 3)
                    throw new Exception("invalid .pal file: Less that 3 lines in length.");

                int numberOfColours = int.Parse(lines[2]);

                if (lines.Length - 3 < numberOfColours)
                    throw new Exception("invalid number of colour entries.");

                for (int i = 0; i < numberOfColours; ++i)
                {
                    Colour colour = new Colour(lines[i + 3]);
                    int index = i << 2;
                    colours[index] = colour.r;
                    colours[index+1] = colour.g;
                    colours[index+2] = colour.b;
                }

                setTransparentColour(0);

                upload();
            }
            catch(Exception e)
            {
                throw new Exception(String.Format("Error loading palette \"{0}\": {1}", path, e.Message));
            }
        }
示例#2
0
 /** Construct the palette from an Imaging.ColorPalette object */
 public Palette(System.Drawing.Imaging.ColorPalette p)
 {
     for (int i = 0; i < p.Entries.Length; ++i)
     {
         Colour colour = new Colour(p.Entries[i]);
         int index = i * 4;
         colours[index] = colour.r;
         colours[index + 1] = colour.g;
         colours[index + 2] = colour.b;
     }
     setTransparentColour(0);
     upload();
 }