propane 3.4.0-java → 3.4.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -2
- data/.travis.yml +2 -2
- data/CHANGELOG.md +2 -0
- data/README.md +12 -7
- data/Rakefile +2 -2
- data/lib/propane.rb +2 -2
- data/lib/propane/app.rb +18 -9
- data/lib/propane/helper_methods.rb +1 -1
- data/lib/propane/runner.rb +1 -1
- data/lib/propane/version.rb +1 -1
- data/library/color_group/color_group.rb +26 -0
- data/library/dxf/dxf.rb +4 -0
- data/library/net/net.rb +5 -0
- data/library/video_event/video_event.rb +2 -1
- data/pom.rb +3 -3
- data/pom.xml +3 -3
- data/propane.gemspec +1 -1
- data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
- data/src/main/java/monkstone/ColorUtil.java +14 -0
- data/src/main/java/monkstone/MathToolModule.java +243 -194
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +6 -5
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -2
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
- data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +10 -26
- data/src/main/java/processing/awt/PSurfaceAWT.java +1 -1
- data/src/main/java/processing/core/PApplet.java +1236 -599
- data/src/main/java/processing/core/PGraphics.java +59 -59
- data/src/main/java/processing/core/PImage.java +528 -129
- data/src/main/java/processing/core/PShape.java +10 -10
- data/src/main/java/processing/core/PVector.java +2 -2
- data/src/main/java/processing/core/ThinkDifferent.java +5 -7
- data/src/main/java/processing/dxf/RawDXF.java +404 -0
- data/src/main/java/processing/net/Client.java +744 -0
- data/src/main/java/processing/net/Server.java +388 -0
- data/src/main/java/processing/opengl/FontTexture.java +19 -20
- data/src/main/java/processing/opengl/FrameBuffer.java +27 -17
- data/src/main/java/processing/opengl/LinePath.java +512 -508
- data/src/main/java/processing/opengl/PGL.java +3106 -3066
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +4 -4
- data/src/main/java/processing/opengl/PShader.java +1442 -1341
- data/vendors/Rakefile +3 -27
- metadata +12 -25
- data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
- data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
- data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
- data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
- data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
- data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
- data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
- data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
- data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
- data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
- data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
- data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
- data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
- data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
- data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
- data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
- data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
- data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
- data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
- data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
data/vendors/Rakefile
CHANGED
@@ -8,9 +8,9 @@ EOS
|
|
8
8
|
SOUND = 'sound.zip'.freeze
|
9
9
|
SOUND_VERSION = 'v1.3.2' # version 1.3.2
|
10
10
|
GLVIDEO = 'processing-glvideo.zip'
|
11
|
-
VIDEO = 'video-2.zip'
|
12
|
-
VIDEO_VERSION = '
|
13
|
-
EXAMPLES = '2.
|
11
|
+
VIDEO = 'video-2.0-beta4.zip'
|
12
|
+
VIDEO_VERSION = 'r6-v2.0-beta4'
|
13
|
+
EXAMPLES = '2.6'.freeze
|
14
14
|
HOME_DIR = ENV['HOME']
|
15
15
|
MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
|
16
16
|
|
@@ -40,10 +40,6 @@ task download_and_copy_sound: [:init_dir, :download_sound, :copy_sound, :clobber
|
|
40
40
|
desc 'download and copy video library to ~/.propane'
|
41
41
|
task download_and_copy_video: [:init_dir, :download_video, :copy_video, :clobber]
|
42
42
|
|
43
|
-
desc 'download and copy glvideo library to ~/.propane'
|
44
|
-
task download_and_copy_glvideo: [:init_dir, :download_glvideo, :copy_glvideo, :clobber]
|
45
|
-
|
46
|
-
|
47
43
|
desc 'download sound library'
|
48
44
|
task :download_sound do
|
49
45
|
wget_base = 'wget https://github.com/processing/processing-sound'
|
@@ -55,17 +51,6 @@ task :download_sound do
|
|
55
51
|
end
|
56
52
|
end
|
57
53
|
|
58
|
-
desc 'download glvideo library'
|
59
|
-
task :download_glvideo do
|
60
|
-
wget_base = 'wget https://github.com/gohai/processing-glvideo'
|
61
|
-
wget_string = [wget_base, 'releases/download/latest', GLVIDEO].join('/')
|
62
|
-
begin
|
63
|
-
sh wget_string
|
64
|
-
rescue
|
65
|
-
warn(WARNING)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
54
|
desc 'download video library'
|
70
55
|
task :download_video do
|
71
56
|
wget_base = 'wget https://github.com/processing/processing-video'
|
@@ -116,12 +101,3 @@ task :copy_video => VIDEO do
|
|
116
101
|
sh "cp -r video #{HOME_DIR}/.propane/libraries/video"
|
117
102
|
sh 'rm -r video'
|
118
103
|
end
|
119
|
-
|
120
|
-
desc 'copy glvideo library'
|
121
|
-
task :copy_glvideo => GLVIDEO do
|
122
|
-
directory "~/.propane/libraries/glvideo"
|
123
|
-
sh "unzip #{GLVIDEO}"
|
124
|
-
sh "rm -r #{HOME_DIR}/.propane/libraries/glvideo" if File.exist? "#{HOME_DIR}/.propane/libraries/glvideo"
|
125
|
-
sh "cp -r glvideo #{HOME_DIR}/.propane/libraries/glvideo"
|
126
|
-
sh 'rm -r glvideo'
|
127
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: propane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.
|
4
|
+
version: 3.4.1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- monkstone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -91,7 +91,7 @@ files:
|
|
91
91
|
- lib/jogl-all-natives-macosx-universal.jar
|
92
92
|
- lib/jogl-all-natives-windows-amd64.jar
|
93
93
|
- lib/jogl-all.jar
|
94
|
-
- lib/propane-3.4.
|
94
|
+
- lib/propane-3.4.1.jar
|
95
95
|
- lib/propane.rb
|
96
96
|
- lib/propane/app.rb
|
97
97
|
- lib/propane/creators/sketch_class.rb
|
@@ -107,11 +107,14 @@ files:
|
|
107
107
|
- lib/propane/runner.rb
|
108
108
|
- lib/propane/version.rb
|
109
109
|
- library/boids/boids.rb
|
110
|
+
- library/color_group/color_group.rb
|
110
111
|
- library/control_panel/control_panel.rb
|
112
|
+
- library/dxf/dxf.rb
|
111
113
|
- library/file_chooser/chooser.rb
|
112
114
|
- library/file_chooser/file_chooser.rb
|
113
115
|
- library/library_proxy/README.md
|
114
116
|
- library/library_proxy/library_proxy.rb
|
117
|
+
- library/net/net.rb
|
115
118
|
- library/simplex_noise/simplex_noise.rb
|
116
119
|
- library/slider/slider.rb
|
117
120
|
- library/vector_utils/vector_utils.rb
|
@@ -149,7 +152,8 @@ files:
|
|
149
152
|
- src/main/java/monkstone/vecmath/vec2/package-info.java
|
150
153
|
- src/main/java/monkstone/vecmath/vec3/Vec3.java
|
151
154
|
- src/main/java/monkstone/vecmath/vec3/package-info.java
|
152
|
-
- src/main/java/monkstone/videoevent/
|
155
|
+
- src/main/java/monkstone/videoevent/CaptureEvent.java
|
156
|
+
- src/main/java/monkstone/videoevent/MovieEvent.java
|
153
157
|
- src/main/java/monkstone/videoevent/package-info.java
|
154
158
|
- src/main/java/processing/awt/PGraphicsJava2D.java
|
155
159
|
- src/main/java/processing/awt/PShapeJava2D.java
|
@@ -170,26 +174,6 @@ files:
|
|
170
174
|
- src/main/java/processing/core/PSurfaceNone.java
|
171
175
|
- src/main/java/processing/core/PVector.java
|
172
176
|
- src/main/java/processing/core/ThinkDifferent.java
|
173
|
-
- src/main/java/processing/core/util/image/ImageLoadFacade.java
|
174
|
-
- src/main/java/processing/core/util/image/ImageSaveFacade.java
|
175
|
-
- src/main/java/processing/core/util/image/constants/TifConstants.java
|
176
|
-
- src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java
|
177
|
-
- src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java
|
178
|
-
- src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java
|
179
|
-
- src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java
|
180
|
-
- src/main/java/processing/core/util/image/load/ImageLoadStrategy.java
|
181
|
-
- src/main/java/processing/core/util/image/load/ImageLoadUtil.java
|
182
|
-
- src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java
|
183
|
-
- src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java
|
184
|
-
- src/main/java/processing/core/util/image/save/ImageSaveStrategy.java
|
185
|
-
- src/main/java/processing/core/util/image/save/ImageSaveUtil.java
|
186
|
-
- src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java
|
187
|
-
- src/main/java/processing/core/util/image/save/SaveImageException.java
|
188
|
-
- src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java
|
189
|
-
- src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java
|
190
|
-
- src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java
|
191
|
-
- src/main/java/processing/core/util/io/InputFactory.java
|
192
|
-
- src/main/java/processing/core/util/io/PathUtil.java
|
193
177
|
- src/main/java/processing/data/DoubleDict.java
|
194
178
|
- src/main/java/processing/data/DoubleList.java
|
195
179
|
- src/main/java/processing/data/FloatDict.java
|
@@ -207,12 +191,15 @@ files:
|
|
207
191
|
- src/main/java/processing/data/Table.java
|
208
192
|
- src/main/java/processing/data/TableRow.java
|
209
193
|
- src/main/java/processing/data/XML.java
|
194
|
+
- src/main/java/processing/dxf/RawDXF.java
|
210
195
|
- src/main/java/processing/event/Event.java
|
211
196
|
- src/main/java/processing/event/KeyEvent.java
|
212
197
|
- src/main/java/processing/event/MouseEvent.java
|
213
198
|
- src/main/java/processing/event/TouchEvent.java
|
214
199
|
- src/main/java/processing/javafx/PGraphicsFX2D.java
|
215
200
|
- src/main/java/processing/javafx/PSurfaceFX.java
|
201
|
+
- src/main/java/processing/net/Client.java
|
202
|
+
- src/main/java/processing/net/Server.java
|
216
203
|
- src/main/java/processing/opengl/FontTexture.java
|
217
204
|
- src/main/java/processing/opengl/FrameBuffer.java
|
218
205
|
- src/main/java/processing/opengl/LinePath.java
|
@@ -291,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
291
278
|
version: '0'
|
292
279
|
requirements:
|
293
280
|
- java runtime >= 11.0.2+
|
294
|
-
rubygems_version: 3.0.
|
281
|
+
rubygems_version: 3.0.6
|
295
282
|
signing_key:
|
296
283
|
specification_version: 4
|
297
284
|
summary: ruby implementation of processing-4.0 on MacOS, linux and windows (64bit
|
@@ -1,161 +0,0 @@
|
|
1
|
-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
-
|
3
|
-
/*
|
4
|
-
Part of the Processing project - http://processing.org
|
5
|
-
|
6
|
-
Copyright (c) 2012-18 The Processing Foundation
|
7
|
-
Copyright (c) 2004-12 Ben Fry and Casey Reas
|
8
|
-
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
9
|
-
|
10
|
-
This library is free software; you can redistribute it and/or
|
11
|
-
modify it under the terms of the GNU Lesser General Public
|
12
|
-
License as published by the Free Software Foundation, version 2.1.
|
13
|
-
|
14
|
-
This library is distributed in the hope that it will be useful,
|
15
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
17
|
-
Lesser General Public License for more details.
|
18
|
-
|
19
|
-
You should have received a copy of the GNU Lesser General
|
20
|
-
Public License along with this library; if not, write to the
|
21
|
-
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
22
|
-
Boston, MA 02111-1307 USA
|
23
|
-
*/
|
24
|
-
|
25
|
-
package processing.core.util.image;
|
26
|
-
|
27
|
-
import processing.core.PApplet;
|
28
|
-
import processing.core.PImage;
|
29
|
-
import processing.core.util.image.load.*;
|
30
|
-
import processing.core.util.io.PathUtil;
|
31
|
-
|
32
|
-
import java.util.HashMap;
|
33
|
-
import java.util.Map;
|
34
|
-
import java.util.concurrent.atomic.AtomicReference;
|
35
|
-
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Utility for loading images either from file system or string encoding using a set of strategies.
|
39
|
-
*/
|
40
|
-
public class ImageLoadFacade {
|
41
|
-
|
42
|
-
private static final AtomicReference<ImageLoadFacade> instance = new AtomicReference<>(null);
|
43
|
-
|
44
|
-
private static final String PREFIX_BASE64_STRING_IMAGE = "data:image";
|
45
|
-
private static final String PREFIX_FILE_PATH = "file://";
|
46
|
-
|
47
|
-
private final Map<String, ImageLoadStrategy> loadStrategies;
|
48
|
-
private final ImageLoadStrategy defaultImageLoadStrategy;
|
49
|
-
|
50
|
-
/**
|
51
|
-
* Get a shared instance of this singleton.
|
52
|
-
*
|
53
|
-
* @return Shared instance of this singleton.
|
54
|
-
*/
|
55
|
-
public static ImageLoadFacade get() {
|
56
|
-
instance.compareAndSet(null, new ImageLoadFacade());
|
57
|
-
return instance.get();
|
58
|
-
}
|
59
|
-
|
60
|
-
/**
|
61
|
-
* Hidden constructor. Clients should use get().
|
62
|
-
*/
|
63
|
-
private ImageLoadFacade() {
|
64
|
-
loadStrategies = new HashMap<>();
|
65
|
-
|
66
|
-
loadStrategies.put("base64", new Base64StringImageLoadStrategy());
|
67
|
-
|
68
|
-
loadStrategies.put("tga", new TgaImageLoadStrategy());
|
69
|
-
|
70
|
-
ImageLoadStrategy tifImageLoadStrategy = new TiffImageLoadStrategy();
|
71
|
-
loadStrategies.put("tif", tifImageLoadStrategy);
|
72
|
-
loadStrategies.put("tiff", tifImageLoadStrategy);
|
73
|
-
|
74
|
-
ImageLoadStrategy awtImageLoadStrategy = new AwtImageLoadStrategy();
|
75
|
-
defaultImageLoadStrategy = new ImageIoImageLoadStrategy();
|
76
|
-
|
77
|
-
ImageLoadStrategy awtFallbackStrategy = new FallbackImageLoadStrategy(
|
78
|
-
awtImageLoadStrategy,
|
79
|
-
defaultImageLoadStrategy
|
80
|
-
);
|
81
|
-
loadStrategies.put("jpg", awtFallbackStrategy);
|
82
|
-
loadStrategies.put("jpeg", awtFallbackStrategy);
|
83
|
-
loadStrategies.put("gif", awtFallbackStrategy);
|
84
|
-
loadStrategies.put("png", awtFallbackStrategy);
|
85
|
-
loadStrategies.put("unknown", awtFallbackStrategy);
|
86
|
-
}
|
87
|
-
|
88
|
-
/**
|
89
|
-
* Load an image embedded within an SVG string.
|
90
|
-
*
|
91
|
-
* @param pApplet The PApplet on whose behalf an SVG is being parsed. This must be given so that
|
92
|
-
* image can be retrieved in the case of sketch relative file.
|
93
|
-
* @param svgImageStr The SVG string to load which can be data:image or file://.
|
94
|
-
* @return The image loaded as a PImage.
|
95
|
-
*/
|
96
|
-
public PImage loadFromSvg(PApplet pApplet, String svgImageStr) {
|
97
|
-
if (svgImageStr == null) {
|
98
|
-
return null;
|
99
|
-
}
|
100
|
-
|
101
|
-
if (svgImageStr.startsWith(PREFIX_BASE64_STRING_IMAGE)) {
|
102
|
-
String[] parts = svgImageStr.split(";base64,");
|
103
|
-
String extension = parts[0].substring(11);
|
104
|
-
String encodedData = parts[1];
|
105
|
-
return loadStrategies.get("base64").load(pApplet, encodedData, extension);
|
106
|
-
} else if (svgImageStr.startsWith(PREFIX_FILE_PATH)) {
|
107
|
-
String filePath = svgImageStr.substring(PREFIX_FILE_PATH.length());
|
108
|
-
return loadFromFile(pApplet, filePath);
|
109
|
-
} else {
|
110
|
-
return null;
|
111
|
-
}
|
112
|
-
}
|
113
|
-
|
114
|
-
/**
|
115
|
-
* Load an image from a file.
|
116
|
-
*
|
117
|
-
* @param pApplet The PApplet through which the image should be retrieved in the case of sketch
|
118
|
-
* relative file (data folder for example).
|
119
|
-
* @param path The path to the file to be opened.
|
120
|
-
* @return The image loaded.
|
121
|
-
*/
|
122
|
-
public PImage loadFromFile(PApplet pApplet, String path) {
|
123
|
-
return loadFromFile(pApplet, path, null);
|
124
|
-
}
|
125
|
-
|
126
|
-
/**
|
127
|
-
* Load an image from a file using the given file extension.
|
128
|
-
*
|
129
|
-
* @param pApplet The PApplet through which the image should be retrieved in the case of sketch
|
130
|
-
* relative file (data folder for example).
|
131
|
-
* @param path The path to the file to be opened.
|
132
|
-
* @param extension The extension with which the image should be loaded like "png".
|
133
|
-
* @return The image loaded.
|
134
|
-
*/
|
135
|
-
public PImage loadFromFile(PApplet pApplet, String path, String extension) {
|
136
|
-
if (extension == null) {
|
137
|
-
extension = PathUtil.parseExtension(path);
|
138
|
-
}
|
139
|
-
|
140
|
-
// just in case. them users will try anything!
|
141
|
-
extension = PathUtil.cleanExtension(extension);
|
142
|
-
|
143
|
-
// Find strategy for loading
|
144
|
-
ImageLoadStrategy imageLoadStrategy = loadStrategies.getOrDefault(
|
145
|
-
extension,
|
146
|
-
defaultImageLoadStrategy
|
147
|
-
);
|
148
|
-
|
149
|
-
// Load image
|
150
|
-
PImage resultImage = imageLoadStrategy.load(pApplet, path, extension);
|
151
|
-
|
152
|
-
// Report error or return
|
153
|
-
if (resultImage == null) {
|
154
|
-
System.err.println("Could not find a method to load " + path);
|
155
|
-
return null;
|
156
|
-
} else {
|
157
|
-
return resultImage;
|
158
|
-
}
|
159
|
-
}
|
160
|
-
|
161
|
-
}
|
@@ -1,169 +0,0 @@
|
|
1
|
-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
-
|
3
|
-
/*
|
4
|
-
Part of the Processing project - http://processing.org
|
5
|
-
|
6
|
-
Copyright (c) 2012-18 The Processing Foundation
|
7
|
-
Copyright (c) 2004-12 Ben Fry and Casey Reas
|
8
|
-
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
9
|
-
|
10
|
-
This library is free software; you can redistribute it and/or
|
11
|
-
modify it under the terms of the GNU Lesser General Public
|
12
|
-
License as published by the Free Software Foundation, version 2.1.
|
13
|
-
|
14
|
-
This library is distributed in the hope that it will be useful,
|
15
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
17
|
-
Lesser General Public License for more details.
|
18
|
-
|
19
|
-
You should have received a copy of the GNU Lesser General
|
20
|
-
Public License along with this library; if not, write to the
|
21
|
-
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
22
|
-
Boston, MA 02111-1307 USA
|
23
|
-
*/
|
24
|
-
|
25
|
-
package processing.core.util.image;
|
26
|
-
|
27
|
-
import processing.core.PApplet;
|
28
|
-
import processing.core.PGraphics;
|
29
|
-
import processing.core.util.image.save.*;
|
30
|
-
import processing.core.util.io.PathUtil;
|
31
|
-
|
32
|
-
import java.io.File;
|
33
|
-
import java.io.IOException;
|
34
|
-
import java.util.HashMap;
|
35
|
-
import java.util.Map;
|
36
|
-
import java.util.concurrent.atomic.AtomicReference;
|
37
|
-
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Facade to load PImages from various sources.
|
41
|
-
*/
|
42
|
-
public class ImageSaveFacade {
|
43
|
-
|
44
|
-
private static final AtomicReference<ImageSaveFacade> instance = new AtomicReference<>(null);
|
45
|
-
|
46
|
-
private final Map<String, ImageSaveStrategy> saveStrategies;
|
47
|
-
private final ImageSaveStrategy defaultImageSaveStrategy;
|
48
|
-
|
49
|
-
/**
|
50
|
-
* Get a shared instance of this singleton.
|
51
|
-
*
|
52
|
-
* @return Shared instance of ImageSaveFacade.
|
53
|
-
*/
|
54
|
-
public static ImageSaveFacade get() {
|
55
|
-
instance.compareAndSet(null, new ImageSaveFacade());
|
56
|
-
return instance.get();
|
57
|
-
}
|
58
|
-
|
59
|
-
/**
|
60
|
-
* Private hidden constructor requiring clients to use get().
|
61
|
-
*/
|
62
|
-
private ImageSaveFacade() {
|
63
|
-
saveStrategies = new HashMap<>();
|
64
|
-
|
65
|
-
ImageSaveStrategy imageWriterImageSaveStrategy = new ImageWriterImageSaveStrategy();
|
66
|
-
for (String format : javax.imageio.ImageIO.getWriterFormatNames()) {
|
67
|
-
saveStrategies.put(format.toLowerCase(), imageWriterImageSaveStrategy);
|
68
|
-
}
|
69
|
-
|
70
|
-
ImageSaveStrategy tgaImageSaveStrategy = new TgaImageSaveStrategy();
|
71
|
-
saveStrategies.put("tga", tgaImageSaveStrategy);
|
72
|
-
|
73
|
-
ImageSaveStrategy tiffImageSaveStrategy = new TiffImageSaveStrategy();
|
74
|
-
saveStrategies.put("tiff", tiffImageSaveStrategy);
|
75
|
-
|
76
|
-
defaultImageSaveStrategy = new TiffNakedFilenameImageSaveStrategy();
|
77
|
-
}
|
78
|
-
|
79
|
-
/**
|
80
|
-
* Save a raw representation of pixel values to a file given that file's path.
|
81
|
-
*
|
82
|
-
* @param pixels The raw representation of the image to save.
|
83
|
-
* @param pixelWidth Width of the image in pixels.
|
84
|
-
* @param pixelheight Height of the image in pixels.
|
85
|
-
* @param format Format corresponding to value in PConstants like PConstants.ARGB.
|
86
|
-
* @param filename The path at which the file should be saved like "test/path/output.png".
|
87
|
-
*/
|
88
|
-
public boolean save(int[] pixels, int pixelWidth, int pixelHeight, int format, String filename) {
|
89
|
-
return save(
|
90
|
-
pixels,
|
91
|
-
pixelWidth,
|
92
|
-
pixelHeight,
|
93
|
-
format,
|
94
|
-
filename,
|
95
|
-
null
|
96
|
-
);
|
97
|
-
}
|
98
|
-
|
99
|
-
/**
|
100
|
-
* Save a raw representation of pixel values to a file given that file's path.
|
101
|
-
*
|
102
|
-
* @param pixels The raw representation of the image to save.
|
103
|
-
* @param pixelWidth Width of the image in pixels.
|
104
|
-
* @param pixelheight Height of the image in pixels.
|
105
|
-
* @param format Format corresponding to value in PConstants like PConstants.ARGB.
|
106
|
-
* @param filename The path at which the file should be saved like "test/path/output.png".
|
107
|
-
* @param pApplet The applet through which files should be saved when using sketch relative paths.
|
108
|
-
* Can pass null if using absolute paths.
|
109
|
-
*/
|
110
|
-
public boolean save(int[] pixels, int pixelWidth, int pixelHeight, int format, String filename,
|
111
|
-
PApplet pApplet) {
|
112
|
-
|
113
|
-
filename = preparePath(pApplet, filename);
|
114
|
-
|
115
|
-
String extension = PathUtil.parseExtension(filename);
|
116
|
-
|
117
|
-
ImageSaveStrategy imageSaveStrategy = saveStrategies.getOrDefault(
|
118
|
-
extension,
|
119
|
-
defaultImageSaveStrategy
|
120
|
-
);
|
121
|
-
|
122
|
-
try {
|
123
|
-
return imageSaveStrategy.save(
|
124
|
-
pixels,
|
125
|
-
pixelWidth,
|
126
|
-
pixelHeight,
|
127
|
-
format,
|
128
|
-
filename
|
129
|
-
);
|
130
|
-
} catch (IOException e) {
|
131
|
-
System.err.println("Error while saving image.");
|
132
|
-
e.printStackTrace();
|
133
|
-
return false;
|
134
|
-
} catch (SaveImageException e) {
|
135
|
-
PGraphics.showException(e.getMessage());
|
136
|
-
return false;
|
137
|
-
}
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
/**
|
142
|
-
* Ensure that the path is ready so that a file can be saved.
|
143
|
-
*
|
144
|
-
* @param pApplet The applet through which files should be saved when using sketch relative paths.
|
145
|
-
* Can pass null if using absolute paths.
|
146
|
-
* @param filename The filename that will be written and for which a path needs to be prepared.
|
147
|
-
* @return Completed path useable for writing like a file path that has been made relative to
|
148
|
-
* the sketch folder.
|
149
|
-
*/
|
150
|
-
private String preparePath(PApplet pApplet, String filename) {
|
151
|
-
if (pApplet != null) {
|
152
|
-
return pApplet.savePath(filename);
|
153
|
-
} else {
|
154
|
-
File file = new File(filename);
|
155
|
-
if (file.isAbsolute()) {
|
156
|
-
// make sure that the intermediate folders have been created
|
157
|
-
PathUtil.createPath(file);
|
158
|
-
return filename;
|
159
|
-
} else {
|
160
|
-
String msg =
|
161
|
-
"PImage.save() requires an absolute path. " +
|
162
|
-
"Use createImage(), or pass savePath() to save().";
|
163
|
-
|
164
|
-
throw new SaveImageException(msg);
|
165
|
-
}
|
166
|
-
}
|
167
|
-
}
|
168
|
-
|
169
|
-
}
|