mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Add an filter to make images look like oil paintings
This commit is contained in:
parent
b5bc34e0fe
commit
54ac2d394a
@ -21,7 +21,10 @@ from calibre.gui2.dnd import (
|
|||||||
IMAGE_EXTENSIONS, dnd_has_extension, dnd_has_image, dnd_get_image, DownloadDialog)
|
IMAGE_EXTENSIONS, dnd_has_extension, dnd_has_image, dnd_get_image, DownloadDialog)
|
||||||
from calibre.gui2.tweak_book import capitalize
|
from calibre.gui2.tweak_book import capitalize
|
||||||
from calibre.utils.imghdr import identify
|
from calibre.utils.imghdr import identify
|
||||||
from calibre.utils.img import remove_borders, gaussian_sharpen, gaussian_blur, image_to_data, despeckle, normalize
|
from calibre.utils.img import (
|
||||||
|
remove_borders, gaussian_sharpen, gaussian_blur, image_to_data, despeckle,
|
||||||
|
normalize, oil_paint
|
||||||
|
)
|
||||||
|
|
||||||
def painter(func):
|
def painter(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
@ -142,6 +145,17 @@ class Blur(Sharpen):
|
|||||||
def __call__(self, canvas):
|
def __call__(self, canvas):
|
||||||
return gaussian_blur(canvas.current_image, sigma=self.sigma)
|
return gaussian_blur(canvas.current_image, sigma=self.sigma)
|
||||||
|
|
||||||
|
class Oilify(Command):
|
||||||
|
|
||||||
|
TEXT = _('Make image look like an oil painting')
|
||||||
|
|
||||||
|
def __init__(self, radius, canvas):
|
||||||
|
self.radius = radius
|
||||||
|
Command.__init__(self, canvas)
|
||||||
|
|
||||||
|
def __call__(self, canvas):
|
||||||
|
return oil_paint(canvas.current_image, radius=self.radius)
|
||||||
|
|
||||||
class Despeckle(Command):
|
class Despeckle(Command):
|
||||||
|
|
||||||
TEXT = _('De-speckle image')
|
TEXT = _('De-speckle image')
|
||||||
@ -380,6 +394,11 @@ class Canvas(QWidget):
|
|||||||
self.undo_stack.push(Normalize(self))
|
self.undo_stack.push(Normalize(self))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@imageop
|
||||||
|
def oilify_image(self, radius=4.0):
|
||||||
|
self.undo_stack.push(Oilify(radius, self))
|
||||||
|
return True
|
||||||
|
|
||||||
# The selection rectangle {{{
|
# The selection rectangle {{{
|
||||||
@property
|
@property
|
||||||
def dc_size(self):
|
def dc_size(self):
|
||||||
|
@ -274,6 +274,7 @@ class Editor(QMainWindow):
|
|||||||
m.addAction(_('Blur image'), self.blur_image)
|
m.addAction(_('Blur image'), self.blur_image)
|
||||||
m.addAction(_('De-speckle image'), self.canvas.despeckle_image)
|
m.addAction(_('De-speckle image'), self.canvas.despeckle_image)
|
||||||
m.addAction(_('Improve contrast (normalize image)'), self.canvas.normalize_image)
|
m.addAction(_('Improve contrast (normalize image)'), self.canvas.normalize_image)
|
||||||
|
m.addAction(_('Make image look like an oil painting'), self.oilify_image)
|
||||||
|
|
||||||
self.info_bar = b = self.addToolBar(_('Image information bar'))
|
self.info_bar = b = self.addToolBar(_('Image information bar'))
|
||||||
b.setObjectName('image_info_bar')
|
b.setObjectName('image_info_bar')
|
||||||
@ -322,6 +323,12 @@ class Editor(QMainWindow):
|
|||||||
if ok:
|
if ok:
|
||||||
self.canvas.blur_image(sigma=val)
|
self.canvas.blur_image(sigma=val)
|
||||||
|
|
||||||
|
def oilify_image(self):
|
||||||
|
val, ok = QInputDialog.getDouble(self, _('Oilify image'), _(
|
||||||
|
'The strength of the operation (higher numbers have larger effects)'), value=4, min=0.1, max=20)
|
||||||
|
if ok:
|
||||||
|
self.canvas.oilify_image(radius=val)
|
||||||
|
|
||||||
def launch_editor(path_to_edit, path_is_raw=False):
|
def launch_editor(path_to_edit, path_is_raw=False):
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
if path_is_raw:
|
if path_is_raw:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user