From 939a7ef1fb9d7179737c89e67d8cfbc32d607431 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 6 May 2016 09:28:48 +0530 Subject: [PATCH] Expose gaussian_sharpen() --- src/calibre/utils/imageops/imageops.cpp | 2 +- src/calibre/utils/imageops/imageops.h | 1 + src/calibre/utils/imageops/imageops.sip | 7 +++++++ src/calibre/utils/img.py | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/imageops/imageops.cpp b/src/calibre/utils/imageops/imageops.cpp index 8b715e5cea..e5e6b4dd92 100644 --- a/src/calibre/utils/imageops/imageops.cpp +++ b/src/calibre/utils/imageops/imageops.cpp @@ -266,7 +266,7 @@ int default_convolve_matrix_size(const float radius, const float sigma, const bo // }}} -QImage gaussian_sharpen(const QImage &img, const float radius, const float sigma, const bool high_quality=true) { +QImage gaussian_sharpen(const QImage &img, const float radius, const float sigma, const bool high_quality) { int matrix_size = default_convolve_matrix_size(radius, sigma, high_quality); int len = matrix_size*matrix_size; float alpha, *matrix = new float[len]; diff --git a/src/calibre/utils/imageops/imageops.h b/src/calibre/utils/imageops/imageops.h index 7b266e826b..79c5c38250 100644 --- a/src/calibre/utils/imageops/imageops.h +++ b/src/calibre/utils/imageops/imageops.h @@ -12,4 +12,5 @@ QImage remove_borders(const QImage &image, double fuzz); QImage grayscale(const QImage &image); +QImage gaussian_sharpen(const QImage &img, const float radius, const float sigma, const bool high_quality=true); diff --git a/src/calibre/utils/imageops/imageops.sip b/src/calibre/utils/imageops/imageops.sip index af2e8fe5d1..25024e7cd7 100644 --- a/src/calibre/utils/imageops/imageops.sip +++ b/src/calibre/utils/imageops/imageops.sip @@ -31,3 +31,10 @@ QImage* grayscale(const QImage &image); ans = grayscale(*a0); IMAGEOPS_SUFFIX %End + +QImage gaussian_sharpen(const QImage &img, const float radius, const float sigma, const bool high_quality=true); +%MethodCode + IMAGEOPS_PREFIX + ans = gaussian_sharpen(*a0, a1, a2, a3); + IMAGEOPS_SUFFIX +%End diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index 64b478254f..cd2f123ad4 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -217,6 +217,11 @@ def remove_borders(img, fuzz=None): ans = imageops.remove_borders(image_from_data(img), max(0, fuzz)) return ans if ans.size() != img.size() else img +def gaussian_sharpen(img, radius=0, sigma=3, high_quality=True): + if imageops is None: + raise RuntimeError(imageops_err) + return imageops.gaussian_sharpen(image_from_data(img), max(0, radius), sigma, high_quality) + def run_optimizer(file_path, cmd, as_filter=False, input_data=None): file_path = os.path.abspath(file_path) cwd = os.path.dirname(file_path)