コード例 #1
0
ファイル: ImageProcessing.cs プロジェクト: BenGab/Imageeditor
        public List <Task> AdjustImage <T>(ILockBitmap bitmap, IMaybe <T> value, Action <ILockBitmap, int, int, IMaybe <T> > converterFunction)
        {
            int         tilewidth  = bitmap.Width / 4;
            int         tileheight = bitmap.Height / 2;
            List <Task> threads    = new List <Task>();

            for (int i = 0; i < 4; i++)
            {
                int endwidth = (i + 1) * tilewidth;
                for (int j = 0; j < 2; j++)
                {
                    int  currentwidth  = i;
                    int  currentheight = j;
                    int  endheight     = (currentheight + 1) * tileheight;
                    Task task          = Task.Factory.StartNew(() =>
                    {
                        var obj = new BitmapTileData <T>(currentwidth * tilewidth, currentheight * tileheight, endwidth, endheight, bitmap, value, converterFunction);
                        AdjustFunction(obj);
                    });
                    threads.Add(task);
                }
            }

            return(threads);
        }
コード例 #2
0
ファイル: AdjustProvider.cs プロジェクト: BenGab/Imageeditor
        private void ConverToGray(ILockBitmap bitmap, int i, int j, IMaybe <object> value)
        {
            Color colorPixel = bitmap.GetPixel(i, j);
            int   grayScale  = (int)((colorPixel.R * 0.3) + (colorPixel.G * 0.59) + (colorPixel.B * 0.11));

            bitmap.SetPixel(i, j, Color.FromArgb(grayScale, grayScale, grayScale));
        }
コード例 #3
0
ファイル: AdjustProvider.cs プロジェクト: BenGab/Imageeditor
        private void AdjustContrast(ILockBitmap bitmap, int i, int j, IMaybe <double> contrast)
        {
            //if (contrast < -100) contrast = -100;
            //if (contrast > 100) contrast = 100;
            //contrast = (100.0 + contrast) / 100.0;
            //contrast *= contrast;
            Color c;

            c = bitmap.GetPixel(i, j);
            double pR = c.R / 255.0;

            pR -= 0.5;
            pR *= contrast.Value;
            pR += 0.5;
            pR *= 255;
            if (pR < 0)
            {
                pR = 0;
            }
            if (pR > 255)
            {
                pR = 255;
            }

            double pG = c.G / 255.0;

            pG -= 0.5;
            pG *= contrast.Value;
            pG += 0.5;
            pG *= 255;
            if (pG < 0)
            {
                pG = 0;
            }
            if (pG > 255)
            {
                pG = 255;
            }

            double pB = c.B / 255.0;

            pB -= 0.5;
            pB *= contrast.Value;
            pB += 0.5;
            pB *= 255;
            if (pB < 0)
            {
                pB = 0;
            }
            if (pB > 255)
            {
                pB = 255;
            }

            bitmap.SetPixel(i, j, Color.FromArgb((byte)pR, (byte)pG, (byte)pB));
        }
コード例 #4
0
ファイル: BitmapTileData.cs プロジェクト: BenGab/Imageeditor
 public BitmapTileData(int startwidth, int startHeight, int endwidth, int endheight, ILockBitmap bmp, IMaybe <T> value, Action <ILockBitmap, int, int, IMaybe <T> > converterFunction)
 {
     Startwidht  = startwidth;
     Startheight = startHeight;
     Endwidht    = endwidth;
     Endheight   = endheight;
     Bitmap      = bmp;
     Value       = value;
     Fn          = converterFunction;
 }
コード例 #5
0
ファイル: AdjustProvider.cs プロジェクト: BenGab/Imageeditor
        private void AdjustBrightness(ILockBitmap bitmap, int i, int j, IMaybe <int> brightness)
        {
            Color c;

            c = bitmap.GetPixel(i, j);
            int cR = c.R + brightness.Value;
            int cG = c.G + brightness.Value;
            int cB = c.B + brightness.Value;

            if (cR < 0)
            {
                cR = 1;
            }
            if (cR > 255)
            {
                cR = 255;
            }

            if (cG < 0)
            {
                cG = 1;
            }
            if (cG > 255)
            {
                cG = 255;
            }

            if (cB < 0)
            {
                cB = 1;
            }
            if (cB > 255)
            {
                cB = 255;
            }

            bitmap.SetPixel(i, j,
                            Color.FromArgb((byte)cR, (byte)cG, (byte)cB));
        }
コード例 #6
0
ファイル: AdjustProvider.cs プロジェクト: BenGab/Imageeditor
        public void ConvertToNegative(ILockBitmap bitmap, int i, int j, IMaybe <object> value)
        {
            Color colorPixel = bitmap.GetPixel(i, j);

            bitmap.SetPixel(i, j, Color.FromArgb(255 - colorPixel.R, 255 - colorPixel.G, 255 - colorPixel.G));
        }