add basic transform operators to the pyKrita objects Document and Node
ClosedPublic

Authored by woltherav on May 27 2017, 2:29 PM.

Details

Summary

This adds Shear, Rotate and Scale to Document and Node. It also adds Crop to Node.

Questions:

  1. How to handle filter strategies? Right now I have it default to Bilinear, as that's the one that gets the most avarage results for all bitdepths(lanczos3's natural halo becomes a bit intense in floating point). More prduently, how do we communicate the right filter strategy?
  1. Scaling seems to be happening in percentages, should this be full pixel values instead?
  1. Rotate uses radians, shear uses degrees, maybe have rotate use degrees as well, for both consistency and ease of use?
Test Plan

You can test it by using the following script in scripter:

import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from krita import *

doc = Application.activeDocument()

doc.scaleImage(50, 50, doc.xRes(), doc.yRes())
doc.rotateImage(0.5)
doc.shearImage(25, 25)

doc.activeNode().rotateNode(1)

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
dkazakov added a subscriber: dkazakov.EditedMay 29 2017, 9:46 AM

Hi, @woltherav!

The patch looks fine, from the Strokes point of view. The only (theoretical) trouble might be in the testing code. If one decides to read pixel data with the script that after calling these transformations, he would need to call waitForDone() before that. But this is more a documentation issue.

UPD:
Without that "reading", waitForDone() is not needed, exactly like in your example script.

I'm okay with pushing this patch

dkazakov accepted this revision as: dkazakov.May 30 2017, 9:47 AM

Accept

This revision is now accepted and ready to land.May 30 2017, 9:47 AM
rempt accepted this revision.May 30 2017, 9:49 AM

Cool, but the three questions that I asked? :D

How to handle filter strategies? Right now I have it default to Bilinear, as that's the one that gets the most avarage results for all bitdepths(lanczos3's natural halo becomes a bit intense in floating point). More prduently, how do we communicate the right filter strategy?

Can you just pass some enum value from the script and create an appropriate strategy in the C++ code? Afair, in Python people just pass strings for such options... And add a runtime assert to check if the strings are from the supported list of values.

Scaling seems to be happening in percentages, should this be full pixel values instead?

Erm... I don't see any percents there, you pass real widht and height, don't you?

Rotate uses radians, shear uses degrees, maybe have rotate use degrees as well, for both consistency and ease of use?

Nice catch! :) Can you fix KisImage::shearImpl() to accept radians instead of degrees? In all the places in Krita we use radians by default (KisTransformWorker, KisPaintInformation).

This revision was automatically updated to reflect the committed changes.

I pushed this, I will refactor shear a bit later because radian/degree stuff makes my head boggle.

I pushed this, I will refactor shear a bit later because radian/degree stuff makes my head boggle.

Just use kisDegreesToRadians() function from kis_global.h :)