Example #1
0
        public Bitmap GetZoomImagePixels(int x0, int y0, Color saturationColor, TangraConfig.SaturationSettings saturationLevels, out Pixelmap zoomPixelmap)
        {
            int height = m_Pixelmap.Height;
            int width  = m_Pixelmap.Width;

            if (x0 < 15)
            {
                x0 = 15;
            }
            if (y0 < 15)
            {
                y0 = 15;
            }
            if (x0 > width - 16)
            {
                x0 = width - 16;
            }

            if (y0 > height - 16)
            {
                y0 = height - 16;
            }
            Bitmap featureBitmap = new Bitmap(31 * 8, 31 * 8, PixelFormat.Format24bppRgb);

            uint[] zoomPixels = new uint[31 * 8 * 31 * 8];

            uint saturationLevel = saturationLevels.GetSaturationForBpp(m_Pixelmap.BitPixCamera, m_Pixelmap.MaxSignalValue);

            BitmapData zoomedData = featureBitmap.LockBits(new Rectangle(0, 0, 31 * 8, 31 * 8), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            try
            {
                int    bytes        = zoomedData.Stride * featureBitmap.Height;
                byte[] zoomedValues = new byte[bytes];

                byte saturatedR = saturationColor.R;
                byte saturatedG = saturationColor.G;
                byte saturatedB = saturationColor.B;

                int selIdx = 0;

                if (m_Pixelmap.DisplayBitmapPixels != null && m_Pixelmap.DisplayBitmapPixels.Length == width * height)
                {
                    for (int yy = -15; yy < 16; yy++)
                    {
                        for (int xx = -15; xx < 16; xx++)
                        {
                            for (int i = 0; i < 8; i++)
                            {
                                for (int j = 0; j < 8; j++)
                                {
                                    int x = x0 + xx;
                                    int y = y0 + yy;

                                    int zoomedX = 8 * (xx + 15) + i;
                                    int zoomedY = 8 * (yy + 15) + j;


                                    byte zoomedByte = 0;
                                    uint pixelVal   = 0;
                                    if (x >= 0 && x < width && y >= 0 && y < height)
                                    {
                                        zoomedByte = m_Pixelmap.DisplayBitmapPixels[y * width + x];
                                        pixelVal   = m_Pixelmap[x, y];
                                    }

                                    int zoomedIdx = zoomedData.Stride * zoomedY + zoomedX * AstroImage.BytesPerDisplayBitmapPixel;

                                    zoomPixels[zoomedX + 31 * 8 * zoomedY] = pixelVal;

                                    if (pixelVal > saturationLevel)
                                    {
                                        // Saturation detected
                                        zoomedValues[zoomedIdx]     = saturatedR;
                                        zoomedValues[zoomedIdx + 1] = saturatedG;
                                        zoomedValues[zoomedIdx + 2] = saturatedB;
                                    }
                                    else
                                    {
                                        zoomedValues[zoomedIdx]     = zoomedByte;
                                        zoomedValues[zoomedIdx + 1] = zoomedByte;
                                        zoomedValues[zoomedIdx + 2] = zoomedByte;
                                    }
                                }
                            }

                            selIdx++;
                        }
                    }
                }

                Marshal.Copy(zoomedValues, 0, zoomedData.Scan0, bytes);
            }
            finally
            {
                featureBitmap.UnlockBits(zoomedData);
            }

            zoomPixelmap = new Pixelmap(31 * 8, 31 * 8, m_Pixelmap.BitPixCamera, zoomPixels, featureBitmap, null);
            return(featureBitmap);
        }
Example #2
0
        public Bitmap GetZoomImagePixels(int x0, int y0, Color saturationColor, TangraConfig.SaturationSettings saturationLevels)
        {
            Pixelmap zoomPixelmap;

            return(GetZoomImagePixels(x0, y0, saturationColor, saturationLevels, out zoomPixelmap));
        }