Exemplo n.º 1
0
        public bool MustPress()
        {
            var color = Pixels.GetPixelColor(p);

            return(color.R == Color.R && color.G == Color.G && color.B == Color.B);
        }
Exemplo n.º 2
0
        static Pixels[,] zoom_in_with_cubic_rgb(Pixels[,] image, int width, int height, int new_width, int new_height)
        {
            int   x = 0, y = 0, m = 0, n = 0;
            float dx, dy;

            float[] t_blue  = new float[4];
            float[] t_red   = new float[4];
            float[] t_green = new float[4];
            dx = (float)width / (float)(new_width - 1);
            dy = (float)height / (float)(new_height - 1);
            Pixels[,] _zoomImg = new Pixels[new_height, new_width];

            for (y = 0; y < new_height; y++)
            {
                double iy = y * dy - 0.5;
                double v  = iy - Math.Floor(iy);
                int    oy = (int)iy;
                if (oy - 1 < 0)
                {
                    oy = 1;
                }
                if (((oy + 1) > (height - 1)) && ((oy + 2) > (height - 1)))
                {
                    oy = height - 4;
                }
                else if (((oy + 1) <= (height - 1)) && ((oy + 2) > (height - 1)))
                {
                    oy = height - 3;
                }
                for (x = 0; x < new_width; x++)
                {
                    double ix = x * dx - 0.5;
                    double s  = ix - Math.Floor(ix);
                    int    ox = (int)ix;
                    if (ox - 1 < 0)
                    {
                        ox = 1;
                    }
                    if ((ox + 1 > width - 1) && ((ox + 2) > (width - 1)))
                    {
                        ox = width - 4;
                    }
                    else if (((ox + 1) <= (width - 1)) && ((ox + 2) > (width - 1)))
                    {
                        ox = width - 3;
                    }
                    t_blue[0] = CubicHermite(image[oy - 1, ox - 1].blue, image[oy - 1, ox].blue, image[oy - 1, ox + 1].blue, image[oy - 1, ox + 2].blue, (float)s);
                    t_blue[1] = CubicHermite(image[oy, ox - 1].blue, image[oy, ox].blue, image[oy, ox + 1].blue, image[oy, ox + 2].blue, (float)s);
                    t_blue[2] = CubicHermite(image[oy + 1, ox - 1].blue, image[oy + 1, ox].blue, image[oy + 1, ox + 1].blue, image[oy + 1, ox + 2].blue, (float)s);
                    t_blue[3] = CubicHermite(image[oy + 2, ox - 1].blue, image[oy + 2, ox].blue, image[oy + 2, ox + 1].blue, image[oy + 2, ox + 2].blue, (float)s);
                    //
                    //
                    //t[0] = CubicHermite(image[ox - 1,oy - 1], image[ox,oy - 1], image[ox + 1,oy - 1], image[ox + 2,oy - 1], s);
                    //t[1] = CubicHermite(image[ox - 1,oy], image[ox,oy], image[ox + 1,oy], image[ox + 2,oy], s);
                    //t[2] = CubicHermite(image[ox - 1,oy + 1], image[ox,oy + 1], image[ox + 1,oy + 1], image[ox + 2,oy + 1], s);
                    //t[3] = CubicHermite(image[ox - 1,oy + 2], image[ox,oy + 2], image[ox + 1,oy + 2], image[ox + 2,oy + 2], s);
                    int valueblue = (int)CubicHermite(t_blue[0], t_blue[1], t_blue[2], t_blue[3], (float)v);
                    _zoomImg[y, x].blue = clamp(valueblue, 0, 255);

                    //red
                    t_red[0] = CubicHermite(image[oy - 1, ox - 1].red, image[oy - 1, ox].red, image[oy - 1, ox + 1].red, image[oy - 1, ox + 2].red, (float)s);
                    t_red[1] = CubicHermite(image[oy, ox - 1].red, image[oy, ox].red, image[oy, ox + 1].red, image[oy, ox + 2].red, (float)s);
                    t_red[2] = CubicHermite(image[oy + 1, ox - 1].red, image[oy + 1, ox].red, image[oy + 1, ox + 1].red, image[oy + 1, ox + 2].red, (float)s);
                    t_red[3] = CubicHermite(image[oy + 2, ox - 1].red, image[oy + 2, ox].red, image[oy + 2, ox + 1].red, image[oy + 2, ox + 2].red, (float)s);
                    int valuered = (int)CubicHermite(t_red[0], t_red[1], t_red[2], t_red[3], (float)v);
                    _zoomImg[y, x].red = clamp(valuered, 0, 255);

                    //green
                    t_green[0] = CubicHermite(image[oy - 1, ox - 1].green, image[oy - 1, ox].green, image[oy - 1, ox + 1].green, image[oy - 1, ox + 2].green, (float)s);
                    t_green[1] = CubicHermite(image[oy, ox - 1].green, image[oy, ox].green, image[oy, ox + 1].green, image[oy, ox + 2].green, (float)s);
                    t_green[2] = CubicHermite(image[oy + 1, ox - 1].green, image[oy + 1, ox].green, image[oy + 1, ox + 1].green, image[oy + 1, ox + 2].green, (float)s);
                    t_green[3] = CubicHermite(image[oy + 2, ox - 1].green, image[oy + 2, ox].green, image[oy + 2, ox + 1].green, image[oy + 2, ox + 2].green, (float)s);
                    int valuegreen = (int)CubicHermite(t_green[0], t_green[1], t_green[2], t_green[3], (float)v);
                    _zoomImg[y, x].green = clamp(valuegreen, 0, 255);
                }
            }
            return(_zoomImg);
        }
Exemplo n.º 3
0
        internal static int GetTextValue(Rectangle rectangle)
        {
            Stopwatch st = Stopwatch.StartNew();

            Bitmap src = Pixels.GetScreenshot();

            Bitmap target = new Bitmap(rectangle.Width, rectangle.Height);


            using (Graphics g = Graphics.FromImage(target))
            {
                g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), rectangle, GraphicsUnit.Pixel);
            }

            Page page = Engine.Process(target);

            int    text;
            string textReplacement;

            textReplacement = page.GetText();
            if (textReplacement.Contains('I'))
            {
                textReplacement = textReplacement.Replace('I', '1');
            }

            if (textReplacement.Contains(' '))
            {
                textReplacement = textReplacement.Replace(" ", String.Empty);
            }

            if (textReplacement.Contains('Z'))
            {
                textReplacement = textReplacement.Replace('Z', '2');
            }

            if (textReplacement.Contains('S'))
            {
                textReplacement = textReplacement.Replace('S', '5');
            }

            if (textReplacement.Contains("\n"))
            {
                textReplacement = textReplacement.Replace("\n", String.Empty);
            }

            try
            {
                text = Convert.ToInt32(textReplacement);
            }
            catch
            {
                text = 0;
            }

            src.Dispose();

            target.Dispose();

            page.Dispose();

            return(text);
        }
        public override byte[] ToByteArray(int index)
        {
            //System.IO.File.WriteAllBytes(@"pixels_" + DateTime.Now.Ticks + ".bin", Pixels.ToArray());   // DEBUG

            System.Diagnostics.Debug.Assert(index == 0);
            List <byte> ourResult = new List <byte>(36864);

            foreach (Palette p in Palettes)
            {
                ourResult.AddRange(p.ToByteArray());
            }
            for (int i = 0; i < 36864; i++)
            {
                ourResult.Add((byte)((Pixels[2 * i + 1] << 4) | (Pixels[2 * i] & 0x0F)));
            }

            int pixelIndex = Pixels.Count - 1;

            for (; ((pixelIndex >= 0) && (Pixels[pixelIndex] == 0)); pixelIndex--)
            {
                ;
            }
            pixelIndex = (pixelIndex < 0) ? 0 : pixelIndex;
            int sectorByteIndex     = Math.Min(((pixelIndex / 2048) * 2048), 122880);
            int nextSectorByteIndex = sectorByteIndex + 2048;

            //int endIndex = Math.Min(nextSectorByteIndex, 124928) - 1;
            //int endIndex = Math.Min(nextSectorByteIndex + (2048 * 3), 124928) - 1;

            /*
             * // DEBUG
             * System.Text.StringBuilder sb = new System.Text.StringBuilder();
             * for (int testIndex = 99999; testIndex < 111111; testIndex++)
             * {
             *  byte[] testBytes = Recompress(Pixels.Sub(2 * 36864, testIndex));
             *  int testStartIndex = testBytes.Length - 2;
             *  int testEndIndex = testStartIndex + 1;
             *  if ((testBytes[testStartIndex] == 0xD8) && (testBytes[testEndIndex] == 0x90))
             *      sb.AppendLine(testIndex.ToString());
             * }
             * string testText = sb.ToString();
             * if (!string.IsNullOrEmpty(testText))
             * {
             *  System.IO.File.WriteAllText(@"recompress_index.txt", testText);
             * }
             */

            //if (OriginalSize > 38912)
            //if (OriginalSize > 40960)
            //if (sectorByteIndex > (40960 * 2))

            if (sectorByteIndex > (55296 * 2))
            {
                ourResult.AddRange(Recompress(Pixels.Sub(2 * 36864, 2 * 36864 + 200 * 256 - 1)));     // (73728, 124927)
            }
            else if (sectorByteIndex > (49152 * 2))
            {
                //int endIndex = Math.Min(nextSectorByteIndex + (2048 * 2) + 1024 + 512, 124928) - 1;
                //int endIndex = Math.Min(nextSectorByteIndex + (2048 * 4), 124928) - 1;
                int endIndex = Math.Min(nextSectorByteIndex + 6568, 124928) - 1;

                byte[] bytes = Recompress(Pixels.Sub(2 * 36864, endIndex));
                //bytes[bytes.Length - 2] = 0xD8;
                //bytes[bytes.Length - 1] = 0x90;

                ourResult.AddRange(bytes);
            }
            else if (sectorByteIndex > (38912 * 2))
            {
                int endIndex = Math.Min(nextSectorByteIndex + 6568, 124928) - 1;
                //int endIndex = Math.Min(nextSectorByteIndex + (2048 * 3), 124928) - 1;

                byte[] bytes = Recompress(Pixels.Sub(2 * 36864, endIndex));
                bytes[bytes.Length - 2] = 0xD8;
                bytes[bytes.Length - 1] = 0x90;

                ourResult.AddRange(bytes);
            }

            if (ourResult.Count < OriginalSize)
            {
                ourResult.AddRange(new byte[OriginalSize - ourResult.Count]);
            }

            return(ourResult.ToArray());
        }
Exemplo n.º 5
0
        private void LoadImgBinary(FileStream stream)
        {
            BinaryReader binReader = new BinaryReader(stream);

            int headerItemCount = 0;

            while (headerItemCount < 4)
            {
                char nextChar = (char)binReader.PeekChar();
                if (nextChar == '#')
                {
                    while (binReader.ReadChar() != '\n')
                    {
                        ;
                    }
                }
                else if (Char.IsWhiteSpace(nextChar))
                {
                    binReader.ReadChar();
                }
                else
                {
                    switch (headerItemCount)
                    {
                    case 0:     //zczytaj typ pliku
                        char[] chars = binReader.ReadChars(2);
                        this.FileType = chars[0].ToString() + chars[1].ToString();
                        headerItemCount++;
                        break;

                    case 1:     //liczba kolumn
                        this.Width = ReadValue(binReader);
                        headerItemCount++;
                        break;

                    case 2:     //liczba wierszy
                        this.Height = ReadValue(binReader);
                        headerItemCount++;
                        break;

                    case 3:     //max wartosc
                        this.Depth = ReadValue(binReader);
                        headerItemCount++;
                        break;

                    default:
                        throw new Exception("[EX_1] Podczas wykonywania operacji wystąpił błąd.");
                    }
                }
            }

            if (FileType == "P3")
            {
                binReader.ReadChar();
                int    charsLeft = (int)(binReader.BaseStream.Length - binReader.BaseStream.Position);
                char[] charData  = binReader.ReadChars(charsLeft);
                string data      = new string(charData);
                data = data.Replace(System.Environment.NewLine, " ");

                int[] pixels = data.Split(' ').Where(o => !String.IsNullOrEmpty(o)).Select(int.Parse).ToArray();

                if (Depth != 255)
                {
                    pixels = NormalizeLine(pixels);
                }

                for (int j = 0; j < pixels.Length; j += 3)
                {
                    Pixels.Add(new Pixel(pixels[j], pixels[j + 1], pixels[j + 2]));
                }

                BitMap = new Bitmap(Width, Height);

                int pIndex = 0;
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        Color color = Color.FromArgb(255, Pixels[pIndex].R, Pixels[pIndex].G, Pixels[pIndex].B);
                        BitMap.SetPixel(x, y, color);
                        pIndex++;
                    }
                }
            }
            else if (FileType == "P6")
            {
                int bytesLeft = (int)(binReader.BaseStream.Length - binReader.BaseStream.Position);
                this.imageData = binReader.ReadBytes(bytesLeft);
                ConvertBGRToRGB();
                if (Depth != 255)
                {
                    imageData = NormalizeByteArray(imageData);
                }


                Bitmap   bitmap = new Bitmap(this.Width, this.Height, PixelFormat.Format24bppRgb);
                SysColor color = new SysColor();
                int      red, green, blue;
                int      index;

                for (int x = 0; x < this.Width; x++)
                {
                    for (int y = 0; y < this.Height; y++)
                    {
                        index = x + y * this.Width;
                        index = 3 * index;
                        blue  = (int)this.imageData[index];
                        green = (int)this.imageData[index + 1];
                        red   = (int)this.imageData[index + 2];
                        color = SysColor.FromArgb(red, green, blue);
                        bitmap.SetPixel(x, y, color);
                    }
                }
                bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
                BitMap = bitmap;
            }
        }
Exemplo n.º 6
0
        public void WriteTo(BinaryWriter writer)
        {
            writer.Write(SERIALIZATION_VERSION);

            writer.Write(CombinedMeasurements);
            writer.Write(SignalAreaWidth);
            writer.Write(MaxPixelValue);
            writer.Write(MaxSpectraValue);
            writer.Write(ZeroOrderPixelNo);

            writer.Write(Points.Count);
            foreach (var spectraPoint in Points)
            {
                spectraPoint.WriteTo(writer);
            }

            int width  = Pixels.GetLength(0);
            int height = Pixels.GetLength(1);

            writer.Write(width);
            writer.Write(height);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    writer.Write(Pixels[x, y]);
                }
            }

            MeasurementInfo.WriteTo(writer);

            if (Calibration == null)
            {
                writer.Write(false);
            }
            else
            {
                writer.Write(true);
                Calibration.WriteTo(writer);
            }

            writer.Write(RawMeasurements.Count);
            for (int i = 0; i < RawMeasurements.Count; i++)
            {
                Spectra frameSpectra = RawMeasurements[i];

                writer.Write(frameSpectra.SignalAreaWidth);
                writer.Write(frameSpectra.MaxPixelValue);
                writer.Write(frameSpectra.MaxSpectraValue);
                writer.Write(frameSpectra.ZeroOrderPixelNo);
                writer.Write(frameSpectra.ZeroOrderFWHM); // Version 2 Property

                writer.Write(frameSpectra.Points.Count);
                foreach (var spectraPoint in frameSpectra.Points)
                {
                    spectraPoint.WriteTo(writer);
                }
            }

            ProcessingInfo.WriteTo(writer);
            ObservationInfo.WriteTo(writer);

            // Version 2 Properties
            writer.Write(ZeroOrderFWHM);
        }
Exemplo n.º 7
0
 public PixelBuffer GetBleededBuffer()
 {
     byte[] NewBuffer = Pixels.ToArray();
     MakeBleeding(NewBuffer, BufferSize.Width, BufferSize.Height);
     return(new PixelBuffer(NewBuffer, BufferSize));
 }
Exemplo n.º 8
0
 public int PixelValue(int y, int x)
 {
     return(Pixels.Single(p => p.X == x && p.Y == y).Value);
 }
Exemplo n.º 9
0
 public override int GetHashCode()
 {
     return(Pixels.GetHashCode());
 }
Exemplo n.º 10
0
        public void sendImage(string fileName)
        {
            Bitmap bitmap = new Bitmap(fileName);

            int   x;
            int   y;
            int   i;
            int   RowBytes;
            byte  n;
            Color Pixels;

            byte[,] ImageArray = new byte[bitmap.Width, bitmap.Height];

            // Calculate output size
            RowBytes = (bitmap.Width + 7) / 8;
            // Generate body of array

            int w = bitmap.Width / 8;

            if (bitmap.Width < 8)
            {
                w = 1;
            }

            for (y = 0; y < bitmap.Height; y++)
            {     // Each row...
                for (x = 0; x < w; x++)
                { // Each 8-pixel block within row...
                    ImageArray[x, y] = 0;
                    for (n = 0; n < 8; n++)
                    { // Each pixel within block...
                        if (x * 8 + n >= bitmap.Width)
                        {
                            continue;
                        }

                        Pixels = bitmap.GetPixel(x * 8 + n, y);
                        if (Pixels.GetBrightness() < 0.5)
                        {
                            ImageArray[x, y] += (byte)(1 << (7 - n));
                        }
                    }
                }
            }

            mMemory.WriteByte((byte)0x1d);//GS
            mMemory.WriteByte((byte)'v');
            mMemory.WriteByte((byte)'0');
            mMemory.WriteByte((byte)0);

            mMemory.WriteByte((byte)(RowBytes & 0xff));
            mMemory.WriteByte((byte)((RowBytes >> 8) & 0xff));
            mMemory.WriteByte((byte)(bitmap.Height & 0xff));
            mMemory.WriteByte((byte)((bitmap.Height >> 8) & 0xff));

            for (y = 0; y < bitmap.Height; y++)
            {
                for (x = 0; x < RowBytes; x++)
                {
                    mMemory.WriteByte(ImageArray[x, y]); //[d1 ..... dn]
                }
            }
            sendPkt();
        }
Exemplo n.º 11
0
 public int this[int index1, int index2] =>
 Pixels.Single(it => it.X == index1 && it.Y == index2).Color;
Exemplo n.º 12
0
 public void GetPixelByteRow(int x, int y, Span <byte> destination)
 {
     Pixels.GetPixelByteRow(x, y, destination);
 }
Exemplo n.º 13
0
 private void FlipGridHorizontally()
 {
     Pixels.Reset(MatrixUtil.FlipMatrixHorizontally(Pixels.ToArray(), GridWidth, GridHeight));
     AddHistoryState("Flip Grid Horizontally");
     IsDirty = true;
 }
Exemplo n.º 14
0
 private void RotateGrid180()
 {
     Pixels.Reset(MatrixUtil.RotateMatrix180(Pixels.ToArray(), GridWidth, GridHeight));
     AddHistoryState("Rotate Grid 180°");
     IsDirty = true;
 }
Exemplo n.º 15
0
        internal void OnBitmapSelection(List <int> pixels, Brush brush, bool isSelected)
        {
            if (pixels != null && pixels.Count > 0)
            {
                int seriesIndex = Area.Series.IndexOf(this);

                if (!Area.isBitmapPixelsConverted)
                {
                    Area.ConvertBitmapPixels();
                }

                // Gets the upper series from the selected series
                var upperSeriesCollection = (from series in Area.Series
                                             where Area.Series.IndexOf(series) > seriesIndex
                                             select series).ToList();

                // Gets the upper series pixels in to single collection
                foreach (var series in upperSeriesCollection)
                {
                    upperSeriesPixels.UnionWith(series.Pixels);
                }

                {
                    byte[] buffer = Area.GetFastBuffer();
                    int    j      = 0;
                    Color  uiColor;

                    if (isSelected && brush != null)
                    {
                        uiColor = (brush as SolidColorBrush).Color;
                    }
                    else
                    {
                        if (this is FastHiLoOpenCloseBitmapSeries)
                        {
                            uiColor = ((Segments[0] as FastHiLoOpenCloseSegment).GetSegmentBrush(dataPoint.Index));
                        }
                        else if (this is FastCandleBitmapSeries)
                        {
                            uiColor = ((Segments[0] as FastCandleBitmapSegment).GetSegmentBrush(dataPoint.Index));
                        }
                        else
                        {
                            Brush interior           = GetInteriorColor(dataPoint.Index);
                            var   linearGradienBrush = interior as LinearGradientBrush;
                            uiColor = linearGradienBrush != null ? linearGradienBrush.GradientStops[0].Color : (interior as SolidColorBrush).Color;
                        }
                    }

                    foreach (var pixel in pixels)
                    {
                        if (Pixels.Contains(pixel) && !upperSeriesPixels.Contains(pixel))
                        {
                            if (j == 0)
                            {
                                buffer[pixel] = uiColor.B;
                                j             = j + 1;
                            }
                            else if (j == 1)
                            {
                                buffer[pixel] = uiColor.G;
                                j             = j + 1;
                            }
                            else if (j == 2)
                            {
                                buffer[pixel] = uiColor.R;
                                j             = j + 1;
                            }
                            else if (j == 3)
                            {
                                buffer[pixel] = uiColor.A;
                                j             = 0;
                            }
                        }
                    }

                    Area.RenderToBuffer();
                }

                upperSeriesPixels.Clear();
            }
        }
Exemplo n.º 16
0
        private void Show()
        {
            var pixels = new Pixels(ImmutableList.CreateRange(_currentStatuses));

            LedMatrix.SetPixels(pixels);
        }
Exemplo n.º 17
0
 public Image(int size)
 {
     Pixels.AddRange(new int[size]);
 }
Exemplo n.º 18
0
        public virtual void ImportBitmap4bpp(int paletteIndex, IList <byte> importBytes, IList <byte> originalPaletteBytes)
        {
            using (System.IO.Stream stream = new System.IO.MemoryStream(importBytes.ToArray()))
            {
                using (System.Drawing.Image image = System.Drawing.Image.FromStream(stream))
                {
                    if (image.PixelFormat != PixelFormat.Format4bppIndexed)
                    {
                        throw new BadImageFormatException("Image is not an 4bpp paletted bitmap!");
                    }
                    if (image.Width != 256)
                    {
                        throw new BadImageFormatException("Image is not 256 pixels wide!");
                    }

                    const int singlePaletteBytes = 32;
                    Palettes = new Palette[16];

                    for (int i = 0; i < 16; i++)
                    {
                        int          startIndex = singlePaletteBytes * i;
                        int          endIndex   = startIndex + singlePaletteBytes - 1;
                        IList <byte> bytes      = originalPaletteBytes.Sub(startIndex, endIndex);
                        Palettes[i] = new Palette(bytes, Palette.ColorDepth._16bit);
                    }
                    for (int i = 0; i < image.Palette.Entries.Length; i++)
                    {
                        Color c = image.Palette.Entries[i];
                        Palettes[paletteIndex][i] = Color.FromArgb(c.R & 0xF8, c.G & 0xF8, c.B & 0xF8);
                        if ((i == 0) && c.ToArgb() == Color.Black.ToArgb())
                        {
                            Palettes[paletteIndex][i] = Color.Transparent;
                        }
                    }

                    Pixels.InitializeElements();

                    int combinedWidth = (image.Width + 1) / 2;
                    int stride        = (((Width * 4) + 31) / 32) * 4;

                    byte[] resultData      = new byte[image.Height * stride];
                    int    imageDataOffset = importBytes[10] | (importBytes[11] << 8) | (importBytes[12] << 16) | (importBytes[13] << 24);

                    for (int rowIndex = 0; rowIndex < image.Height; rowIndex++)
                    {
                        for (int colIndex = 0; colIndex < combinedWidth; colIndex++)
                        {
                            int  currentByteIndex = imageDataOffset + (rowIndex * stride) + colIndex;
                            int  pixelIndex       = ((image.Height - rowIndex - 1) * image.Width) + (colIndex * 2);
                            byte currentByte      = importBytes[currentByteIndex];

                            if (pixelIndex < Pixels.Count)
                            {
                                Pixels[pixelIndex] = (byte)((currentByte & 0xF0) >> 4);
                                if ((colIndex < image.Width) && ((pixelIndex + 1) < Pixels.Count))
                                {
                                    Pixels[pixelIndex + 1] = (byte)(currentByte & 0x0F);
                                }
                            }
                        }
                    }
                }
            }

            BitmapDirty = true;
            FirePixelsChanged();
        }
        public override string ToString()
        {
            switch (Type)
            {
            case PropertyType.Null:
                return("null");

            case PropertyType.Calculated:
                return("calculated");

            case PropertyType.Bool:
                return(Bool.ToString());

            case PropertyType.String:
                return("string: " + StringHandle.ToString());

            case PropertyType.MultiValue:
                return("multi: " + MultiValueHandle.ToString());

            case PropertyType.Enum:
                return("enum: " + Enum.ToString());

            case PropertyType.Color:
                return("color: " + Color.ToString());

            case PropertyType.Integer:
                return(Integer.ToString() + " (integer)");

            case PropertyType.Fractional:
                return(Fractional.ToString() + " (fractional)");

            case PropertyType.Percentage:
                return(Percentage.ToString() + "%");

            case PropertyType.AbsLength:
                return(string.Concat(new string[]
                {
                    Points.ToString(),
                    "pt (",
                    Inches.ToString(),
                    "in, ",
                    Millimeters.ToString(),
                    "mm) (abs)"
                }));

            case PropertyType.RelLength:
                return(string.Concat(new string[]
                {
                    Points.ToString(),
                    "pt (",
                    Inches.ToString(),
                    "in, ",
                    Millimeters.ToString(),
                    "mm) (rel)"
                }));

            case PropertyType.Pixels:
                return(Pixels.ToString() + "px");

            case PropertyType.Ems:
                return(Ems.ToString() + "em");

            case PropertyType.Exs:
                return(Exs.ToString() + "ex");

            case PropertyType.HtmlFontUnits:
                return(HtmlFontUnits.ToString() + " (html font units)");

            case PropertyType.RelHtmlFontUnits:
                return(RelativeHtmlFontUnits.ToString() + " (relative html font units)");

            case PropertyType.Multiple:
                return(Integer.ToString() + "*");

            case PropertyType.Milliseconds:
                return(Milliseconds.ToString() + "ms");

            case PropertyType.kHz:
                return(kHz.ToString() + "kHz");

            case PropertyType.Degrees:
                return(Degrees.ToString() + "deg");

            default:
                return("unknown value type");
            }
        }
Exemplo n.º 20
0
 protected bool Equals(Symbol other)
 {
     return(Pixels.ToString() == other.ToString());
 }
Exemplo n.º 21
0
 public void SendPixelUpdate(Pixels pixels)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 22
0
 public override int GetHashCode()
 {
     return(Pixels.ToString() !.GetHashCode());
 }
Exemplo n.º 23
0
 public bool IsExistsInList(List <HandwrittenImage> images)
 {
     return(images.Select(x => String.Join("", x.Pixels.MatrixToArray())).Contains(String.Join("", Pixels.MatrixToArray())));
 }
Exemplo n.º 24
0
 public override string ToString()
 {
     return(Enumerable.Range(0, Height)
            .StrJoin("\n",
                     y => Enumerable.Range(0, Width).StrJoin(x => Pixels.Contains(new Vec(x, y)) ? "#" : ".")));
 }
Exemplo n.º 25
0
        public static Bitmap MixBothImage()
        {
            int i = 0, j = 0;
            /************Tao mot mang IMG 60 * 80***************/
            //ushort[,] img_arr_pmg = new ushort[60, 80];

            /***********Chuyen Mang du lieu doc duoc thanh mang anh 256 cap xam***************/
            ushort minval = ImageProcessing.MinVal;

            byte[,] raw_to_bmp = new byte[60, 80];
            double scale = 255.0 / ImageProcessing.SubVal;

            for (i = 0; i < 60; i++)
            {
                for (j = 0; j < 80; j++)
                {
                    //int temp = img_arr_pmg[i, j] - minval;
                    //raw_to_bmp[60 - i - 1, j] = (byte)((img_arr_pmg[i, j] - minval) * scale);
                    raw_to_bmp[60 - i - 1, 80 - j - 1] = (byte)((ImageProcessing.imgFLIR16[i * 80 + j] - minval) * scale);
                }
            }

            /*********Tao mang 240 x 320 image scaling *********************/
            byte[,] scaleimg = new byte[240, 320];
            scaleimg         = zoom_in_with_cubic(raw_to_bmp, 80, 60, 320, 240);

            /****************Tao mang 240 x 320 image rotating******************/
            //byte[,] rotateimg = new byte[240, 320];
            //rotateImg(scaleimg, rotateimg, -90);

            /*********Anh RGB******************/
            Pixels[,] img_arr_rgb = ImageProcessing.UndistortedJPGToPixels();//mang anh rgb input
            Pixels[,] img_cutted  = new Pixels[180, 252];
            for (i = 0; i < 180; i++)
            {
                for (j = 0; j < 252; j++)
                {
                    img_cutted[i, j] = img_arr_rgb[i + 17, j + 36];
                }
            }
            Pixels[,] img_zooming_rgb = new Pixels[240, 320];
            img_zooming_rgb           = zoom_in_with_cubic_rgb(img_cutted, 252, 180, 320, 240);
            //average_overlay_rgb(img_zooming_rgb, ImageProcessing.rgb, rotateimg);
            average_overlay_rgb(img_zooming_rgb, ImageProcessing.rgb, scaleimg);

            int n = 0;

            byte[] arrImg = new byte[240 * 320 * 3];
            for (i = 239; i >= 0; i--)
            {
                for (j = 319; j >= 0; j--)
                {
                    arrImg[n]     = (byte)img_zooming_rgb[i, j].blue;
                    arrImg[n + 1] = (byte)img_zooming_rgb[i, j].green;
                    arrImg[n + 2] = (byte)img_zooming_rgb[i, j].red;
                    n            += 3;
                }
            }
            Bitmap bmpTemp = ImageProcessing.CreateBitmapFromBytes(arrImg, 320, 240);

            return(bmpTemp);
        }
Exemplo n.º 26
0
 public int UpdatePixelCache()
 {
     _pixelCache = Pixels.Where(x => x.Node != null).ToList();
     _points     = new List <float>(_pixelCache.Count * 8);
     return(_pixelCache.Count);
 }
Exemplo n.º 27
0
 public OnScreenPixel(Color c, Point p, UIElement owner) : base(c, p)
 {
     Pixels.Add(new OwnedPixel(c, p, owner));
 }
Exemplo n.º 28
0
        public static void ReadText()
        {
            Console.WriteLine("Image Preprocessing...");

            List <string>    WLines = new List <string>();
            List <Rectangle> WRects = new List <Rectangle>();

            List <string>    PLines = new List <string>();
            List <Rectangle> PRects = new List <Rectangle>();

            Bitmap screenshot = Image.Utils.InvertImage(Image.Utils.ContrastImage(Image.Utils.DesaturateImage(Pixels.GetScreenshot()), 25));

            Console.WriteLine("Engine Processing...");
            var data = Engine.Process(screenshot, PageSegMode.SparseText);

            WRects = data.GetSegmentedRegions(PageIteratorLevel.Word);
            PRects = data.GetSegmentedRegions(PageIteratorLevel.TextLine);

            TextCache.Clear();
            PhraseCache.Clear();

            Console.WriteLine("Extracting Words...");

            using (var iterator = data.GetIterator())
            {
                string line = "";
                iterator.Begin();

                do
                {
                    do
                    {
                        do
                        {
                            do
                            {
                                string word = iterator.GetText(PageIteratorLevel.Word).Trim();
                                if (word != "")
                                {
                                    line = line + word + " ";
                                    WLines.Add(word.ToUpper().Trim());
                                }
                            }while (iterator.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word));

                            if (line != "")
                            {
                                PLines.Add(line.ToUpper().Trim());
                            }
                            line = "";
                        }while (iterator.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine));
                    }while (iterator.Next(PageIteratorLevel.Block, PageIteratorLevel.Para));
                }while (iterator.Next(PageIteratorLevel.Block));
            }
            data.Dispose();
            screenshot.Dispose();

            Console.WriteLine("Saving results...");

            for (int i = 0; i < WLines.Count; ++i)
            {
                if (!TextCache.ContainsKey(WLines[i]))
                {
                    TextCache.Add(WLines[i], new Point(Convert.ToInt32((WRects[i].X + (WRects[i].Width / 2)) * 1), Convert.ToInt32((WRects[i].Y + (WRects[i].Height / 2)) * 1)));
                }
            }

            for (int i = 0; i < PLines.Count; ++i)
            {
                if (!PhraseCache.ContainsKey(PLines[i]))
                {
                    PhraseCache.Add(PLines[i], new Point(Convert.ToInt32((PRects[i].X + (PRects[i].Width / 2)) * 1), Convert.ToInt32((PRects[i].Y + (PRects[i].Height / 2)) * 1)));
                }
            }
            Console.WriteLine("Read Complete.");
            Console.WriteLine("-----------------------");
        }