Beispiel #1
0
        /// <summary>
        /// Creates a new colour with properties identical to the old one.
        /// </summary>
        /// <remarks>
        /// This is intended for changing the properties of a colour, while
        /// preserving the old version's properties, due to changing the
        /// reference.
        /// </remarks>
        /// <returns>The new colour.</returns>
        public PaletteColor Clone()
        {
            var pc = new PaletteColor();

            pc.Name     = Name;
            pc.Color    = Color;
            pc.Metadata = Metadata;
            return(pc);
        }
Beispiel #2
0
        static void ToPhotoshopColorV2(BinaryWriter bw, PaletteColor pc)
        {
            // write the V1 color, then the string
            ToPhotoshopColorV1(bw, pc);

            var strWithNull = pc.Name + '\0';

            // length, and then string
            bw.WriteUInt32BE(Convert.ToUInt32(strWithNull.Length));
            bw.WriteStringBE(strWithNull);
        }
Beispiel #3
0
        // TODO: Write based on colorspace
        static void ToPhotoshopColorV1(BinaryWriter bw, PaletteColor pc)
        {
            // 10 bytes: 1 ushort for type, 4 ushorts for channels

            if (pc.Color is LabColor)
            {
                var lab = (LabColor)pc.Color;
                bw.WriteUInt16BE((ushort)AdobeColorSpace.Lab);
                bw.WriteUInt16BE(Convert.ToUInt16(lab.L * 100));
                bw.WriteInt16BE(Convert.ToInt16(lab.A * 100));
                bw.WriteInt16BE(Convert.ToInt16(lab.B * 100));
                bw.WriteUInt16BE(0); //nop 4th
            }
            if (pc.Color is CmykColor)
            {
                var cmyk = (CmykColor)pc.Color;
                bw.WriteUInt16BE((ushort)AdobeColorSpace.Lab);
                bw.WriteUInt16BE(Convert.ToUInt16(cmyk.Cyan * ushort.MaxValue));
                bw.WriteUInt16BE(Convert.ToUInt16(cmyk.Magenta * ushort.MaxValue));
                bw.WriteUInt16BE(Convert.ToUInt16(cmyk.Yellow * ushort.MaxValue));
                bw.WriteUInt16BE(Convert.ToUInt16(cmyk.Key * ushort.MaxValue));
            }
            // HSV looks to be a cluster of magic values, see the HACK above
            else
            {
                // we can fall back to RGB easily, especially if it's already
                var rgb = pc.Color.ToRgb();
                // type
                bw.WriteUInt16BE((ushort)AdobeColorSpace.Rgb);
                // red channel
                bw.WriteUInt16BE(rgb.R);
                // green channel
                bw.WriteUInt16BE(rgb.G);
                // blue channel
                bw.WriteUInt16BE(rgb.B);
                // no need for fourth channel, so write 0
                bw.WriteUInt16BE(0);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new color palette from a GIMP palette file.
        /// </summary>
        /// <param name="file">The file itself, as lines.</param>
        public GimpPalette(string[] file)
        {
            if (file[0] != magic)
            {
                throw new PaletteException("Palette is not in a valid format.");
            }

            Colors   = new List <PaletteColor>();
            Comments = new List <string>();

            foreach (string l in file)
            {
                if (l == magic)
                {
                    continue;
                }
                if (Regex.IsMatch(l, commentRegex))
                {
                    // empty matches (like just a #) will give a string.Empty
                    Comments.Add(Regex.Match(l, commentRegex).Groups[1].Value);
                }
                else if (Regex.IsMatch(l, columnsRegex))
                {
                    int i = 0; // a default
                    int.TryParse(Regex.Match(l,
                                             columnsRegex).Groups[1].Value, out i);
                    BucketSize = i;
                }
                else if (Regex.IsMatch(l, nameRegex))
                {
                    Name = Regex.Match(l, nameRegex).Groups[1].Value;
                }
                else if (PaletteColor.IsPaletteColorString(l))
                {
                    // i guess we'll try to coax some colours out of it
                    Colors.Add(new PaletteColor(l));
                }
            }
        }
 public ColorDragEventArgs(PaletteColor dragged, PaletteColor target)
 {
     DraggedColor = dragged;
     TargetColor  = target;
 }
 public ColorChangeTextForm(string title, string text, PaletteColor pc) : this()
 {
     Text = title;
     valueBox.Text = text;
     Icon = RenderColorIcon.RenderIcon(pc.Color.ToRgb());
 }
 public ColorGridChangeEventArgs(PaletteColor old, RgbColor @new)
 {
     Color    = old;
     NewColor = @new;
 }