await QueuedTask.Run(() =>
{
// Read pixel values from the raster dataset into the pixel block starting from the given top left corner.
raster.Read(0, 0, currentPixelBlock);
// For each plane (band) in the pixel block
for (int plane = 0; plane < currentPixelBlock.GetPlaneCount(); plane++)
{
// Get a copy of the array of pixels from the pixel block corresponding to the current plane.
Array sourcePixels = currentPixelBlock.GetPixelData(plane, true);
// Get the height and width of the pixel block.
int pBHeight = currentPixelBlock.GetHeight();
int pBWidth = currentPixelBlock.GetWidth();
// Iterate through the pixels in the array.
for (int i = 0; i < pBHeight; i++)
{
for (int j = 0; j < pBWidth; j++)
{
// Get the NoData mask value to see if the pixel is a valid pixel.
if (Convert.ToByte(currentPixelBlock.GetNoDataMaskValue(plane, j, i)) == 1)
{
// Get the pixel value from the array and process it (add 5 to the value).
// Note: This is assuming the pixel type is Unisigned 8bit.
int pixelValue = Convert.ToInt16(sourcePixels.GetValue(j, i)) + 5;
// Make sure the pixel value does not go above the range of the pixel type.
pixelValue = pixelValue > 254 ? 254 : pixelValue;
// Set the new pixel value to the array.
// Note: This is assuming the pixel type is Unisigned 8bit.
sourcePixels.SetValue(Convert.ToByte(pixelValue), j, i);
}
}
}
// Set the modified array of pixels back to the pixel block.
currentPixelBlock.SetPixelData(plane, sourcePixels);
}
// Write the pixel block to the raster dataset starting from the given top left corner.
raster.Write(0, 0, currentPixelBlock);
});