Skip to content

Commit

Permalink
random crash due to thumbnail will no longer occur.
Browse files Browse the repository at this point in the history
It could have the effect of a thumbnail having a big red X, which would require a refresh. Added back parallel For
  • Loading branch information
maforget committed Mar 7, 2024
1 parent c838098 commit 1a25c1b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cYo.Common/Drawing/ImageProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,8 @@ public static void EdgeDetectQuick(this Bitmap bitmap)
bitmap.EdgeDetectQuick(Rectangle.Empty);
}

public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeight, PixelFormat format, ResizeFastInterpolation method)
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeight, PixelFormat format, ResizeFastInterpolation method)
{
Bitmap bitmap = source;

Expand Down Expand Up @@ -956,7 +957,7 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
{
case ResizeFastInterpolation.NearestNeighbor:
// for each line
for (int y = 0; y < newHeight; y++)
Parallel.For(0, newHeight, (int y) =>
{
//Ref: https://github.com/andrewkirillov/AForge.NET/blob/master/Sources/Imaging/Filters/Transform/ResizeNearestNeighbor.cs#L81
byte* dst = orgdst + dstStride * y;
Expand All @@ -973,7 +974,7 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
}
dst += dstExtra;
}
};
});
break;
case ResizeFastInterpolation.Bilinear:
{
Expand All @@ -983,7 +984,7 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
int xmax = width - 1;

// for each line
for (int y = 0; y < newHeight; y++)
Parallel.For(0, newHeight, (int y) =>
{
byte* dst = orgdst + y * dstStride;
Expand Down Expand Up @@ -1014,6 +1015,7 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
byte* p3 = tp2 + ox1 * srcPixelSize;
byte* p4 = tp2 + ox2 * srcPixelSize;
// interpolate using 4 points
for (int i = 0; i < minPixelSize; i++, dst++, p1++, p2++, p3++, p4++)
{
*dst = (byte)(
Expand All @@ -1022,7 +1024,7 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
}
dst += dstExtra;
}
};
});
break;
}
case ResizeFastInterpolation.Bicubic:
Expand All @@ -1032,7 +1034,7 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
int ymax = height - 1;
int xmax = width - 1;

for (int y = 0; y < newHeight; y++)
Parallel.For(0, newHeight, (int y) =>
{
byte* dst = orgdst + y * dstStride;
Expand Down Expand Up @@ -1092,13 +1094,13 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
}
dst += dstPixelSize;
}
};
});
break;
}
}
return dstImage;
}
catch
catch (AccessViolationException)
{
return null;
}
Expand Down

0 comments on commit 1a25c1b

Please sign in to comment.