What’s new in Pystacia 0.2

This release focuses on thread-safety, reducing code boiler-plate, performance, increasing quality and test-coverage.

Architecture

The C API intermediate interface has been rewritten from scratch. It introduces a concept of a bridge that isolates code execution from several threads into so called “C-thread” that takes care of correct synchronization and ensures thread-safety. Imaging operations are still performed in parallel thanks to OMP inside ImageMagick. Actually this approach yields even better performance as OMP may have strange interactions with threads resulting in excessive context switching.

pystacia.image.Image and pystacia.color.Color inherit now from common base pystacia.common.Resource that encapsulate all the details of tracing instances, allocating, freeing memory at right time and preventing memory leaks.

Underlying C function prototypes and ImageMagick itself are loaded lazily on-demand resulting in faster startup times when importing modules. Also cross-module dependencies have been greatly reduced.

Enumeration and color handling simplification

From now on function calls that accept enumerations and color specifications can handle many formats without explicit casting. This approach reduces dependencies in your code and will be used in the documentation. Old way is still supported and in fact it gets auto-cast to it underneath.

>>> img1.overlay(img2, composite=composites.dst_over)  # old way
>>> img1.overlay(img2, composite='dst_over')  # new preferred way
>>> img1.get_pixel(0, 0) == from_rgb(1, 0, 0)  # old way
>>> img1.get_pixel(0, 0) == (1, 0, 0)  # new way
>>> img1.get_pixel(0, 0) == 'red'  # even simpler
>>> img1.get_pixel(0, 0) == 0xFF0000  # or like that

TODO: Link it More information can be found in Enum handling and Working with color chapters.

The registry

The registry is a concept introducing control over global Pystacia behavior. E.g. you can use it to set class used instead of pystacia.image.Image when instantiating image objects:

>>> class MyImage(Image):
>>>     def cool_stuff(self): pass
>>>
>>> from pystacia import registry
>>> registry.image_factory = MyImage
>>>
>>> blank(30, 30).__class__ == MyImage
True

TODO link: More on registry can be read in Controlling global behavior

Underlying ImageMagick

TODO: Bundled ImageMagick has been updated to version 6.3.7.X and built with

  • libjpeg
  • libtiff
  • libpng
  • libwebp
  • libfftw
  • libz

Color features

Color module gained support for pystacia.color.from_hsl(), pystacia.color.from_int24() and pystacia.color.from_rgb8() together with accompanying getters pystacia.color.Color.get_hsl(), pystacia.color.Color.get_rgb8(), pystacia.color.Color.get_int24().

Migrating to 0.2

Deprecated symbols

Several symbols have been deprecated:

  • read, read_blob, read_raw, blank, checkerboard, lena, magick_logo, rose, wizard, granite, netscape, composites, types, filters, colorspaces, compressions, axes, Image have been moved from pystacia to pystacia.image. Old imports will still worked and are proxied to corresponding imports in pystacia.image but they will be completely removed in 0.3.
  • pystacia.util.TinyException is deprecated in favor of pystacia.util.PystaciaException. The old class is still in place but will be removed in 0.3.

There is easy way to detect if you are using one of those symbols. To get all warning information sent to stdout just run your script with -W all switch.