Skip to content

Add improved halftone filter

Deif Lou requested to merge deiflou/krita:deiflou/halftone_filter_mr into master

This MR adds an improved halftone filter. Some of its features are:

  • It allows three modes:
    • Intensity. Converts the image to grayscale and performs the halftoning (typical of black and white newspaper images).
    • Independent Channels. Applies the halftoning to each channel separatelly (color separation, usefull for offset printing or screen printing).
    • Alpha. Apply the halftoning to the alpha channel or to a mask (This allows to apply texture to the semitransparent areas).
  • It doesn't hardcode the patterns/textures. Instead it uses the generators to create them, allowing for more variety and exploration. The screentone generator provides the most common halftone patterns such as dots or lines. Other custom textures can be made with the pattern generator or procedurally with the SeExpr generator, allowing the filter to use a virtually endless number of patterns.
  • It is fast. Both this filter and the screentone generator use an image processing approach. They perform simple and fast per-pixel operations instead of drawing circles or similar approaches, comparable in speed to a simple levels adjustement. The speed really depends on how fast is the generator used to make the patterns. This approach allows multithreading and allows the filter to be used as a filter layer or mask.
  • It allows to modulate the hardness of the resulting image. The classical approach just ends up performing a thresholding and outputting an aliased binary image. In this filter you can choose how hard the edges are.
  • In case of using the intensity mode, one can choose the color and opacity of the foreground and the background.
  • The filter is color space aware. If for example CMYK is selected, you see the tabs for these channels in the ui to allow you to choose the halftoning approach for each of them when independent channels mode is selected.

Sample videos:

https://www.youtube.com/watch?v=qhBjrKrbq6k

https://www.youtube.com/watch?v=4HfKxd4pst0

NOTE 1: I've decided to replace the old halftone filter with this one. Since the old one couldn't be used as a filter layer or mask, I think this change can't broke anything, like saved files (if it may, please let me know).

NOTE 2: The filter works well, but I'm getting some segmentation faults that I don't know how to fix. I've debugged but I'm not capable of seeing where can the bug be. It seems that always is related to the KisPropertiesConfiguration somehow. Here are 3 backtraces. In two of them the program seems to crash when the generators are called, so for a while I think that it could be related to that. But in the other one the program crashes even before any of the functions that use generator are called. Here they are the backtraces: backtrace01.txt, backtrace02.txt, backtrace03.txt

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.
Edited by Dmitry Kazakov

Merge request reports

Loading