Exemple #1
0
        public Form1()
        {
            InitializeComponent();

            HDRImage skyImg = new HDRImage();

            skyImg.Open("../../DUMMY DATA/SKULUDwlJQa9o9yZot82ew_upscaled_trim.hdr");
            Bitmap classifiedImg = new Bitmap(skyImg.Width, skyImg.Height);

            //First, work out an average red blue division value
            float avgRBDiv = 0.0f;

            for (int x = 0; x < skyImg.Width; x++)
            {
                for (int y = 0; y < skyImg.Height; y++)
                {
                    HDRPixelFloat thisSkyPixel = skyImg.GetPixel(x, y).AsFloat();
                    avgRBDiv += thisSkyPixel.R / thisSkyPixel.B;
                }
            }
            avgRBDiv /= (skyImg.Width * skyImg.Height);

            //Categorise pixels based on the average divison (+ a bit extra)
            for (int x = 0; x < skyImg.Width; x++)
            {
                for (int y = 0; y < skyImg.Height; y++)
                {
                    HDRPixelFloat thisSkyPixel = skyImg.GetPixel(x, y).AsFloat();
                    float         redBlueDiv   = thisSkyPixel.R / thisSkyPixel.B;

                    if (redBlueDiv > (avgRBDiv + (avgRBDiv / 6.5f)))
                    {
                        classifiedImg.SetPixel(x, y, Color.White);
                    }
                    else
                    {
                        classifiedImg.SetPixel(x, y, Color.Black);
                    }
                }
            }

            //Remove all categorised pixels close to the sun position
            int start_x = classifiedImg.Width / 4;
            int start_y = 588; //588 is hard-coded for the test img, actually get this value from StreetviewImageProcessor

            FloodFill(classifiedImg, start_x, start_y, Color.Black);

            classifiedImg.Save("test.png");

            Application.Exit();
        }
Exemple #2
0
        protected override void OnLoad(BinaryReader reader)
        {
            lock (Renderer.Context)
            {
                var staging = IsStaging;

                Dispose(false);
                _disposed = false;

                var stream = reader.BaseStream;

                var fourCC = reader.ReadUInt32();
                var twoCC  = (ushort)fourCC;
                stream.Position = 0;

                Texture2D texture;

                if (fourCC == HDRImage.Magic)
                {
                    texture = new HDRImage(stream, staging).Texture2D;
                }
                else if (fourCC == MagicPNG || fourCC == MagicBMP || fourCC == MagicGIF || twoCC == MagicJPEG ||
                         twoCC == MagicBMP || fourCC == MagicRIFF || fourCC == DDSImage.Magic)
                {
                    using (
                        var decoder = new BitmapDecoder(Renderer.ImagingFactory, stream,
                                                        DecodeOptions.CacheOnDemand))
                    {
                        var frame = decoder.GetFrame(0);

                        using (var converter = new FormatConverter(Renderer.ImagingFactory))
                        {
                            converter.Initialize(frame, PixelFormat.Format32bppPRGBA);

                            int stride = frame.Size.Width * 4;
                            using (var buffer = new DataStream(frame.Size.Height * stride, true, true))
                            {
                                converter.CopyPixels(stride, buffer);

                                texture = new Texture2D(Renderer.Device, new Texture2DDescription
                                {
                                    Width     = frame.Size.Width,
                                    Height    = frame.Size.Height,
                                    ArraySize = 1,
                                    BindFlags =
                                        staging ? BindFlags.None : (BindFlags.ShaderResource | BindFlags.RenderTarget),
                                    Usage             = staging ? ResourceUsage.Staging : ResourceUsage.Default,
                                    Format            = Format.R8G8B8A8_UNorm,
                                    MipLevels         = 1,
                                    OptionFlags       = 0,
                                    CpuAccessFlags    = staging ? CpuAccessFlags.Read : CpuAccessFlags.None,
                                    SampleDescription = new SampleDescription(1, 0)
                                }, new DataRectangle(buffer.DataPointer, stride));
                            }
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException("Unknown texture format or corrupt data.");
                }

                NativeTexture = texture;
                if (texture.Description.BindFlags.HasFlag(BindFlags.ShaderResource))
                {
                    SrvArraySlices.Add(new ShaderResourceView(Renderer.Device, texture)
                    {
                        Tag = this, DebugName = Name
                    });
                }
            }

            IsLoaded = true;
        }