forked from connordelacruz/ChannelShiftGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages.pde
87 lines (69 loc) · 2.42 KB
/
images.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// =============================================================================
// Globals related to working PImage objects
// =============================================================================
// Manager =====================================================================
// TODO store previous image objects to allow for undo?
/**
* Manage the source, target, and preview PImage objects
*/
public class ImgManager {
// Source, modified, and preview images
public PImage sourceImg, targetImg, previewImg;
// Width/height vars for easy access
public int imgWidth, imgHeight;
// Use resulting image as the source for next iteration upon confirming step
public boolean recursiveIteration;
public ImgManager() {
imgWidth = imgHeight = 0;
recursiveIteration = true;
}
// Getter/Setter
public void loadImageFile(String path) {
// Initialize images
sourceImg = loadImage(path);
targetImg = sourceImg.copy();
previewImg = sourceImg.copy();
// This seems to fix a bug where the recursive option doesn't do anything
sourceImg.loadPixels();
targetImg.loadPixels();
previewImg.loadPixels();
// Update width/height vars
imgWidth = sourceImg.width;
imgHeight = sourceImg.height;
}
public void toggleRecursiveIteration(boolean recursive) { recursiveIteration = recursive; }
// Confirm Current Step
public void confirmStep() {
// Update targetImg to match preview
copyPreviewToTarget();
// If recursive, sourceImg.pixels = targetImg.pixels
if (recursiveIteration)
copyTargetPixelsToSource();
}
// Image Utility Methods
// TODO: doc, better names?
public void savePreviewImg(String path) {
previewImg.save(path);
}
public void copyTargetToPreview() {
previewImg = targetImg.copy();
previewImg.loadPixels();
}
public void copyPreviewToTarget() {
targetImg = previewImg.copy();
targetImg.loadPixels();
}
public void updatePreview() {
previewImg.updatePixels();
}
// For recursive iterations
public void copyTargetPixelsToSource() {
sourceImg.pixels = targetImg.pixels;
sourceImg.updatePixels();
}
}
// Event Handlers ==============================================================
// Recursive Checkbox ----------------------------------------------------------
public void recursiveCheckbox_click(GCheckbox source, GEvent event) {
imgManager.toggleRecursiveIteration(source.isSelected());
}