コード例 #1
0
        protected override void DemosaickingAdams(ImageComponent <ushort> image, ColorFilterArray cfa)
        {
            SuperSimple(image, cfa);
            // Interpolate the green channel by bilinear on the boundaries
            // make the average of four neighbouring green pixels: Nourth, South, East, West

            /* Parallel.For(0, image.dim.Height, row =>
             * {
             *   var cfapos = (row % 2) * 2;
             *   var posRow = row * image.dim.Width;
             *
             *   long gn = 1, gs;
             *   if (row > 0) gn = row - 1;
             *   if (row < image.dim.Height - 1) gs = row + 1; else gs = image.dim.Height - 2;
             *   gs *= image.dim.Width;
             *   gn *= image.dim.Width;
             *
             *   for (long col = 0; col < image.dim.Width; col++)
             *   {
             *       var pos = posRow + col;
             *       var color = mask[pos] = cfa.cfa[cfapos + (col % 2)];
             *       long gw = 1, ge;
             *       if (col < image.dim.Width - 1) ge = col + 1; else ge = image.dim.Width - 2;
             *       if (col > 0) gw = col - 1;
             *
             *       if ((color != CFAColor.Green))
             *       {
             *           //interpolate green
             *           image.green[pos] = (ushort)((image.green[gn + col] + image.green[gs + col] + image.green[posRow + gw] + image.green[posRow + ge]) / 4);
             *       }
             *   }
             * });*/
        }
コード例 #2
0
ファイル: HistogramHelper.Cs プロジェクト: xvanneste/Raw2Jpeg
        internal static void HistogramEqualisation(ImageComponent <int> image, HistoRaw histogram)
        {
            //TODO change and correct

            //apply histogram equalisation if needed using the histogram
            //create a lookup table
            var    lut        = new int[uint.MaxValue];
            double pixelCount = image.dim.height * image.dim.width;

            int sum = 0;

            // build a LUT containing scale factor
            for (int i = 0; i < lut.Length; ++i)
            {
                sum   += histogram.luma[i];
                lut[i] = (int)(sum * 255 / pixelCount);
            }
            // transform image using sum histogram as a LUT
            Parallel.For(0, image.dim.height, y =>
            {
                long realY = y * image.dim.width;
                for (int x = 0; x < image.dim.width; x++)
                {
                    long realX         = realY + x;
                    image.red[realX]   = lut[image.red[realX]];
                    image.green[realX] = lut[image.green[realX]];
                    image.blue[realX]  = lut[image.blue[realX]];
                }
            });
        }
コード例 #3
0
ファイル: ImageEffect.cs プロジェクト: xvanneste/Raw2Jpeg
        protected void SinglePixelProcessing(ImageComponent <ushort> image, ImageComponent <int> buffer, double[] curve)
        {
            Debug.Assert(image.red != null);
            Debug.Assert(image.blue != null);
            Debug.Assert(image.green != null);
            Debug.Assert(image.dim.Area >= 4);

            Debug.Assert(buffer.red != null);
            Debug.Assert(buffer.blue != null);
            Debug.Assert(buffer.green != null);
            Debug.Assert(buffer.dim.Area == image.dim.Area);

            Parallel.For(0, image.dim.height, y =>
            {
                long realY = (y + image.offset.height) * image.UncroppedDim.width;
                for (int x = 0; x < image.dim.width; x++)
                {
                    long realPix = realY + x + image.offset.width;
                    double red   = image.red[realPix] * rMul, green = image.green[realPix] * gMul, blue = image.blue[realPix] * bMul;
                    Luminance.Clip(ref red, ref green, ref blue, maxValue);
                    ColorManipulation.RgbToHsl(red, green, blue, maxValue, out double h, out double s, out double l);
                    l  = curve[(int)(l * maxValue)];
                    s *= saturation;

                    ColorManipulation.HslToRgb(h, s, l, maxValue, out red, out green, out blue);

                    long bufferPix          = Rotate(x, y, image.dim.width, image.dim.height);
                    buffer.red[bufferPix]   = (int)red;
                    buffer.green[bufferPix] = (int)green;
                    buffer.blue[bufferPix]  = (int)blue;
                }
コード例 #4
0
ファイル: ImageControlFactory.cs プロジェクト: Tauron1990/Fun
        private object CreateView(ImageComponent imageComponent)
        {
            var mem = new MemoryStream(File.ReadAllBytes(imageComponent.FilePath));

            try
            {
                var source = BitmapFrame.Create(mem);


                if (imageComponent.FilePath.EndsWith(".gif"))
                {
                    var gifImg = _gifControl.Value;
                    GifAnimationBehavior.SetAnimatedSource(gifImg, source);
                    return(gifImg);
                }

                var img = _imageControl.Value;
                img.Source = source;

                return(img);
            }
            catch (Exception)
            {
                // ignored
            }

            mem.Position = 0;
            var video = _video.Value;

            video.SourceProvider.MediaPlayer !.Play(mem);

            return(video);
        }
コード例 #5
0
ファイル: HistogramHelper.Cs プロジェクト: xvanneste/Raw2Jpeg
        internal static HistoRaw CalculateHistogram(ImageComponent <int> image)
        {
            var      maxValue  = 1 << image.ColorDepth;
            HistoRaw histogram = new HistoRaw()
            {
                luma  = new int[maxValue],
                red   = new int[maxValue],
                blue  = new int[maxValue],
                green = new int[maxValue]
            };

            for (int y = 0; y < image.dim.height; y++)
            {
                long realY = (y + image.offset.height) * image.UncroppedDim.width;
                for (int x = 0; x < image.dim.width; x++)
                {
                    long realPix = realY + x + image.offset.width;
                    histogram.luma[(int)(0.299 * image.red[realPix] + 0.587 * image.green[realPix] + 0.114 * image.blue[realPix])]++;
                    histogram.red[image.red[realPix]]++;
                    histogram.green[image.green[realPix]]++;
                    histogram.blue[image.blue[realPix]]++;
                }
            }
            return(histogram);
        }
コード例 #6
0
ファイル: SSDDemosaic.cs プロジェクト: xvanneste/Raw2Jpeg
        /**
         * \brief  Iterate median filter on chromatic components of the image
         *
         *
         * @param[in]  ired, igreen, iblue  initial  image
         * @param[in]  iter  number of iteracions
         * @param[out] ored, ogreen, oblue  filtered output
         * @param[in]  (redx, redy)  coordinates of the red pixel: (0,0), (0,1), (1,0), (1,1)
         * @param[in]  side  median in a (2*side+1) x (2*side+1) window
         * @param[in]  projflag if not zero, values of the original CFA are kept
         * @param[in]  width, height size of the image
         *
         */
        static void ChromaticMedian(int iter, int redx, int redy, double side, ImageComponent <ushort> image)
        {
            uint size = image.dim.height * image.dim.width;

            // Auxiliary variables for computing chromatic components
            float[] y  = new float[size];
            float[] u  = new float[size];
            float[] v  = new float[size];
            float[] u0 = new float[size];
            float[] v0 = new float[size];

            int bluex = 1 - redx;
            int bluey = 1 - redy;

            // For each iteration
            for (int i = 1; i <= iter; i++)
            {
                // Transform to YUV
                // wxRgb2Yuv(image, iblue, y, u, v);

                // Perform a Median on YUV component
                //wxMedian(u, u0, side, 1, image.dim.Width, image.dim.Height);
                //wxMedian(v, v0, side, 1, image.dim.Width, image.dim.Height);

                // Transform back to RGB
                //wxYuv2Rgb(image, y, u0, v0);*/
            }
        }
コード例 #7
0
ファイル: AutoExposure.cs プロジェクト: xvanneste/Raw2Jpeg
        public static ImageEffect Get(ImageComponent <ushort> preview, PointCollection histo)
        {
            //find the exposure shift needed
            //caclute the mean
            double mean = 0, count = 0;

            for (int i = 0; i < histo.Count; i++)
            {
                mean  += histo[i].Y * i;
                count += histo[i].Y;
            }
            mean /= count;
            var shift = 78 - mean;
            var sign  = Math.Sign(shift);

            //get the shift until the mean

            //find the shadow shift

            //find the higlight shift

            //find the contrast
            return(new ImageEffect()
            {
                Exposure = Math.Log(Math.Abs(shift) / 8, 2) * sign
            });
        }
コード例 #8
0
ファイル: ActionScene.cs プロジェクト: jdindia/MonoGame
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="game">The main game object</param>
        /// <param name="theTexture">Texture with the sprite elements</param>
        /// <param name="backgroundTexture">Texture for the background</param>
        /// <param name="font">Font used in the score</param>
        public ActionScene(Game game, Texture2D theTexture,
                           Texture2D backgroundTexture, SpriteFont font, ExplosionManager explosions)
            : base(game)
        {
            // Get the current audiocomponent and play the background music
            audio = (AudioLibrary)Game.Services.GetService(typeof(AudioLibrary));

            background = new ImageComponent(game, backgroundTexture,
                                            ImageComponent.DrawMode.Stretch);
            Components.Add(background);

            actionTexture = theTexture;

            spriteBatch = (SpriteBatch)
                          Game.Services.GetService(typeof(SpriteBatch));
            meteors = new MeteorsManager(Game, ref actionTexture);
            Components.Add(meteors);

            player = new Player(Game, ref actionTexture);
            player.Initialize();
            Components.Add(player);

            score          = new Score(game, font, Color.LightGray);
            score.Position = new Vector2(1, 1);
            Components.Add(score);

            powerSource = new PowerSource(game, ref actionTexture);
            powerSource.Initialize();
            Components.Add(powerSource);

            _explosions = explosions;
        }
コード例 #9
0
ファイル: SearchQuery.cs プロジェクト: Tauron1990/Fun
        public bool FilterAction(ImageComponent component)
        {
            if (string.IsNullOrWhiteSpace(Term) || IsInvalid)
            {
                return(false);
            }

            if (Favorite)
            {
                if (!component.IsFavorite.Value)
                {
                    return(false);
                }
            }

            if (ExcludedTags.Count != 0)
            {
                if (ExcludedTags.Any(t => component.MetaData.Tags.Contains(t)))
                {
                    return(false);
                }
            }

            if (Tags.Count != 0)
            {
                if (!Tags.Any(t => component.MetaData.Tags.Contains(t)))
                {
                    return(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(SearchName))
            {
                if (!component.Name.Contains(SearchName))
                {
                    return(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(User.Value))
            {
                if (!component.MetaData.User.Contains(User.Value))
                {
                    return(false);
                }
            }

            if (CompareInt(component.MetaData.Rating, Rating) && CompareInt(component.MetaData.Height, Height) &&
                CompareInt(component.MetaData.Width, Width) && CompareInt(component.MetaData.Mpixels, Mpixels))
            {
                return(Date.Expression switch
                {
                    Expression.None => true,
                    Expression.Larger => (component.MetaData.CreationTime > Date.Value),
                    Expression.Smaller => (component.MetaData.CreationTime < Date.Value),
                    Expression.Equal => (component.MetaData.CreationTime == Date.Value),
                    Expression.Between => (component.MetaData.CreationTime >= Date.Value && component.MetaData.CreationTime <= Date.Next),
                    _ => throw new ArgumentOutOfRangeException()
                });
コード例 #10
0
        /// <summary>
        /// Called whenever properties affecting the image are changed.
        /// </summary>
        public virtual void ImageChanged()
        {
            if (IgnoreObject)
            {
                return;
            }

            if (ImageComponent == null)
            {
                // add image component if background color is defined
                if (BackgroundColorProperty.IsUndefined(this, true))
                {
                    return;
                }

                ImageComponent = GameObject.AddComponent <UnityEngine.UI.Image>();
            }

            if (BackgroundColorProperty.IsUndefined(this))
            {
                if (ImageComponent.sprite != null || ImageComponent.overrideSprite != null)
                {
                    // use white color by default if image is set
                    ImageComponent.color = Color.white;
                }
                else
                {
                    // use clear color by default if image isn't set
                    ImageComponent.color = Color.clear;
                }
            }

            var sprite = ImageComponent.overrideSprite ?? ImageComponent.sprite;

            if (Width == null && Height == null)
            {
                // if width and height is undefined, adjust size to native size of sprite
                if (sprite != null)
                {
                    ImageComponent.SetNativeSize();
                    OverrideWidth  = ElementSize.FromPixels(ImageComponent.rectTransform.sizeDelta.x);
                    OverrideHeight = ElementSize.FromPixels(ImageComponent.rectTransform.sizeDelta.y);
                }
            }

            bool isLoading = BackgroundSprite != null && !BackgroundSprite.IsLoaded;

            if (isLoading && sprite == null)
            {
                // always disable image while loading if current sprite isn't set
                ImageComponent.enabled = false;
            }
            else
            {
                // disable raycast blocks if image is transparent
                ImageComponent.enabled = RaycastBlockMode == RaycastBlockMode.Always ? true : ImageComponent.color.a > 0;
            }
        }
コード例 #11
0
        public Crate()
        {
            // Add image component
            ImageComponent = AddComponent(new ImageComponent(GetAsset <Image>("tile.crate")));

            // Add physics and collider components
            Collider = AddComponent(new Collider(ImageComponent.Image.Bounds));
            Physics  = AddComponent(new PhysicsComponent());
        }
コード例 #12
0
ファイル: Image.cs プロジェクト: bradparks/Delight
        /// <summary>
        /// Called whenever properties affecting the image are changed.
        /// </summary>
        public virtual void ImageChanged()
        {
            if (ImageComponent == null)
            {
                return;
            }

            if (ColorProperty.IsUndefined(this))
            {
                if (ImageComponent.sprite != null || ImageComponent.overrideSprite != null)
                {
                    // use white color by default if image is set
                    ImageComponent.color = Color.white;
                }
                else
                {
                    // use clear color by default if image isn't set
                    ImageComponent.color = Color.clear;
                }
            }

            var sprite = ImageComponent.overrideSprite ?? ImageComponent.sprite;

            if (WidthProperty.IsUndefined(this) && HeightProperty.IsUndefined(this))
            {
                // if width and height is undefined, adjust size to native size of sprite
                if (sprite != null)
                {
                    ImageComponent.SetNativeSize();
                    OverrideWidth  = ElementSize.FromPixels(ImageComponent.rectTransform.sizeDelta.x);
                    OverrideHeight = ElementSize.FromPixels(ImageComponent.rectTransform.sizeDelta.y);
                    if (OverrideHeight.Pixels != 0)
                    {
                        _nativeAspectRatio = OverrideWidth.Pixels / OverrideHeight.Pixels;
                    }
                }
            }
            else
            {
                _nativeAspectRatio = -1;
            }

            bool isLoading = Sprite != null && !Sprite.IsLoaded;

            if (isLoading && sprite == null)
            {
                // always disable image while loading
                ImageComponent.enabled = false;
            }
            else
            {
                // disable raycast blocks if image is transparent
                ImageComponent.enabled = RaycastBlockMode == RaycastBlockMode.Always ? true : ImageComponent.color.a > 0;
            }
        }
コード例 #13
0
ファイル: ImageEffect.cs プロジェクト: xvanneste/Raw2Jpeg
        protected ImageComponent <int> Apply(ImageComponent <ushort> image)
        {
            Debug.Assert(image.red != null);
            Debug.Assert(image.blue != null);
            Debug.Assert(image.green != null);
            Debug.Assert(image.dim.Area >= 4);

            //calculate the max value for clip
            maxValue = (uint)(1 << image.ColorDepth) - 1;
            HistoRaw histo;

            //TODO cut the image in patch to reduce memory

            var buffer = new ImageComponent <int>(image.dim, image.ColorDepth);

            //apply the single pixel processing
            SinglePixelProcessing(image, buffer, CreateCurve());

            ColorManipulation.SplitTone(buffer, new Pixel(SplitShadow), new Pixel(SplitHighlight), SplitBalance, maxValue);

            if (Rotation == 1 || Rotation == 3)
            {
                buffer.dim.Flip();
                buffer.UncroppedDim.Flip();
            }

            //clip
            Luminance.Clip(buffer);

            //apply histogram equalisation if any
            if (histogramEqual)
            {
                //calculate the histogram
                histo = HistogramHelper.CalculateLumaHistogram(buffer);
                HistogramHelper.HistogramEqualisation(buffer, histo);
            }

            //apply denoising
            if (denoise != 0)
            {
                buffer = Denoising.Apply(buffer, (int)denoise);
            }

            //apply sharpening (always last step)
            if (sharpness != 0)
            {
                buffer = Sharpening.Apply(buffer, (int)sharpness);
            }

            //return the final histogram
            return(buffer);
        }
コード例 #14
0
        public ArticleComponent GetComponentFor(Context context, dynamic componentSegment)
        {
            string type = componentSegment.type;

            switch (type)
            {
            case "text": return(ArticleTextView.Create(Inflater, componentSegment));

            case "image": return(ImageComponent.Create(Inflater));

            case "byline": return(BylineComponent.Create(Inflater));

            default: return(new BlankComponent(context));
            }
        }
コード例 #15
0
 public ImageActor(ulong id, string path = "") : base(id)
 {//path需要是绝对路径
     InitializeComponent();
     Name = "Image-" + id;
     _cmp = new ImageComponent(this);
     AddComponent(_cmp);
     if (string.IsNullOrEmpty(path))
     {
         path = string.Format("{0}{1}", PathDefine.PackBase, "Resources/Textures/17zuoye.png");
     }
     Pic = new Image()
     {
         Source = new BitmapImage(new Uri(string.Format("{0}", path)))
     };
 }
コード例 #16
0
ファイル: Luminance.cs プロジェクト: xvanneste/Raw2Jpeg
        internal static void Clip(ImageComponent <int> image, ushort colorDepth)
        {
            var maxValue = (1 << colorDepth) - 1;
            var shift    = image.ColorDepth - colorDepth;

            image.ColorDepth = colorDepth;
            Parallel.For(0, image.dim.height, y =>
            {
                long realY = y * image.dim.width;
                for (int x = 0; x < image.dim.width; x++)
                {
                    long realPix = realY + x;
                    var red      = image.red[realPix] >> shift;
                    var green    = image.green[realPix] >> shift;
                    var blue     = image.blue[realPix] >> shift;
                    if (red < 0)
                    {
                        red = 0;
                    }
                    else if (red > maxValue)
                    {
                        red = maxValue;
                    }

                    if (green < 0)
                    {
                        green = 0;
                    }
                    else if (green > maxValue)
                    {
                        green = maxValue;
                    }

                    if (blue < 0)
                    {
                        blue = 0;
                    }
                    else if (blue > maxValue)
                    {
                        blue = maxValue;
                    }

                    image.red[realPix]   = red;
                    image.green[realPix] = green;
                    image.blue[realPix]  = blue;
                }
            });
        }
コード例 #17
0
 public virtual void SetImageSprite(Sprite sprite)
 {
     m_AspectRatioFitterComponent.aspectMode = AspectRatioFitter.AspectMode.None;
     ImageComponent.sprite = null;
     if (sprite != null)
     {
         ImageComponent.sprite         = sprite;
         ImageComponent.preserveAspect = true;
         ImageComponent.SetNativeSize();
         CalculateAspectRatio();
     }
     else
     {
         m_AspectRatioFitterComponent.aspectRatio = 1;
     }
 }
コード例 #18
0
ファイル: ImageEffect.cs プロジェクト: xvanneste/Raw2Jpeg
        public unsafe HistoRaw ApplyTo16Bits(ImageComponent <ushort> image, SoftwareBitmap bitmap, bool histogram)
        {
            Debug.Assert(bitmap.BitmapPixelFormat == BitmapPixelFormat.Rgba16);

            var buffer = Apply(image);
            //Clip the image
            //Luminance.Clip(buffer, 16);

            HistoRaw histo = null;

            //calculate the new histogram (create a 8 bits histogram)
            if (histogram)
            {
                histo = HistogramHelper.CalculateHistogram(buffer);
            }

            //copy the buffer to the image with clipping
            //calculte the shift between colordepth input and output
            int shift = image.ColorDepth - 16;

            using (BitmapBuffer buff = bitmap.LockBuffer(BitmapBufferAccessMode.Write))
                using (var reference = buff.CreateReference())
                {
                    ((IMemoryBufferByteAccess)reference).GetBuffer(out var temp, out uint capacity);
                    Parallel.For(0, buffer.dim.height, y =>
                    {
                        long realY = y * buffer.dim.width;
                        for (int x = 0; x < buffer.dim.width; x++)
                        {
                            long realPix        = realY + x;
                            long bufferPix      = realPix * 8;
                            temp[bufferPix]     = (byte)(buffer.red[realPix] >> 8);
                            temp[bufferPix + 1] = (byte)(buffer.red[realPix]);

                            temp[bufferPix + 2] = (byte)(buffer.green[realPix] >> 8);
                            temp[bufferPix + 3] = (byte)(buffer.green[realPix]);

                            temp[bufferPix + 4] = (byte)(buffer.blue[realPix] >> 8);
                            temp[bufferPix + 5] = (byte)(buffer.blue[realPix]);

                            temp[bufferPix + 6] = 255; //set transparency to 255 else image will be blank
                            temp[bufferPix + 7] = 255; //set transparency to 255 else image will be blank
                        }
                    });
                }
            return(histo);
        }
コード例 #19
0
        protected virtual void DemosaickingAdams(ImageComponent <ushort> image, ColorFilterArray cfa)
        {
            // Interpolate the green channel by bilinear on the boundaries
            // make the average of four neighbouring green pixels: Nourth, South, East, West
            Parallel.For(0, image.dim.height, row =>
            {
                for (long col = 0; col < image.dim.width; col++)
                {
                    var color = mask[row * image.dim.width + col];


                    //take the pixel and put it around
                    if (color == CFAColor.Green)
                    {
                        Interpolate(CFAColor.Green, image.green, col, row, image.dim);
                    }
                    else if (color == CFAColor.Red)
                    {
                        Interpolate(CFAColor.Red, image.red, col, row, image.dim);
                    }
                    else
                    {
                        Interpolate(CFAColor.Blue, image.blue, col, row, image.dim);
                    }

                    /*if (!(col < 3 || row < 3 || col >= image.dim.width - 3 || row >= image.dim.height - 3))
                     * {
                     *  //skip to the end of line to reduce calculation
                     *  col = image.dim.width - 4;
                     * }
                     * else if (((mask[row * image.dim.width + col] = cfa.cfa[((row % cfa.Size.width) * cfa.Size.height) + (col % cfa.Size.height)]) != CFAColor.Green))
                     * {
                     *  long gn, gs, ge, gw;
                     *  if (row > 0) gn = row - 1; else gn = 1;
                     *  if (row < image.dim.height - 1) gs = row + 1; else gs = image.dim.height - 2;
                     *  if (col < image.dim.width - 1) ge = col + 1; else ge = image.dim.width - 2;
                     *  if (col > 0) gw = col - 1; else gw = 1;
                     *
                     *  image.green[row * image.dim.width + col] = (ushort)((
                     *      image.green[gn * image.dim.width + col] +
                     *      image.green[gs * image.dim.width + col] +
                     *      image.green[row * image.dim.width + gw] +
                     *      image.green[row * image.dim.width + ge]) / 4.0);
                     * }*/
                }
            });
        }
コード例 #20
0
        private static void UpdateImage(GameObject gameObject, Image image, ImageComponent imageComponent, IAssetLoader assetLoader)
        {
            var rectTransform = gameObject.GetComponent <RectTransform>();

            if (imageComponent.Sprite != null)
            {
                UpdateImageSprite(gameObject, image, imageComponent.Sprite, assetLoader);
            }
            if (imageComponent.Color != null)
            {
                image.color = imageComponent.Color.Value;
            }

            if (imageComponent.Direction != null)
            {
                rectTransform.localScale = new Vector3(imageComponent.Direction.Value.x, imageComponent.Direction.Value.y, 1f);
            }
        }
コード例 #21
0
ファイル: MainPage.xaml.cs プロジェクト: tsvx/RawParser
        private async void CropButton_TappedAsync(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            if (rawImage?.fullSize != null)
            {
                CropUI.SetThumbAsync(null);
                Load.Show();
                // Blur(true);
                ControlVisibilty.Value = false;
                //display the crop UI
                CropGrid.Visibility = Visibility.Visible;
                //wait for accept or reset pressed

                uint h, w;
                if (EditionValue.Rotation == 1 || EditionValue.Rotation == 3)
                {
                    h = rawImage.preview.UncroppedDim.width;
                    w = rawImage.preview.UncroppedDim.height;
                }
                else
                {
                    h = rawImage.preview.UncroppedDim.height;
                    w = rawImage.preview.UncroppedDim.width;
                }
                double factor;
                if (w > h)
                {
                    factor = ImageDisplay.ActualWidth / (w);
                }
                else
                {
                    factor = ImageDisplay.ActualHeight / (h + 160);
                }
                CropUI.SetSize((int)(w * factor * 0.7), (int)(h * factor * 0.7), EditionValue.Rotation);
                ImageComponent<ushort> img = new ImageComponent<ushort>(rawImage.preview) { offset = new Point2D(), dim = new Point2D(rawImage.preview.UncroppedDim) };
                rawImage.preview.dim = new Point2D(rawImage.preview.UncroppedDim);
                //create a preview of the image             
                SoftwareBitmap image = await Task.Run(() =>
                {
                    return ApplyImageEffect8bitsNoHistoAsync(img, EditionValue);
                });
                //display the preview
                CropUI.SetThumbAsync(image);
            }
        }
コード例 #22
0
ファイル: ImageEffect.cs プロジェクト: xvanneste/Raw2Jpeg
        public unsafe HistoRaw ApplyTo8Bits(ImageComponent <ushort> image, SoftwareBitmap bitmap, bool histogram)
        {
            Debug.Assert(image.red != null);
            Debug.Assert(image.blue != null);
            Debug.Assert(image.green != null);
            Debug.Assert(image.dim.Area >= 4);
            Debug.Assert(bitmap != null);
            Debug.Assert(image.dim.Area == bitmap.PixelHeight * bitmap.PixelWidth);

            var buffer = Apply(image);

            //Clip the image
            Luminance.Clip(buffer, 8);

            //calculate the new histogram (create a 8 bits histogram)
            HistoRaw histo = null;

            if (histogram)
            {
                histo = HistogramHelper.CalculateHistogram(buffer);
            }

            //copy the buffer to the image with clipping
            using (BitmapBuffer buff = bitmap.LockBuffer(BitmapBufferAccessMode.Write))
                using (var reference = buff.CreateReference())
                {
                    ((IMemoryBufferByteAccess)reference).GetBuffer(out var temp, out uint capacity);
                    Parallel.For(0, buffer.dim.height, y =>
                    {
                        long realY = y * buffer.dim.width;
                        for (int x = 0; x < buffer.dim.width; x++)
                        {
                            long realPix        = realY + x;
                            long bufferPix      = realPix * 4;
                            temp[bufferPix]     = (byte)(buffer.blue[realPix]);
                            temp[bufferPix + 1] = (byte)(buffer.green[realPix]);
                            temp[bufferPix + 2] = (byte)(buffer.red[realPix]);
                            temp[bufferPix + 3] = 255; //set transparency to 255 else image will be blank
                        }
                    });
                }
            return(histo);
        }
コード例 #23
0
ファイル: HistogramHelper.Cs プロジェクト: xvanneste/Raw2Jpeg
        internal static HistoRaw CalculateLumaHistogram(ImageComponent <int> image)
        {
            HistoRaw histogram = new HistoRaw()
            {
                luma = new int[(1 << image.ColorDepth)]
            };

            for (int y = 0; y < image.dim.height; y++)
            {
                long realY = (y + image.offset.height) * image.UncroppedDim.width;
                for (int x = 0; x < image.dim.width; x++)
                {
                    long realPix = realY + x + image.offset.width;

                    histogram.luma[(int)((Math.Max(Math.Max(image.red[realPix], image.green[realPix]), image.blue[realPix])
                                          + Math.Min(Math.Min(image.red[realPix], image.green[realPix]), image.blue[realPix])) / 2.0)]++;
                }
            }
            return(histogram);
        }
コード例 #24
0
 protected override void DemosaickingBilinearRedBlue(int colorX, int colorY, ImageComponent <ushort> image, ushort[] output, CFAColor COLORPOSITION)
 {
     /*Parallel.For(0, image.dim.Height, row =>
      * {
      *  var cfapos = (row % 2) * 2;
      *  var posRow = row * image.dim.Width;
      *
      *  long gn = 1, gs;
      *  if (row > 0) gn = row - 1;
      *  if (row < image.dim.Height - 1) gs = row + 1; else gs = image.dim.Height - 2;
      *  gs *= image.dim.Width;
      *  gn *= image.dim.Width;
      *
      *  for (int col = 0; col < image.dim.Width; col++)
      *  {
      *      var pos = posRow + col;
      *      var color = mask[pos];
      *      if (color != COLORPOSITION)
      *      {
      *          // Compute north, south, west, east positions
      *          // taking a mirror symmetry at the boundaries
      *          long gw = 1, ge;
      *          if (col < image.dim.Width - 1) ge = col + 1; else ge = image.dim.Width - 2;
      *          if (col > 0) gw = col - 1;
      *
      *          if (color == CFAColor.Green && row % 2 == colorY)
      *          {
      *              output[pos] = (ushort)((output[posRow + ge] + output[posRow + gw]) / 2);
      *          }
      *          else if (color == CFAColor.Green && col % 2 == colorX)
      *          {
      *              output[pos] = (ushort)((output[gn + col] + output[gs + col]) / 2);
      *          }
      *          else
      *          {
      *              output[pos] = (ushort)((output[gn + ge] + output[gn + gw] + output[gs + ge] + output[gs + gw]) / 4);
      *          }
      *      }
      *  }
      * });*/
 }
コード例 #25
0
        public HttpResponseMessage DownloadImage(string id)
        {
            if (string.IsNullOrWhiteSpace(id) || id == "null")
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }
            var bytes = new ImageComponent().DownloadWithMaster(id);

            if (bytes == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            var resp = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(bytes)
            };

            resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            return(resp);
        }
コード例 #26
0
    private static void initComponent(Children child, GameObject parentObj, string fileName = "")
    {
        var propStr = child.options.property;
        var props   = propStr.Split('\r');
        var prop    = new Property();

        prop.DeserializeProperty(props);

        GameObject tempObj  = null;
        GameObject childObj = null;

        if ((child.classname == "LABEL") && (!prop.isInput))
        {
            childObj = TextComponent.InitTextComponent(child, parentObj);
        }
        else if ((child.classname == "LABEL") && (prop.isInput))
        {
            childObj = TextFieldComponent.InitTextFieldComponent(child, parentObj);
        }
        else if (child.classname == "IMAGE")
        {
            childObj = ImageComponent.InitImageComponent(child, parentObj, fileName);
        }
        else if (child.classname == "GROUP")
        {
            childObj = RectComponent.InitRectComponent(child, parentObj);
        }
        else if (child.classname == "LIST")
        {
            childObj = ScrollComponent.InitComponent(child, parentObj);
        }

        if ((child.children.Length > 0) && (childObj != null))
        {
            for (int i = child.children.Length - 1; i >= 0; i--)
            {
                initComponent(child.children [i], childObj, fileName);
            }
        }
    }
コード例 #27
0
ファイル: Color.cs プロジェクト: xvanneste/Raw2Jpeg
        public static void SplitTone(ImageComponent <int> image, Pixel splitShadow, Pixel splitHighlight, double splitBalance, uint maxValue)
        {
            if (splitShadow.IsZero() && splitHighlight.IsZero())
            {
                return;
            }
            //scale the value
            var coeff = maxValue / (double)byte.MaxValue;

            splitShadow.R    *= coeff;
            splitShadow.G    *= coeff;
            splitShadow.B    *= coeff;
            splitHighlight.R *= coeff;
            splitHighlight.G *= coeff;
            splitHighlight.B *= coeff;


            //loop and apply
            Parallel.For(0, image.dim.height, y =>
            {
                long realY = (y + image.offset.height) * image.UncroppedDim.width;
                for (int x = 0; x < image.dim.width; x++)
                {
                    long realPix = realY + x + image.offset.width;
                    //compute luminance
                    var l       = ((image.red[realPix] + image.green[realPix] + image.blue[realPix]) / 3.0 / maxValue);
                    double invL = (1 - l) * (1 - splitBalance);
                    l          *= splitBalance;

                    image.red[realPix]   += (int)(splitShadow.R * invL);
                    image.green[realPix] += (int)(splitShadow.G * invL);
                    image.blue[realPix]  += (int)(splitShadow.B * invL);

                    image.red[realPix]   += (int)(splitHighlight.R * l);
                    image.green[realPix] += (int)(splitHighlight.G * l);
                    image.blue[realPix]  += (int)(splitHighlight.B * l);
                }
            });
        }
コード例 #28
0
        public HttpResponseMessage Download(string id)
        {
            if (string.IsNullOrWhiteSpace(id) || id == Guid.Empty.ToString())
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }

            var bytes = new ImageComponent().DownloadWithRegion(id, this.GetUser().CountryId);

            if (bytes == null || bytes.Length == 0)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }

            var resp = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(bytes)
            };

            resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            return(resp);
        }
コード例 #29
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            var response = ImageComponent.IdentifyDartMembers(_image.ImageToByteArray());

            _image = null;

            pbSave.Invoke(new MethodInvoker(
                              delegate()
            {
                pbSave.Image = response;
            }));

            pbLoading.Invoke(new MethodInvoker(
                                 delegate()
            {
                pbLoading.Visible = false;
            }));

            pbSearch.Invoke(new MethodInvoker(
                                delegate()
            {
                pbSearch.Visible = true;
            }));
        }
コード例 #30
0
        internal static ImageComponent <int> Apply(ImageComponent <int> image, int denoise)
        {
            //create a buffer
            ImageComponent <int> buffer = new ImageComponent <int>(image.dim, image.ColorDepth);
            int mul    = 11 - denoise;
            int factor = 8 + mul;

            //apply a median filtering
            Parallel.For(1, image.dim.height - 1, y =>
            {
                long realY  = y * image.dim.width;
                var beforeY = ((y - 1) * image.dim.width);
                var afterY  = ((y + 1) * image.dim.width);
                for (int x = 1; x < image.dim.width - 1; x++)
                {
                    long realX        = realY + x;
                    var beforeRow     = beforeY + x;
                    var afterRow      = afterY + x;
                    buffer.red[realX] = ((mul * image.red[realX])
                                         + image.red[realX + 1]
                                         + image.red[realX - 1]
                                         + image.red[afterRow]
                                         + image.red[afterRow + 1]
                                         + image.red[afterRow - 1]
                                         + image.red[beforeRow]
                                         + image.red[beforeRow + 1]
                                         + image.red[beforeRow - 1]) / factor;

                    buffer.green[realX] = ((mul * image.green[realX])
                                           + image.green[realX + 1]
                                           + image.green[realX - 1]
                                           + image.green[afterRow]
                                           + image.green[afterRow + 1]
                                           + image.green[afterRow - 1]
                                           + image.green[beforeRow]
                                           + image.green[beforeRow + 1]
                                           + image.green[beforeRow - 1]) / factor;

                    buffer.blue[realX] = ((mul * image.blue[realX])
                                          + image.blue[realX + 1]
                                          + image.blue[realX - 1]
                                          + image.blue[afterRow]
                                          + image.blue[afterRow + 1]
                                          + image.blue[afterRow - 1]
                                          + image.blue[beforeRow]
                                          + image.blue[beforeRow + 1]
                                          + image.blue[beforeRow - 1]) / factor;
                }
            });

            //fill in the edge
            Parallel.For(0, buffer.dim.height, y =>
            {
                var pos = y * buffer.dim.width;

                buffer.red[pos]   = image.red[pos];
                buffer.green[pos] = image.green[pos];
                buffer.blue[pos]  = image.blue[pos];

                pos              += image.dim.width - 1;
                buffer.red[pos]   = image.red[pos];
                buffer.green[pos] = image.green[pos];
                buffer.blue[pos]  = image.blue[pos];
            });

            var p = (buffer.dim.height - 1) * buffer.dim.width;

            Parallel.For(0, buffer.dim.width, x =>
            {
                buffer.red[x]   = image.red[x];
                buffer.green[x] = image.green[x];
                buffer.blue[x]  = image.blue[x];

                buffer.red[p]   = image.red[p];
                buffer.green[p] = image.green[p];
                buffer.blue[p]  = image.blue[p];
                p++;
            });

            return(buffer);
        }