Example #1
0
        private void LoadImage(string path, ImageBuffer destImage, bool invertImage = false)
        {
            lock (locker)
            {
                if (!cachedImages.TryGetValue(path, out ImageBuffer cachedImage))
                {
                    using (var imageStream = OpenStream(path))
                        using (var bitmap = new Bitmap(imageStream))
                        {
                            cachedImage = new ImageBuffer();
                            ImageIOWindowsPlugin.ConvertBitmapToImage(cachedImage, bitmap);
                        }

                    if (cachedImage.Width < 200 && cachedImage.Height < 200)
                    {
                        // only cache relatively small images
                        cachedImages.Add(path, cachedImage);
                    }
                }

                // Themed icons are black and need be inverted on dark themes, or when white icons are requested
                if (invertImage)
                {
                    cachedImage = cachedImage.InvertLightness();
                    cachedImage.SetRecieveBlender(new BlenderPreMultBGRA());
                }

                destImage.CopyFrom(cachedImage);
            }
        }
 private void UpdateHistogramDisplay()
 {
     if (_histogramRawCache != null)
     {
         var graphics2D = _histogramDisplayCache.NewGraphics2D();
         graphics2D.Clear(Color.Transparent);
         _histogramDisplayCache.CopyFrom(_histogramRawCache);
         graphics2D.FillRectangle(0, 0, RangeStart * _histogramDisplayCache.Width, _histogramDisplayCache.Height, new Color(Color.Red, 100));
         graphics2D.FillRectangle(RangeEnd * _histogramDisplayCache.Width, 0, 255, _histogramDisplayCache.Height, new Color(Color.Red, 100));
         graphics2D.Line(RangeStart * _histogramDisplayCache.Width, 0, RangeStart * _histogramDisplayCache.Width, _histogramDisplayCache.Height, new Color(Color.LightGray, 200));
         graphics2D.Line(RangeEnd * _histogramDisplayCache.Width, 0, RangeEnd * _histogramDisplayCache.Width, _histogramDisplayCache.Height, new Color(Color.LightGray, 200));
     }
 }
Example #3
0
        private void RebuildColorToAlphaImage(ImageBuffer sourceImage, ImageBuffer alphaImage, ImageBuffer displayImage)
        {
            if (sourceImage == null)
            {
                return;
            }

            // build the alpha image
            if (alphaImage == null)
            {
                alphaImage = new ImageBuffer(sourceImage.Width, sourceImage.Height);
            }
            else if (alphaImage.Width != sourceImage.Width ||
                     alphaImage.Height != sourceImage.Height)
            {
                alphaImage.Allocate(sourceImage.Width, sourceImage.Height, sourceImage.BitDepth, sourceImage.GetRecieveBlender());
            }

            byte[] sourceBuffer = sourceImage.GetBuffer();
            byte[] destBuffer   = alphaImage.GetBuffer();
            Parallel.For(0, sourceImage.Height, (y) =>
                         //for(int y = 0; y < sourceImage.Height; y++)
            {
                int imageOffset = sourceImage.GetBufferOffsetY(y);

                for (int x = 0; x < sourceImage.Width; x++)
                {
                    int imageBufferOffsetWithX = imageOffset + x * 4;
                    var b = sourceBuffer[imageBufferOffsetWithX + 0];
                    var g = sourceBuffer[imageBufferOffsetWithX + 1];
                    var r = sourceBuffer[imageBufferOffsetWithX + 2];
                    destBuffer[imageBufferOffsetWithX + 0] = b;
                    destBuffer[imageBufferOffsetWithX + 1] = g;
                    destBuffer[imageBufferOffsetWithX + 2] = r;
                    destBuffer[imageBufferOffsetWithX + 3] = GetAlphaFromHue(r, g, b, RangeStart, RangeEnd);
                }
                //}
            });

            alphaImage.MarkImageChanged();

            displayImage.CopyFrom(alphaImage);
        }
Example #4
0
        public void LoadImage(string path, ImageBuffer destImage)
        {
            ImageBuffer cachedImage = null;

            if (!cachedImages.TryGetValue(path, out cachedImage))
            {
                using (var imageStream = OpenSteam(path))
                {
                    var bitmap = new Bitmap(imageStream);
                    cachedImage = new ImageBuffer();
                    ImageIOWindowsPlugin.ConvertBitmapToImage(cachedImage, bitmap);
                }
                if (cachedImage.Width < 200 && cachedImage.Height < 200)
                {
                    // only cache relatively small images
                    cachedImages.Add(path, cachedImage);
                }
            }

            destImage.CopyFrom(cachedImage);
        }