Beispiel #1
0
 public NumericAxisView()
 {
     ForeColor           = Color2.Black;
     IndicatorColor      = Color2.FromArgb(30, 251, 173, 73);
     IsLogarithmic       = false;
     Reverse             = false;
     TotalMax            = double.NaN;
     TotalMin            = double.NaN;
     ZeroPoint           = double.NaN;
     ZoomMax             = double.NaN;
     ZoomMin             = double.NaN;
     MaxNumIntegerDigits = 4;
     LineWidth           = 1F;
     ZoomType            = AxisZoomType.None;
     MinorTickLineWidth  = 1;
     MajorTickLineWidth  = 1;
     MinorTickLength     = 3;
     MajorTickLength     = 6;
     IsLogarithmic       = false;
     ZoomMax             = double.NaN;
     ZoomMin             = double.NaN;
     TotalMax            = double.NaN;
     TotalMin            = double.NaN;
     MouseMode           = AxisMouseMode.Zoom;
 }
 public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header)
 {
     byte[] newScanline = GrayscaleReader.ToArrayByBitsLength(scanline,header.BitDepth);
     int offset, index;
     if (paletteAlpha != null && paletteAlpha.Length > 0){
         for (int i = 0; i < header.Width; i++){
             index = newScanline[i];
             offset = (row*header.Width) + i;
             int pixelOffset = index*3;
             byte r = palette[pixelOffset];
             byte g = palette[pixelOffset + 1];
             byte b = palette[pixelOffset + 2];
             byte a = paletteAlpha.Length > index ? paletteAlpha[index] : (byte) 255;
             Color2 color = Color2.FromArgb(a,r, g, b);
             pixels[offset] = color;
         }
     } else{
         for (int i = 0; i < header.Width; i++){
             index = newScanline[i];
             offset = (row*header.Width) + i;
             int pixelOffset = index*3;
             byte r = palette[pixelOffset];
             byte g = palette[pixelOffset + 1];
             byte b = palette[pixelOffset + 2];
             Color2 color = Color2.FromArgb(r, g, b);
             pixels[offset] = color;
         }
     }
     row++;
 }
        public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header)
        {
            int offset;

            byte[] newScanline = GrayscaleReader.ToArrayByBitsLength(scanline, header.BitDepth);
            if (useAlpha)
            {
                for (int x = 0; x < newScanline.Length; x += 4)
                {
                    offset = row * header.Width + (x >> 2);
                    byte   r     = newScanline[x];
                    byte   g     = newScanline[x + 1];
                    byte   b     = newScanline[x + 2];
                    byte   a     = newScanline[x + 3];
                    Color2 color = Color2.FromArgb(a, r, g, b);
                    pixels[offset] = color;
                }
            }
            else
            {
                for (int x = 0; x < newScanline.Length / 3; x++)
                {
                    offset = (row * header.Width) + x;
                    int    pixelOffset = x * 3;
                    byte   r           = newScanline[pixelOffset];
                    byte   g           = newScanline[pixelOffset + 1];
                    byte   b           = newScanline[pixelOffset + 2];
                    Color2 color       = Color2.FromArgb(r, g, b);
                    pixels[offset] = color;
                }
            }
            row++;
        }
Beispiel #4
0
 public SymbolProperties(Color2 color, int size, int type, bool showLabel)
 {
     Color     = color;
     Size      = size;
     Type      = type;
     ShowLabel = showLabel;
 }
Beispiel #5
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType.IsAssignableFrom(typeof(ISolidColorBrush)))
            {
                if (value is Color c)
                {
                    return(new SolidColorBrush(c));
                }

                if (value is Color2 c2)
                {
                    return(new SolidColorBrush(c2));
                }

                if (value is string c3 && Color.TryParse(c3, out var cc))
                {
                    return(new SolidColorBrush(cc));
                }
            }
            else
            {
                if (value is string c3 && Color2.TryParse(c3, out var cc))
                {
                    return(cc);
                }
            }
            return(value);
        }
Beispiel #6
0
Datei: Rgb.cs Projekt: 0-v-0/test
 public Info ConvertFromRgb(Color2 color)
 {
     return(new Info()
     {
         a = color.r - 128, b = color.g - 128, c = color.b - 128
     });
 }
Beispiel #7
0
 public static Tweener DOColor(this LineRenderer target, Color2 startValue, Color2 endValue, float duration)
 {
     return(DOTween.To(() => startValue, delegate(Color2 x)
     {
         target.SetColors(x.ca, x.cb);
     }, endValue, duration).SetTarget(target));
 }
Beispiel #8
0
        public override string ToString()
        {
            string summary = Color1.ToString().Substring(0, 1) + Color2.ToString().Substring(0, 1) + Color3.ToString().Substring(0, 1);

            summary = summary.Replace("N", "") + "+";
            if (Stats.Agility > 0)
            {
                summary += Stats.Agility.ToString() + "Agi";
            }
            if (Stats.Stamina > 0)
            {
                summary += Stats.Stamina.ToString() + "Sta";
            }
            if (Stats.DodgeRating > 0)
            {
                summary += Stats.DodgeRating.ToString() + "Dodge";
            }
            if (Stats.DefenseRating > 0)
            {
                summary += Stats.DefenseRating.ToString() + "Def";
            }
            if (Stats.Resilience > 0)
            {
                summary += Stats.Resilience.ToString() + "Res";
            }
            if (summary.EndsWith("+"))
            {
                summary = summary.Substring(0, summary.Length - 1);
            }
            return(summary);
        }
Beispiel #9
0
        public override string ToString()
        {
            string text = "物品ID:" + ItemClass + "\n物品名:" + ItemName
                          + "\n背包:" + Collection + ",格子:" + Slot
                          + "\n类型:" + MainCategory + " [" + SubCategory + "]";

            text += "\n最大堆叠数量:" + (MaxStack < 0?"不限":"" + MaxStack);

            if (Color1 != 0)
            {
                text += "\n颜色:" + (Color1 == 0 ? "无" : "#" + Color1.ToString("X"))
                        + "," + (Color2 == 0 ? "无" : "#" + Color2.ToString("X"))
                        + "," + (Color3 == 0 ? "无" : "#" + Color3.ToString("X"));
            }
            text += "\n职业限制:" + ClassInfoEx.GetClassText(this.RequiredClass);
            if (Stat != null)
            {
                text += Stat.ToString();
            }
            if (Attributes != null)
            {
                foreach (ItemAttribute attr in Attributes)
                {
                    text += "\n" + attr.ToString();
                }
            }
            text += "\n物品描述:" + ItemDesc;
            if (Time != "无限期")
            {
                text += "\n到期时间:" + Time;
            }
            return(text);
        }
Beispiel #10
0
        private void ReadRgb16(Color2[] imageData, int width, int height, bool inverted)
        {
            // We divide here as we will store the colors in our floating point format.
            const int scaleR = 8;             // 256/32
            const int scaleG = 4;             // 256/64
            int       alignment;

            byte[] data = GetImageArray(width, height, 2, out alignment);
            Parallel.For(0, height, Bootstrapper.instance.ParallelOptions, y => {
                int rowOffset = y * ((width * 2) + alignment);

                // Revert the y value, because bitmaps are saved from down to top
                int row = Invert(y, height, inverted);
                for (int x = 0; x < width; x++)
                {
                    int offset      = rowOffset + (x * 2);
                    short temp      = BitConverter.ToInt16(data, offset);
                    byte r          = (byte)(((temp & rgb16RMask) >> 11) * scaleR);
                    byte g          = (byte)(((temp & rgb16GMask) >> 5) * scaleG);
                    byte b          = (byte)((temp & rgb16BMask) * scaleR);
                    int arrayOffset = row * width + x;

                    // Stored in b-> g-> r order.
                    Color2 packed          = Color2.FromArgb(r, g, b);
                    imageData[arrayOffset] = packed;
                }
            });
        }
Beispiel #11
0
 // Lerp
 public void Lerp(ref SpriteColors from, ref SpriteColors to, float f01)
 {
     Color0.Lerp(from.Color0, to.Color0, f01);
     Color1.Lerp(from.Color1, to.Color1, f01);
     Color2.Lerp(from.Color2, to.Color2, f01);
     Color3.Lerp(from.Color3, to.Color3, f01);
 }
Beispiel #12
0
        public bool Equals(CarGenerator other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Model.Equals(other.Model) &&
                   Position.Equals(other.Position) &&
                   Heading.Equals(other.Heading) &&
                   Color1.Equals(other.Color1) &&
                   Color2.Equals(other.Color2) &&
                   ForceSpawn.Equals(other.ForceSpawn) &&
                   AlarmChance.Equals(other.AlarmChance) &&
                   LockedChance.Equals(other.LockedChance) &&
                   MinDelay.Equals(other.MinDelay) &&
                   MaxDelay.Equals(other.MaxDelay) &&
                   Timer.Equals(other.Timer) &&
                   Handle.Equals(other.Handle) &&
                   Enabled.Equals(other.Enabled) &&
                   IsBlocking.Equals(other.IsBlocking) &&
                   CollisionBoundingMin.Equals(other.CollisionBoundingMin) &&
                   CollisionBoundingMax.Equals(other.CollisionBoundingMax) &&
                   CollisionSize.Equals(other.CollisionSize));
        }
        public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header)
        {
            int offset;

            byte[] newScanline = ToArrayByBitsLength(scanline, header.BitDepth);
            if (useAlpha)
            {
                for (int x = 0; x < header.Width / 2; x++)
                {
                    offset = row * header.Width + x;
                    byte   rgb   = newScanline[x * 2];
                    byte   a     = newScanline[(x * 2) + 1];
                    Color2 color = Color2.FromArgb(a, rgb, rgb, rgb);
                    pixels[offset] = color;
                }
            }
            else
            {
                for (int x = 0; x < header.Width; x++)
                {
                    offset = row * header.Width + x;
                    byte   rgb   = newScanline[x];
                    Color2 color = Color2.FromArgb(rgb, rgb, rgb);
                    pixels[offset] = color;
                }
            }
            row++;
        }
Beispiel #14
0
        public override string ToString()
        {
            string text = ItemClass + "\n" + Name
                          + "\n" + R.Package + ":" + Collection + "(" + Slot + ")"
                          + "\n" + R.Category + ":" + MainCategory + "," + SubCategory + "";

            text += "\n" + R.MaxStackCount + ":" + (MaxStack < 0? R.UnLimit :"" + MaxStack);
            if (Color1 != 0)
            {
                text += "\n" + R.Color + ":" + "#" + Color1.ToString("X")
                        + "," + (Color2 == 0 ? "-" : "#" + Color2.ToString("X"))
                        + "," + (Color3 == 0 ? "-" : "#" + Color3.ToString("X"));
            }
            text += "\n" + R.ClassRestriction + ":" + ClassInfoEx.GetClassText(this.RequiredClass);
            if (Stat != null)
            {
                text += Stat.ToString();
            }
            if (Attributes != null)
            {
                foreach (ItemAttribute attr in Attributes)
                {
                    text += "\n" + attr.ToString();
                }
            }
            text += "\n" + Desc;
            if (Time != "-")
            {
                text += "\n" + R.TimeDate + ":" + Time;
            }
            return(text);
        }
 public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header)
 {
     int offset;
     byte[] newScanline = GrayscaleReader.ToArrayByBitsLength(scanline,header.BitDepth);
     if (useAlpha){
         for (int x = 0; x < newScanline.Length; x += 4){
             offset = row*header.Width + (x >> 2);
             byte r = newScanline[x];
             byte g = newScanline[x + 1];
             byte b = newScanline[x + 2];
             byte a = newScanline[x + 3];
             Color2 color = Color2.FromArgb(a,r, g, b);
             pixels[offset] = color;
         }
     } else{
         for (int x = 0; x < newScanline.Length/3; x++){
             offset = (row*header.Width) + x;
             int pixelOffset = x*3;
             byte r = newScanline[pixelOffset];
             byte g = newScanline[pixelOffset + 1];
             byte b = newScanline[pixelOffset + 2];
             Color2 color = Color2.FromArgb(r, g, b);
             pixels[offset] = color;
         }
     }
     row++;
 }
        /// <summary>
        /// Synchronizes the properties.
        /// </summary>
        /// <param name="series">The series.</param>
        protected override void SynchronizeProperties(OxyPlot.Series.Series series)
        {
            base.SynchronizeProperties(series);
            var s = (OxyPlot.Series.TwoColorLineSeries)series;

            s.Limit  = Limit;
            s.Color2 = Color2.ToOxyColor();
        }
Beispiel #17
0
 public void Increment(Color2 pixel)
 {
     pixelCount++;
     byte[] components = pixel.ToBytes();
     red   += components[0];
     green += components[1];
     blue  += components[2];
 }
 protected override byte QuantizePixel(Color2 pixel)
 {
     byte paletteIndex = (byte) colors;
     if (pixel.ToBytes()[3] > Threshold){
         paletteIndex = (byte) octree.GetPaletteIndex(pixel);
     }
     return paletteIndex;
 }
Beispiel #19
0
 public string GetColor(Color2 color)
 {
     //if (color.IsNamedColor)
     //{
     //    return color.Name;
     //}
     return($"rgb({color.R},{color.G},{color.B})");
 }
Beispiel #20
0
 public void Write(AssetWriter writer)
 {
     Color0.Write(writer);
     Color1.Write(writer);
     Color2.Write(writer);
     Color3.Write(writer);
     Color4.Write(writer);
 }
Beispiel #21
0
 public void Read(AssetReader reader)
 {
     Color0.Read(reader);
     Color1.Read(reader);
     Color2.Read(reader);
     Color3.Read(reader);
     Color4.Read(reader);
 }
        internal static void DoPaint(IGraphics g, DataGridView grid)
        {
            Pen2          p            = new Pen2(GraphUtils.ToColor2(grid.GridColor));
            float         x            = grid.Location.X;
            float         y            = grid.Location.Y;
            Brush2        text         = new Brush2(GraphUtils.ToColor2(grid.ColumnHeadersDefaultCellStyle.ForeColor));
            Font2         headerFont   = GraphUtils.ToFont2(grid.ColumnHeadersDefaultCellStyle.Font);
            StringFormat2 headerformat = new StringFormat2 {
                Alignment     = StringAlignment2.Near,
                LineAlignment = StringAlignment2.Center
            };

            for (int c = 0; c < grid.Columns.Count; c++)
            {
                Brush2 header = new Brush2(GraphUtils.ToColor2(grid.Columns[c].HeaderCell.Style.BackColor));
                if (header.Color.IsEmpty || header.Color == Color2.Transparent || header.Color == Color2.Black ||
                    header.Color.Name == "0")
                {
                    header.Color = GraphUtils.ToColor2(grid.ColumnHeadersDefaultCellStyle.BackColor);
                }
                g.FillRectangle(header, x, y, grid.Columns[c].Width, grid.ColumnHeadersHeight);
                g.DrawRectangle(p, x, y, grid.Columns[c].Width, grid.ColumnHeadersHeight);
                g.DrawString(grid.Columns[c].HeaderText, headerFont, text,
                             new Rectangle2(x, y, grid.Columns[c].Width, grid.ColumnHeadersHeight), headerformat);
                x += grid.Columns[c].Width;
            }
            y += grid.ColumnHeadersHeight;
            for (int r = 0; r < grid.Rows.Count; r++)
            {
                x = grid.Location.X;
                for (int c = 0; c < grid.Columns.Count; c++)
                {
                    Color2 backcolor = GetBackColor(grid, r, c);
                    Color2 forecolor = GetForeColor(grid, r, c);
                    if (!backcolor.IsEmpty)
                    {
                        g.FillRectangle(new Brush2(backcolor), x, y, grid.Columns[c].Width, grid.Rows[r].Height);
                    }
                    g.DrawRectangle(p, x, y, grid.Columns[c].Width, grid.Rows[r].Height);
                    object value = grid.Rows[r].Cells[c].Value;
                    if (value != null)
                    {
                        Font2         font       = GraphUtils.ToFont2(grid.DefaultCellStyle.Font);
                        StringFormat2 cellformat = GetStringFormat(grid.Columns[c].DefaultCellStyle.Alignment);
                        string        t          = value.ToString();
                        if (!string.IsNullOrEmpty(grid.Columns[c].DefaultCellStyle.Format))
                        {
                            string format = "{0:" + grid.Columns[c].DefaultCellStyle.Format.ToLower() + "}";
                            t = string.Format(format, value);
                        }
                        g.DrawString(t, font, new Brush2(forecolor), new Rectangle2(x, y, grid.Columns[c].Width, grid.Rows[r].Height),
                                     cellformat);
                    }
                    x += grid.Columns[c].Width;
                }
                y += grid.Rows[r].Height;
            }
        }
 public void Read(BinaryReader reader, byte[] version)
 {
     Color1.Read(reader);
     Color2.Read(reader);
     if (version[0] >= 0 && version[1] >= 1 && version[2] >= 8)
     {
         doRgbGradient = reader.ReadBoolean();
     }
 }
Beispiel #24
0
        internal void SetPixel(int x, int y, Color2 color)
        {
            var data = (PixelData *)(pBase + y * stride + x * sizeof(PixelData));

            data->alpha = color.a;
            data->red   = color.r;
            data->green = color.g;
            data->blue  = color.b;
        }
Beispiel #25
0
        /// <summary>
        /// Converts from their colorspace to RGB and combines all previously decoded channels
        /// </summary>
        /// <param name="imgInfo"></param>
        /// <param name="imgS"></param>
        /// <returns>A 2D array representing the color data from the image</returns>
        internal static Color2[,] MergeChannels(ImgInfo imgInfo, float[][,] imgS)
        {
            var img = new Color2[imgInfo.height, imgInfo.width];
            IColorspaceConverter converter;

            if (imgInfo.app14MarkerFound)
            {
                switch (imgInfo.colorMode)
                {
                case Markers.App14ColorMode.Unknown:
                    converter = imgInfo.numOfComponents == 3 ? new Rgb() : (IColorspaceConverter) new YCbCr();
                    break;

                case Markers.App14ColorMode.YCbCr:
                    converter = new YCbCr();
                    break;

                case Markers.App14ColorMode.YCCK:
                    converter = new YCbCr();
                    break;

                default:
                    converter = new Rgb();
                    break;
                }
            }
            else
            {
                converter = new YCbCr();
            }

            for (int y = 0; y < imgInfo.height; y++)
            {
                for (int x = 0; x < imgInfo.width; x++)
                {
                    Info info;

                    if (imgInfo.numOfComponents == 1)                     // Y
                    {
                        info.a = imgS[0][y, x];
                        info.b = 0;
                        info.c = 0;
                    }
                    else                     // YCbCr
                    {
                        info.a = imgS[0][y, x];
                        info.b = imgS[1][y, x];
                        info.c = imgS[2][y, x];
                    }

                    img[y, x] = converter.ConvertToRgb(info);
                }
            }

            return(img);
        }
Beispiel #26
0
 protected virtual void SecondPass(IPixelAccessor source, byte[] output, int width, int height)
 {
     Parallel.For(0, source.Height, Bootstrapper.instance.ParallelOptions, y => {
         for (int x = 0; x < source.Width; x++)
         {
             Color2 sourcePixel           = source[x, y];
             output[y * source.Width + x] = QuantizePixel(sourcePixel);
         }
     });
 }
Beispiel #27
0
        protected override byte QuantizePixel(Color2 pixel)
        {
            byte paletteIndex = (byte)colors;

            if (pixel.ToBytes()[3] > Threshold)
            {
                paletteIndex = (byte)octree.GetPaletteIndex(pixel);
            }
            return(paletteIndex);
        }
        public override void OnPaintBackground(IGraphics g, int width, int height)
        {
            Brush2 b = new Brush2(Color2.FromArgb(236, 233, 216));

            g.FillRectangle(b, 0, 0, width, height);
            Pen2 p = new Pen2(Color2.FromArgb(172, 168, 153));

            g.DrawLine(p, 0, height - 1, width, height - 1);
            g.DrawLine(p, width - 1, 0, width - 1, height);
        }
Beispiel #29
0
    public void Shoot(Color color1, Color color2, Vector3 from, Vector3 to)
    {
        laserLine.enabled = true;
        laserLine.SetPosition(0, from);
        laserLine.SetPosition(1, to);

        Color2 startColor = new Color2(color1, color2);

        laserLine.DOColor(startColor, new Color2(), 1);
    }
Beispiel #30
0
 protected ImageBase(int width, int height)
 {
     if (width <= 0 || height <= 0)
     {
         throw new ArgumentOutOfRangeException();
     }
     Width  = width;
     Height = height;
     Pixels = new Color2[width * height];
 }
        protected override void OnExecute()
        {
            var startColour = new Color2(StartColour.value, StartColour.value);
            var endColour   = new Color2(EndColour.value, EndColour.value);
            var tweener     = agent.DOColor(startColour, endColour, Duration.value);

            tweener.Pause();

            CreatedTween.value = tweener;
            EndAction(true);
        }
Beispiel #32
0
        public override void Execute()
        {
            var startColour  = new Color2(StartColour, StartColour);
            var endColour    = new Color2(EndColour, EndColour);
            var lineRenderer = EntityView.GetComponent <UnityEngine.LineRenderer>();
            var tweener      = lineRenderer.DOColor(startColour, endColour, Duration);

            tweener.Pause();

            CreatedTween = tweener;
        }
Beispiel #33
0
        public YAMLNode ExportYAML(IExportContainer container)
        {
            YAMLMappingNode node = new YAMLMappingNode();

            node.Add(Color0Name, Color0.ExportYAML(container));
            node.Add(Color1Name, Color1.ExportYAML(container));
            node.Add(Color2Name, Color2.ExportYAML(container));
            node.Add(Color3Name, Color3.ExportYAML(container));
            node.Add(Color4Name, Color4.ExportYAML(container));
            return(node);
        }
 public Image2 ToImage()
 {
     Image2 image = new Image2();
     int pixelCount = Pixels.Length;
     int palletCount = Palette.Length - 1;
     Color2[] pixels = new Color2[pixelCount];
     Parallel.For(0, pixelCount, Bootstrapper.instance.ParallelOptions, i =>{
         Color2 color = Palette[Math.Min(palletCount, Pixels[i])];
         pixels[i] = color;
     });
     image.SetPixels(Width, Height, pixels);
     return image;
 }
 public PaletteQuantizer(Color2[] palette = null)
     : base(true)
 {
     if (palette == null){
         Color2[] constants = Color2.WebSafeColors;
         List<Color2> safe = new List<Color2> {default(Color2) };
         foreach (Color2 c in constants){
             Color2 packed = Color2.FromVector4(c.ToVector4());
             safe.Add(packed);
         }
         colors = safe.ToArray();
     } else{
         colors = palette;
     }
 }
 public QuantizedImage(int width, int height, Color2[] palette, byte[] pixels, int transparentIndex = -1)
 {
     if (width <= 0 || height <= 0){
         throw new ArgumentOutOfRangeException();
     }
     if (palette == null || pixels == null){
         throw new ArgumentNullException();
     }
     if (pixels.Length != width*height){
         throw new ArgumentException($"Pixel array size must be {nameof(width)} * {nameof(height)}", nameof(pixels));
     }
     Width = width;
     Height = height;
     Palette = palette;
     Pixels = pixels;
     TransparentIndex = transparentIndex;
 }
 protected override byte QuantizePixel(Color2 pixel)
 {
     byte colorIndex = 0;
     string colorHash = pixel.ToString();
     if (colorMap.ContainsKey(colorHash)){
         colorIndex = colorMap[colorHash];
     } else{
         byte[] bytes = pixel.ToBytes();
         if (!(bytes[3] > Threshold)){
             for (int index = 0; index < colors.Length; index++){
                 if (colors[index].ToBytes()[3] == 0){
                     colorIndex = (byte) index;
                     TransparentIndex = colorIndex;
                     break;
                 }
             }
         } else{
             int leastDistance = int.MaxValue;
             int red = bytes[0];
             int green = bytes[1];
             int blue = bytes[2];
             for (int index = 0; index < colors.Length; index++){
                 byte[] paletteColor = colors[index].ToBytes();
                 int redDistance = paletteColor[0] - red;
                 int greenDistance = paletteColor[1] - green;
                 int blueDistance = paletteColor[2] - blue;
                 int distance = (redDistance*redDistance) + (greenDistance*greenDistance) + (blueDistance*blueDistance);
                 if (distance < leastDistance){
                     colorIndex = (byte) index;
                     leastDistance = distance;
                     if (distance == 0){
                         break;
                     }
                 }
             }
         }
         colorMap.TryAdd(colorHash, colorIndex);
     }
     return colorIndex;
 }
 public void ReadScanline(byte[] scanline, Color2[] pixels, PngHeader header)
 {
     int offset;
     byte[] newScanline = ToArrayByBitsLength(scanline, header.BitDepth);
     if (useAlpha){
         for (int x = 0; x < header.Width/2; x++){
             offset = row*header.Width + x;
             byte rgb = newScanline[x*2];
             byte a = newScanline[(x*2) + 1];
             Color2 color = Color2.FromArgb(a, rgb, rgb, rgb);
             pixels[offset] = color;
         }
     } else{
         for (int x = 0; x < header.Width; x++){
             offset = row*header.Width + x;
             byte rgb = newScanline[x];
             Color2 color = Color2.FromArgb(rgb, rgb, rgb);
             pixels[offset] = color;
         }
     }
     row++;
 }
 public void AddColor(Color2 pixel)
 {
     int packed = pixel.GetPackedValue();
     if (previousColor.Equals(packed)){
         if (previousNode == null){
             previousColor = packed;
             root.AddColor(pixel, maxColorBits, 0, this);
         } else{
             previousNode.Increment(pixel);
         }
     } else{
         previousColor = packed;
         root.AddColor(pixel, maxColorBits, 0, this);
     }
 }
 private void ConvertFromYCbCr(int imageWidth, int imageHeight, ImageBase image)
 {
     int scale = comp[0].h/comp[1].h;
     Color2[] pixels = new Color2[imageWidth*imageHeight];
     Parallel.For(0, imageHeight, Bootstrapper.instance.ParallelOptions, y =>{
         int yo = ycbcrImage.get_row_y_offset(y);
         int co = ycbcrImage.get_row_c_offset(y);
         for (int x = 0; x < imageWidth; x++){
             byte yy = ycbcrImage.pix_y[yo + x];
             byte cb = ycbcrImage.pix_cb[co + (x/scale)];
             byte cr = ycbcrImage.pix_cr[co + (x/scale)];
             int index = y*imageWidth + x;
             Color2 color = new YCbCr2(yy, cb, cr);
             Color2 packed = Color2.FromArgb(color.A, color.R, color.G, color.B);
             pixels[index] = packed;
         }
     });
     image.SetPixels(imageWidth, imageHeight, pixels);
     AssignResolution(image);
 }
 private void ConvertFromGrayScale(int imageWidth, int imageHeight, ImageBase image)
 {
     Color2[] pixels = new Color2[imageWidth*imageHeight];
     Parallel.For(0, imageHeight, Bootstrapper.instance.ParallelOptions, y =>{
         int yoff = grayImage.GetRowOffset(y);
         for (int x = 0; x < imageWidth; x++){
             int offset = (y*imageWidth) + x;
             byte rgb = grayImage.pixels[yoff + x];
             Color2 packed = Color2.FromArgb(rgb, rgb, rgb);
             pixels[offset] = packed;
         }
     });
     image.SetPixels(imageWidth, imageHeight, pixels);
     AssignResolution(image);
 }
 private void ConvertFromRgb(int imageWidth, int imageHeight, ImageBase image)
 {
     int scale = comp[0].h/comp[1].h;
     Color2[] pixels = new Color2[imageWidth*imageHeight];
     Parallel.For(0, imageHeight, Bootstrapper.instance.ParallelOptions, y =>{
         int yo = ycbcrImage.get_row_y_offset(y);
         int co = ycbcrImage.get_row_c_offset(y);
         for (int x = 0; x < imageWidth; x++){
             byte red = ycbcrImage.pix_y[yo + x];
             byte green = ycbcrImage.pix_cb[co + (x/scale)];
             byte blue = ycbcrImage.pix_cr[co + (x/scale)];
             int index = (y*imageWidth) + x;
             Color2 packed = Color2.FromArgb(red, green, blue);
             pixels[index] = packed;
         }
     });
     image.SetPixels(imageWidth, imageHeight, pixels);
     AssignResolution(image);
 }
 public int GetPaletteIndex(Color2 pixel, int level)
 {
     int index = paletteIndex;
     if (!leaf){
         int shift = 7 - level;
         byte[] components = pixel.ToBytes();
         int pixelIndex = ((components[2] & Mask[level]) >> (shift - 2)) | ((components[1] & Mask[level]) >> (shift - 1)) |
                         ((components[0] & Mask[level]) >> shift);
         if (children[pixelIndex] != null){
             index = children[pixelIndex].GetPaletteIndex(pixel, level + 1);
         } else{
             throw new Exception($"Cannot retrive a pixel at the given index {pixelIndex}.");
         }
     }
     return index;
 }
 public void AddColor(Color2 pixel, int colorBits, int level, Octree octree)
 {
     if (leaf){
         Increment(pixel);
         octree.TrackPrevious(this);
     } else{
         int shift = 7 - level;
         byte[] components = pixel.ToBytes();
         int index = ((components[2] & Mask[level]) >> (shift - 2)) | ((components[1] & Mask[level]) >> (shift - 1)) |
                     ((components[0] & Mask[level]) >> shift);
         OctreeNode child = children[index];
         if (child == null){
             child = new OctreeNode(level + 1, colorBits, octree);
             children[index] = child;
         }
         child.AddColor(pixel, colorBits, level + 1, octree);
     }
 }
 public void Increment(Color2 pixel)
 {
     pixelCount++;
     byte[] components = pixel.ToBytes();
     red += components[0];
     green += components[1];
     blue += components[2];
 }
 protected override void InitialQuantizePixel(Color2 pixel)
 {
     octree.AddColor(pixel);
 }
 public int GetPaletteIndex(Color2 pixel)
 {
     return root.GetPaletteIndex(pixel, 0);
 }
        private void ReadFrameColors(byte[] indices, byte[] colorTable, GifImageDescriptor descriptor)
        {
            int imageWidth = logicalScreenDescriptor.Width;
            int imageHeight = logicalScreenDescriptor.Height;
            if (currentFrame == null){
                currentFrame = new Color2[imageWidth*imageHeight];
            }
            Color2[] lastFrame = null;
            if (graphicsControlExtension != null && graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToPrevious){
                lastFrame = new Color2[imageWidth*imageHeight];
                Array.Copy(currentFrame, lastFrame, lastFrame.Length);
            }
            int offset, i = 0;
            int interlacePass = 0; // The interlace pass
            int interlaceIncrement = 8; // The interlacing line increment
            int interlaceY = 0; // The current interlaced line
            for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++){
                // Check if this image is interlaced.
                int writeY; // the target y offset to write to
                if (descriptor.InterlaceFlag){
                    // If so then we read lines at predetermined offsets.
                    // When an entire image height worth of offset lines has been read we consider this a pass.
                    // With each pass the number of offset lines changes and the starting line changes.
                    if (interlaceY >= descriptor.Height){
                        interlacePass++;
                        switch (interlacePass){
                            case 1:
                                interlaceY = 4;
                                break;
                            case 2:
                                interlaceY = 2;
                                interlaceIncrement = 4;
                                break;
                            case 3:
                                interlaceY = 1;
                                interlaceIncrement = 2;
                                break;
                        }
                    }
                    writeY = interlaceY + descriptor.Top;
                    interlaceY += interlaceIncrement;
                } else{
                    writeY = y;
                }
                for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width; x++){
                    offset = (writeY*imageWidth) + x;
                    int index = indices[i];
                    if (graphicsControlExtension == null || graphicsControlExtension.TransparencyFlag == false ||
                        graphicsControlExtension.TransparencyIndex != index){
                        // Stored in r-> g-> b-> a order.
                        int indexOffset = index*3;
                        Color2 pixel = Color2.FromArgb(colorTable[indexOffset], colorTable[indexOffset + 1], colorTable[indexOffset + 2]);
                        currentFrame[offset] = pixel;
                    }
                    i++;
                }
            }
            Color2[] pixels = new Color2[imageWidth*imageHeight];
            Array.Copy(currentFrame, pixels, pixels.Length);
            ImageBase currentImage;
            if (decodedImage.Pixels == null){
                currentImage = decodedImage;
                currentImage.SetPixels(imageWidth, imageHeight, pixels);
                currentImage.Quality = colorTable.Length/3;
                if (graphicsControlExtension != null && graphicsControlExtension.DelayTime > 0){
                    decodedImage.FrameDelay = graphicsControlExtension.DelayTime;
                }
            } else{
                ImageFrame frame = new ImageFrame();
                currentImage = frame;
                currentImage.SetPixels(imageWidth, imageHeight, pixels);
                currentImage.Quality = colorTable.Length/3;
                if (graphicsControlExtension != null && graphicsControlExtension.DelayTime > 0){
                    currentImage.FrameDelay = graphicsControlExtension.DelayTime;
                }
                decodedImage.Frames.Add(frame);
            }
            if (graphicsControlExtension != null){
                if (graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToBackground){
                    for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++){
                        for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width; x++){
                            offset = (y*imageWidth) + x;

                            // Stored in r-> g-> b-> a order.
                            currentFrame[offset] = default(Color2);
                        }
                    }
                } else if (graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToPrevious){
                    currentFrame = lastFrame;
                }
            }
        }
Beispiel #49
0
 public Brush2(Color2 color)
 {
     Color = color;
 }