App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

LinearTransformationTool.java
Go to the documentation of this file.
1 package mhr.appcore.tools.cancelable;
2
3 import mhr.appcore.bitmap.NBitmap;
4 import mhr.appcore.image.Image;
5 import mhr.appcore.image.ImageSelectedState;
6 import mhr.appcore.interpolators.InterpolatorType;
7 import mhr.appcore.tools.actiondata.CancelableToolActionData;
8 import mhr.appcore.tools.actiondata.ContrastLUTCancelableToolActionData;
9 import mhr.appcore.tools.actiondata.LinearTransformationToolActionData;
10 import mhr.appcore.tools.actiondata.ToolActionData;
11 import mhr.appcore.tools.exceptions.ToolNotApplicableException;
12 import mhr.appcore.transform.TM;
13 import mhr.appcore.transform.Transform;
14 import mhr.appcore.utils.Rect;
15
16 public class LinearTransformationTool extends CancelableTool {
17
18 TM tMatrix = null;
19
20 public LinearTransformationTool() {
21 }
22
23 @Override
24 public void applyTo(Image img, ToolActionData data) {
25 if (img.getSelectedState() != ImageSelectedState.SELECTED_LAYER) {
26 throw new ToolNotApplicableException("Selected tool is not applicable to selected item.");
27 }
28 super.applyTo(img, data);
29 }
30
31 @Override
32 public void onRender(Image img, NBitmap canvas, NBitmap tmpLayer, NBitmap origLayer, NBitmap masterMask, Rect src, int srcOrigX, int srcOrigY) {
33 if (tMatrix != null) {
34 Transform.applyMatrixTo(tmpLayer, origLayer, tMatrix, InterpolatorType.NEAREST_NEIGHBOUR);
35 } else {
36 origLayer.copyTo(tmpLayer, src, srcOrigX, srcOrigY);
37 }
38 }
39
40 @Override
41 public void onCommit(Image image, NBitmap canvas, NBitmap tmpLayer, NBitmap origLayer, NBitmap masterMask, Rect src, int srcOrigX, int srcOrigY) {
42 if (tMatrix != null) {
43 origLayer.copyTo(tmpLayer, src, srcOrigX, srcOrigY);
44 Transform.applyMatrixTo(origLayer, tmpLayer, tMatrix, InterpolatorType.CUBIC_INTERPOLATOR);
45 } else {
46 // nothing...
47 }
48 }
49
50 @Override
51 protected void onPreview(Image img, CancelableToolActionData data) {
52 if (!(data instanceof LinearTransformationToolActionData)) {
53 throw new IllegalArgumentException("Received data for different tool");
54 } else {
55 tMatrix = ((LinearTransformationToolActionData)data).m;
56 }
57 }
58
59 }