Esempio n. 1
0
 public override void Save(string filename, Endogine.ColorEx.Palette palette)
 {
     System.IO.BinaryWriter writer = new System.IO.BinaryWriter(new System.IO.FileStream(filename, System.IO.FileMode.OpenOrCreate));
     foreach (KeyValuePair <string, ColorEx.ColorBase> kv in palette)
     {
         //Vector4 v = color.VectorRGBA;
         System.Drawing.Color c = kv.Value.ColorRGBA;
         writer.Write((byte)(int)c.R);
         writer.Write((byte)(int)c.G);
         writer.Write((byte)(int)c.B);
     }
 }
Esempio n. 2
0
        public override Endogine.ColorEx.Palette Load(string filename)
        {
//              --readPainterTxt("C:\Program\Corel\Corel Painter IX\Color Sets\_test.txt")
//  --p-ut readPainterTxt("C:\Program\Corel\Corel Painter IX\Color Sets\Pantone\PANTONE(R) pastel coated.txt")
            string contents = Files.FileReadWrite.Read(filename);

            Endogine.ColorEx.Palette palette = new Endogine.ColorEx.Palette();

            //remove header:
            int indexR = contents.IndexOf("R:");

            contents = contents.Remove(0, indexR);

            int colorIndex = 0;

            //  nNumColors = szContents.lines.count
            string[] lines = contents.Split("\r\n".ToCharArray());
            foreach (string line in lines)
            {
                ColorEx.ColorRgb rgb   = new Endogine.ColorEx.ColorRgb();
                string[]         items = line.Split(':');
                rgb.R = this.GetPainterVal(items[0]);
                rgb.G = this.GetPainterVal(items[1]);
                rgb.B = this.GetPainterVal(items[2]);

                //TODO: they're not always present!!
                for (int i = 3; i < 6; i++)
                {
                    //aUnknowns[n] = me.cleanPainterVal(szLine.item[n+1])
                }

                string name  = colorIndex.ToString();
                int    index = line.IndexOf("VV");
                if (index >= 0)
                {
                    string vv = line.Remove(0, index);
                    index = vv.IndexOf("  ");
                    if (index >= 0)
                    {
                        name = vv.Remove(0, index + 2);
                        name = vv.Remove(vv.Length - 1);
                    }
                }
                palette.Add(name, rgb);
                colorIndex++;
            }
            return(palette);
        }
Esempio n. 3
0
        public override Endogine.ColorEx.Palette Load(string filename)
        {
            //              --readPainterTxt("C:\Program\Corel\Corel Painter IX\Color Sets\_test.txt")
            //  --p-ut readPainterTxt("C:\Program\Corel\Corel Painter IX\Color Sets\Pantone\PANTONE(R) pastel coated.txt")
            string contents = Files.FileReadWrite.Read(filename);

            Endogine.ColorEx.Palette palette = new Endogine.ColorEx.Palette();

            //remove header:
            int indexR = contents.IndexOf("R:");
            contents = contents.Remove(0, indexR);

            int colorIndex = 0;
            //  nNumColors = szContents.lines.count
            string[] lines = contents.Split("\r\n".ToCharArray());
            foreach (string line in lines)
            {
                ColorEx.ColorRgb rgb = new Endogine.ColorEx.ColorRgb();
                string[] items = line.Split(':');
                rgb.R = this.GetPainterVal(items[0]);
                rgb.G = this.GetPainterVal(items[1]);
                rgb.B = this.GetPainterVal(items[2]);

                //TODO: they're not always present!!
                for (int i = 3; i < 6; i++)
                {
                    //aUnknowns[n] = me.cleanPainterVal(szLine.item[n+1])
                }

                string name = colorIndex.ToString();
                int index = line.IndexOf("VV");
                if (index >= 0)
                {
                    string vv = line.Remove(0, index);
                    index = vv.IndexOf("  ");
                    if (index >= 0)
                    {
                        name = vv.Remove(0, index + 2);
                        name = vv.Remove(vv.Length-1);
                    }
                }
                palette.Add(name, rgb);
                colorIndex++;
            }
            return palette;
        }
Esempio n. 4
0
        public override Endogine.ColorEx.Palette Load(string filename)
        {
            Serialization.BinaryReaderEx reader = new BinaryReaderEx(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            int numColors = (int)(reader.BaseStream.Length / 3);
            Endogine.ColorEx.Palette palette = new Endogine.ColorEx.Palette();

            for (int i = 0; i < numColors; i++)
            {
                Vector4 v = new Vector4(0, 0, 0, 1);
                for (int channelNum = 0; channelNum < 3; channelNum++)
                    v[channelNum] = (float)reader.ReadByte() / 255;

                string name = i.ToString();
                ColorEx.ColorRgb rgb = new Endogine.ColorEx.ColorRgb();
                rgb.Vector = v;
                palette.Add(name, rgb);
            }
            return palette;
        }
Esempio n. 5
0
        public override Endogine.ColorEx.Palette Load(string filename)
        {
            Serialization.BinaryReaderEx reader = new BinaryReaderEx(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            int numColors = (int)(reader.BaseStream.Length / 3);

            Endogine.ColorEx.Palette palette = new Endogine.ColorEx.Palette();

            for (int i = 0; i < numColors; i++)
            {
                Vector4 v = new Vector4(0, 0, 0, 1);
                for (int channelNum = 0; channelNum < 3; channelNum++)
                {
                    v[channelNum] = (float)reader.ReadByte() / 255;
                }

                string           name = i.ToString();
                ColorEx.ColorRgb rgb  = new Endogine.ColorEx.ColorRgb();
                rgb.Vector = v;
                palette.Add(name, rgb);
            }
            return(palette);
        }
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.components = new System.ComponentModel.Container();
     Endogine.ColorEx.Palette palette1 = new Endogine.ColorEx.Palette();
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SwatchesForm));
     this.swatchesPanel1 = new Endogine.Editors.ColorEditors.SwatchesPanel();
     this.panel1 = new System.Windows.Forms.Panel();
     this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
     this.loadReplaceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     this.loadMergeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     this.saveAsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
     this.panel1.SuspendLayout();
     this.contextMenuStrip1.SuspendLayout();
     this.SuspendLayout();
     //
     // swatchesPanel1
     //
     this.swatchesPanel1.Location = new System.Drawing.Point(1, 1);
     this.swatchesPanel1.Name = "swatchesPanel1";
     this.swatchesPanel1.Palette = palette1;
     this.swatchesPanel1.Size = new System.Drawing.Size(60, 16);
     this.swatchesPanel1.SwatchSize = ((Endogine.EPoint)(resources.GetObject("swatchesPanel1.SwatchSize")));
     this.swatchesPanel1.TabIndex = 0;
     //
     // panel1
     //
     this.panel1.AutoScroll = true;
     this.panel1.Controls.Add(this.swatchesPanel1);
     this.panel1.Location = new System.Drawing.Point(0, 0);
     this.panel1.Name = "panel1";
     this.panel1.Size = new System.Drawing.Size(213, 144);
     this.panel1.TabIndex = 1;
     //
     // contextMenuStrip1
     //
     this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     this.loadReplaceToolStripMenuItem,
     this.loadMergeToolStripMenuItem,
     this.saveAsToolStripMenuItem,
     this.saveAsToolStripMenuItem1});
     this.contextMenuStrip1.Name = "contextMenuStrip1";
     this.contextMenuStrip1.Size = new System.Drawing.Size(178, 114);
     //
     // loadReplaceToolStripMenuItem
     //
     this.loadReplaceToolStripMenuItem.Name = "loadReplaceToolStripMenuItem";
     this.loadReplaceToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
     this.loadReplaceToolStripMenuItem.Text = "Load Replace...";
     this.loadReplaceToolStripMenuItem.Click += new System.EventHandler(this.loadReplaceToolStripMenuItem_Click);
     //
     // loadMergeToolStripMenuItem
     //
     this.loadMergeToolStripMenuItem.Name = "loadMergeToolStripMenuItem";
     this.loadMergeToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
     this.loadMergeToolStripMenuItem.Text = "Load Merge...";
     //
     // saveAsToolStripMenuItem
     //
     this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
     this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
     this.saveAsToolStripMenuItem.Text = "Save";
     //
     // saveAsToolStripMenuItem1
     //
     this.saveAsToolStripMenuItem1.Name = "saveAsToolStripMenuItem1";
     this.saveAsToolStripMenuItem1.Size = new System.Drawing.Size(177, 22);
     this.saveAsToolStripMenuItem1.Text = "Save As...";
     //
     // SwatchesForm
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize = new System.Drawing.Size(221, 173);
     this.ContextMenuStrip = this.contextMenuStrip1;
     this.Controls.Add(this.panel1);
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
     this.Name = "SwatchesForm";
     this.Text = "Color Swatches";
     this.Resize += new System.EventHandler(this.SwatchesForm_Resize);
     this.panel1.ResumeLayout(false);
     this.contextMenuStrip1.ResumeLayout(false);
     this.ResumeLayout(false);
 }
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.components = new System.ComponentModel.Container();
     Endogine.ColorEx.Palette palette1 = new Endogine.ColorEx.Palette();
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SwatchesForm));
     this.swatchesPanel1               = new Endogine.Editors.ColorEditors.SwatchesPanel();
     this.panel1                       = new System.Windows.Forms.Panel();
     this.contextMenuStrip1            = new System.Windows.Forms.ContextMenuStrip(this.components);
     this.loadReplaceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     this.loadMergeToolStripMenuItem   = new System.Windows.Forms.ToolStripMenuItem();
     this.saveAsToolStripMenuItem      = new System.Windows.Forms.ToolStripMenuItem();
     this.saveAsToolStripMenuItem1     = new System.Windows.Forms.ToolStripMenuItem();
     this.panel1.SuspendLayout();
     this.contextMenuStrip1.SuspendLayout();
     this.SuspendLayout();
     //
     // swatchesPanel1
     //
     this.swatchesPanel1.Location   = new System.Drawing.Point(1, 1);
     this.swatchesPanel1.Name       = "swatchesPanel1";
     this.swatchesPanel1.Palette    = palette1;
     this.swatchesPanel1.Size       = new System.Drawing.Size(60, 16);
     this.swatchesPanel1.SwatchSize = ((Endogine.EPoint)(resources.GetObject("swatchesPanel1.SwatchSize")));
     this.swatchesPanel1.TabIndex   = 0;
     //
     // panel1
     //
     this.panel1.AutoScroll = true;
     this.panel1.Controls.Add(this.swatchesPanel1);
     this.panel1.Location = new System.Drawing.Point(0, 0);
     this.panel1.Name     = "panel1";
     this.panel1.Size     = new System.Drawing.Size(213, 144);
     this.panel1.TabIndex = 1;
     //
     // contextMenuStrip1
     //
     this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
         this.loadReplaceToolStripMenuItem,
         this.loadMergeToolStripMenuItem,
         this.saveAsToolStripMenuItem,
         this.saveAsToolStripMenuItem1
     });
     this.contextMenuStrip1.Name = "contextMenuStrip1";
     this.contextMenuStrip1.Size = new System.Drawing.Size(178, 114);
     //
     // loadReplaceToolStripMenuItem
     //
     this.loadReplaceToolStripMenuItem.Name   = "loadReplaceToolStripMenuItem";
     this.loadReplaceToolStripMenuItem.Size   = new System.Drawing.Size(177, 22);
     this.loadReplaceToolStripMenuItem.Text   = "Load Replace...";
     this.loadReplaceToolStripMenuItem.Click += new System.EventHandler(this.loadReplaceToolStripMenuItem_Click);
     //
     // loadMergeToolStripMenuItem
     //
     this.loadMergeToolStripMenuItem.Name = "loadMergeToolStripMenuItem";
     this.loadMergeToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
     this.loadMergeToolStripMenuItem.Text = "Load Merge...";
     //
     // saveAsToolStripMenuItem
     //
     this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
     this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(177, 22);
     this.saveAsToolStripMenuItem.Text = "Save";
     //
     // saveAsToolStripMenuItem1
     //
     this.saveAsToolStripMenuItem1.Name = "saveAsToolStripMenuItem1";
     this.saveAsToolStripMenuItem1.Size = new System.Drawing.Size(177, 22);
     this.saveAsToolStripMenuItem1.Text = "Save As...";
     //
     // SwatchesForm
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
     this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize          = new System.Drawing.Size(221, 173);
     this.ContextMenuStrip    = this.contextMenuStrip1;
     this.Controls.Add(this.panel1);
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
     this.Name            = "SwatchesForm";
     this.Text            = "Color Swatches";
     this.Resize         += new System.EventHandler(this.SwatchesForm_Resize);
     this.panel1.ResumeLayout(false);
     this.contextMenuStrip1.ResumeLayout(false);
     this.ResumeLayout(false);
 }
Esempio n. 8
0
 public override void Save(string filename, Endogine.ColorEx.Palette palette)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Esempio n. 9
0
        public override Endogine.ColorEx.Palette Load(string filename)
        {
            Serialization.BinaryReverseReader reader = new BinaryReverseReader(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            //Serialization.BinaryReaderEx reader = new BinaryReaderEx(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            ushort version   = reader.ReadUInt16();
            ushort numColors = reader.ReadUInt16();

            if (version > 2)
            {
                throw new Exception("Can't parse .ACO palettes with version > 2: " + filename);
            }

            Endogine.ColorEx.Palette palette = new Endogine.ColorEx.Palette();
            for (int colorNum = 0; colorNum < numColors; colorNum++)
            {
                ushort colorSpaceId = reader.ReadUInt16();

                ushort[] vals = new ushort[4];
                for (int i = 0; i < 4; i++)
                {
                    vals[i] = reader.ReadUInt16();
                }

                string name = colorNum.ToString();
                if (version == 2)
                {
                    reader.ReadUInt16(); //padded
                    int nameLength = reader.ReadUInt16();

                    if (reader.BaseStream.Position % 2 == 1) // ?
                    {
                        reader.ReadUInt16();                 //padded
                    }
                    for (int letterNum = 0; letterNum < nameLength; letterNum++)
                    {
                        char c = (char)reader.ReadUInt16();
                        name += c.ToString();
                    }
                }

                ColorEx.ColorBase color;
                //TODO; uses 16 bits per channel, but here I truncate it to 8 bits
                switch (colorSpaceId)
                {
                case 0:     //RGB
                    ColorEx.ColorRgb rgb = new Endogine.ColorEx.ColorRgb();
                    rgb.R = vals[0] / 256;
                    rgb.G = vals[1] / 256;
                    rgb.B = vals[2] / 256;
                    color = rgb;
                    break;

                case 1:     //HSB
                    ColorEx.ColorHsb hsb = new Endogine.ColorEx.ColorHsb();
                    hsb.H = (float)vals[0] / 182.04f;
                    hsb.S = (float)vals[1] / 655.35f / 100f;
                    hsb.B = (float)vals[2] / 655.35f / 100f;
                    color = hsb;
                    break;

                case 2:     //CMYK
                    ColorEx.ColorCmyk cmyk = new Endogine.ColorEx.ColorCmyk();
                    cmyk.C = (float)vals[0] / 256;
                    cmyk.M = (float)vals[1] / 256;
                    cmyk.Y = (float)vals[2] / 256;
                    cmyk.K = (float)vals[3] / 256;
                    color  = cmyk;
                    break;

                case 7:     //Lab
                    float[] ab = new float[2];
                    for (int i = 1; i < 3; i++)
                    {
                        if (vals[i] <= 12000)
                        {
                            ab[i - 1] = (float)vals[i] / 100;
                        }
                        else
                        {
                            ab[i - 1] = (float)(65536 - vals[i]) / 100;
                        }
                    }
                    ColorEx.ColorLab lab = new Endogine.ColorEx.ColorLab();
                    lab.L = (float)vals[0] / 100;
                    lab.a = vals[1];
                    lab.b = vals[2];
                    //Angle:2, Observer:D65
                    color = lab;
                    break;

                case 8:     //Grayscale
                    ColorEx.ColorRgb rgbGray = new Endogine.ColorEx.ColorRgb();
                    int gray = (int)((float)vals[0] / 39.0625f);
                    rgbGray.R = gray;
                    rgbGray.G = gray;
                    rgbGray.B = gray;
                    color     = rgbGray;
                    break;

                case 9:     //Wide CMYK
                default:
                    throw new Exception("Can't read colorspace " + colorSpaceId + " in " + filename);
                }
                palette.Add(name, color);
            }
            return(palette);
        }
Esempio n. 10
0
        public override Endogine.ColorEx.Palette Load(string filename)
        {
            Serialization.BinaryReverseReader reader = new BinaryReverseReader(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            //Serialization.BinaryReaderEx reader = new BinaryReaderEx(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            ushort version = reader.ReadUInt16();
            ushort numColors = reader.ReadUInt16();

            if (version > 2)
            {
                throw new Exception("Can't parse .ACO palettes with version > 2: "+filename);
            }

            Endogine.ColorEx.Palette palette = new Endogine.ColorEx.Palette();
            for (int colorNum = 0; colorNum < numColors; colorNum++)
            {
                ushort colorSpaceId = reader.ReadUInt16();

                ushort[] vals = new ushort[4];
                for (int i = 0; i < 4; i++)
                    vals[i] = reader.ReadUInt16();

                string name = colorNum.ToString();
                if (version == 2)
                {
                    reader.ReadUInt16(); //padded
                    int nameLength = reader.ReadUInt16();

                    if (reader.BaseStream.Position % 2 == 1) // ?
                        reader.ReadUInt16(); //padded

                    for (int letterNum = 0; letterNum < nameLength; letterNum++)
                    {
                        char c = (char)reader.ReadUInt16();
                        name+=c.ToString();
                    }
                }

                ColorEx.ColorBase color;
                //TODO; uses 16 bits per channel, but here I truncate it to 8 bits
                switch (colorSpaceId)
                {
                    case 0: //RGB
                        ColorEx.ColorRgb rgb = new Endogine.ColorEx.ColorRgb();
                        rgb.R = vals[0] / 256;
                        rgb.G = vals[1] / 256;
                        rgb.B = vals[2] / 256;
                        color = rgb;
                        break;
                    case 1: //HSB
                        ColorEx.ColorHsb hsb = new Endogine.ColorEx.ColorHsb();
                        hsb.H = (float)vals[0] / 182.04f;
                        hsb.S = (float)vals[1] / 655.35f / 100f;
                        hsb.B = (float)vals[2] / 655.35f / 100f;
                        color = hsb;
                        break;
                    case 2: //CMYK
                        ColorEx.ColorCmyk cmyk = new Endogine.ColorEx.ColorCmyk();
                        cmyk.C = (float)vals[0] / 256;
                        cmyk.M = (float)vals[1] / 256;
                        cmyk.Y = (float)vals[2] / 256;
                        cmyk.K = (float)vals[3] / 256;
                        color = cmyk;
                        break;
                    case 7: //Lab
                        float[] ab = new float[2];
                        for (int i = 1; i < 3; i++)
                        {
                            if (vals[i] <= 12000) ab[i - 1] = (float)vals[i] / 100;
                            else ab[i - 1] = (float)(65536 - vals[i]) / 100;
                        }
                        ColorEx.ColorLab lab = new Endogine.ColorEx.ColorLab();
                        lab.L = (float)vals[0]/100;
                        lab.a = vals[1];
                        lab.b = vals[2];
                        //Angle:2, Observer:D65
                        color = lab;
                        break;
                    case 8: //Grayscale
                        ColorEx.ColorRgb rgbGray = new Endogine.ColorEx.ColorRgb();
                        int gray = (int)((float)vals[0] / 39.0625f);
                        rgbGray.R = gray;
                        rgbGray.G = gray;
                        rgbGray.B = gray;
                        color = rgbGray;
                        break;
                    case 9: //Wide CMYK
                    default:
                        throw new Exception("Can't read colorspace "+colorSpaceId+" in "+filename);
                }
                palette.Add(name, color);
            }
            return palette;
        }