Optimization of the WPF C# peak algorim



  • Hello, there's a way to get a set of brightness from BitmapSource to further analyse:

    public const float CoeffColor = ((float)100 / 255 * 3) / 10000;
    //...
    arrayPixelsImage = new byte[SizeArrayPixels];
    source.CopyPixels(arrayPixelsImage, StriteImage, 0); //typeof(source) == BitmapSource
    float[,] massBrightness = new float[WidthImage, HeightImage];
    Parallel.For(0, WidthImage, x =>
    {
        for (int y = 0; y < HeightImage; y++)
        {
            int indx = y * WidthImage * 4 + 4 * x;
            float brightness = (float)(arrayPixelsImage[indx] + arrayPixelsImage[indx + 1] + arrayPixelsImage[indx + 2]) * CoeffColor;
            massBrightness[x, y] = brightness;
        }
    });
    return massBrightness;
    

    Interests how it can be optimized in terms of time of implementation?



  • writeableBitmap.Lock();
    /* 
    в отдельных потоках выполняете обработку.
    дожидаетесь завершения потоков.
    */
    writeableBitmap.AddDirtyRect(...);
    writeableBitmap.Unlock();
    

    also look at the implementation of the methods of the project https://github.com/Microsoft/Win2D




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2