From 3ad9da7d8df2393000e6f78d12bf037a412f2ab8 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sun, 8 Oct 2023 19:24:29 +0200 Subject: [PATCH] More crop for VobSub --- src/libse/Common/NikseBitmap.cs | 27 +++++++++++++++++++++++++++ src/ui/Forms/Ocr/VobSubOcr.cs | 2 ++ 2 files changed, 29 insertions(+) diff --git a/src/libse/Common/NikseBitmap.cs b/src/libse/Common/NikseBitmap.cs index 207f89917..db6c8ad90 100644 --- a/src/libse/Common/NikseBitmap.cs +++ b/src/libse/Common/NikseBitmap.cs @@ -914,6 +914,20 @@ namespace Nikse.SubtitleEdit.Core.Common return Height - y; } + public int CalcBottomTransparent() + { + var y = Height - 1; + for (; y > 0; y--) + { + if (!IsHorizontalLineTransparent(y)) + { + break; + } + } + + return Height - y; + } + public int CalcLeftCropping(Color color) { var x = 0; @@ -968,6 +982,19 @@ namespace Nikse.SubtitleEdit.Core.Common return true; } + public bool IsHorizontalLineTransparent(int y) + { + for (var x = 0; x < Width; x++) + { + if (GetAlpha(x, y) > 1) + { + return false; + } + } + + return true; + } + public void Fill(Color color) { var buffer = new byte[4]; diff --git a/src/ui/Forms/Ocr/VobSubOcr.cs b/src/ui/Forms/Ocr/VobSubOcr.cs index ff3031e2a..9f98cc34a 100644 --- a/src/ui/Forms/Ocr/VobSubOcr.cs +++ b/src/ui/Forms/Ocr/VobSubOcr.cs @@ -2330,9 +2330,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr var nbmp = new NikseBitmap(bmp); var topCropped = nbmp.CropTopTransparent(0); top += topCropped; + var bottomCropped = nbmp.CalcBottomTransparent(); width = bmp.Width; height = bmp.Height; height -= topCropped; + height -= bottomCropped; bmp.Dispose(); return; }