Skip to content

Commit

Permalink
Implement an "emboss" filter in the worst way known to mankind (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Dec 12, 2020
1 parent c2d4790 commit 6caa562
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ drawing_sources = [
'tools/transform_tools/filters/filter_blur.py',
'tools/transform_tools/filters/filter_colors.py',
'tools/transform_tools/filters/filter_contrast.py',
'tools/transform_tools/filters/filter_emboss.py',
'tools/transform_tools/filters/filter_saturation.py',
'tools/transform_tools/filters/filter_transparency.py',
'tools/transform_tools/filters/filter_veil.py',
Expand Down
5 changes: 5 additions & 0 deletions src/optionsbars/transform/optionsbar-filters.ui
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@
<attribute name="action">win.filters_type</attribute>
<attribute name="target">contrast</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Emboss</attribute>
<attribute name="action">win.filters_type</attribute>
<attribute name="target">emboss</attribute>
</item>
</section>
<section>
<!-- Context: the title of the menu with various types of blurring -->
Expand Down
41 changes: 41 additions & 0 deletions src/tools/transform_tools/filters/filter_emboss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Licensed under GPL3 https://github.com/maoschanz/drawing/blob/master/LICENSE

import cairo
from gi.repository import Gdk
from .abstract_filter import AbstractFilter
from .utilities_blur import utilities_blur_surface, BlurType, BlurDirection

class FilterEmboss(AbstractFilter):
__gtype_name__ = 'FilterEmboss'

def do_filter_operation(self, source_pixbuf, operation):
surface = Gdk.cairo_surface_create_from_pixbuf(source_pixbuf, 0, None)
scale = self._tool.scale_factor()
surface.set_device_scale(scale, scale)
width = source_pixbuf.get_width()
height = source_pixbuf.get_height()
new_surface = cairo.ImageSurface(cairo.Format.ARGB32, width, height)

cairo_context = cairo.Context(new_surface)
cairo_context.set_source_surface(surface)
cairo_context.set_operator(cairo.Operator.SOURCE)
cairo_context.paint()

bdir = BlurDirection.BOTH # could be an option
bs = utilities_blur_surface(surface, 1, BlurType.CAIRO_REPAINTS, bdir)
cairo_context2 = cairo.Context(bs)
cairo_context2.set_operator(cairo.Operator.DIFFERENCE)
cairo_context2.set_source_rgba(1.0, 1.0, 1.0, 1.0)
cairo_context2.paint()

cairo_context.set_source_surface(bs)
cairo_context.set_operator(cairo.Operator.OVER)
cairo_context.paint_with_alpha(0.5)

new_pixbuf = Gdk.pixbuf_get_from_surface(new_surface, 0, 0, \
new_surface.get_width(), new_surface.get_height())
self._tool.get_image().set_temp_pixbuf(new_pixbuf)

############################################################################
################################################################################

2 changes: 1 addition & 1 deletion src/tools/transform_tools/filters/filter_transparency.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def do_filter_operation(self, source_pixbuf, operation):
new_surface = cairo.ImageSurface(cairo.Format.ARGB32, width, height)
cairo_context = cairo.Context(new_surface)
cairo_context.set_source_surface(surface)

cairo_context.set_operator(cairo.Operator.SOURCE)

cairo_context.paint_with_alpha(1.0 - percent)
# TODO if percent is negative, paint first the normal version, and then
# paint with [-1 * percent] alpha the pixbuf
Expand Down
5 changes: 5 additions & 0 deletions src/tools/transform_tools/tool_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .filter_blur import FilterBlur
from .filter_colors import FilterColors
from .filter_contrast import FilterContrast
from .filter_emboss import FilterEmboss
from .filter_saturation import FilterSaturation
from .filter_transparency import FilterTransparency
from .filter_veil import FilterVeil
Expand Down Expand Up @@ -48,6 +49,7 @@ def __init__(self, window):
'blur': FilterBlur('blur', self),
'colors': FilterColors('colors', self),
'contrast': FilterContrast('contrast', self),
'emboss': FilterEmboss('emboss', self),
'saturation': FilterSaturation('saturation', self),
'transparency': FilterTransparency('transparency', self),
'veil': FilterVeil('veil', self),
Expand Down Expand Up @@ -110,6 +112,9 @@ def _set_active_type(self, *args):
self.type_label = _("Increase contrast")
self._active_filter = 'contrast'
# TODO changer la luminosity tant qu'à faire
elif state_as_string == 'emboss':
self.type_label = _("Emboss")
self._active_filter = 'emboss'

elif state_as_string == 'invert':
self.type_label = _("Invert colors")
Expand Down
5 changes: 5 additions & 0 deletions src/tools/ui/tool-filters.ui
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<attribute name="action">win.filters_type</attribute>
<attribute name="target">contrast</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Emboss</attribute>
<attribute name="action">win.filters_type</attribute>
<attribute name="target">emboss</attribute>
</item>
</section>
<section>
<item>
Expand Down

0 comments on commit 6caa562

Please sign in to comment.