propane 3.4.0-java → 3.7.0.pre-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/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
- data/.mvn/wrapper/maven-wrapper.properties +2 -2
- data/.travis.yml +2 -2
- data/CHANGELOG.md +12 -0
- data/Gemfile +2 -0
- data/README.md +17 -8
- data/Rakefile +10 -11
- data/bin/propane +3 -1
- data/lib/propane.rb +6 -4
- data/lib/propane/app.rb +20 -10
- data/lib/propane/creators/sketch_class.rb +7 -1
- data/lib/propane/creators/sketch_factory.rb +4 -2
- data/lib/propane/creators/sketch_writer.rb +1 -0
- data/lib/propane/helper_methods.rb +23 -24
- data/lib/propane/helpers/numeric.rb +2 -0
- data/lib/propane/helpers/version_error.rb +1 -0
- data/lib/propane/library.rb +5 -1
- data/lib/propane/library_loader.rb +2 -0
- data/lib/propane/native_folder.rb +10 -9
- data/lib/propane/native_loader.rb +3 -0
- data/lib/propane/runner.rb +14 -6
- data/lib/propane/version.rb +2 -1
- data/library/boids/boids.rb +21 -11
- data/library/color_group/color_group.rb +28 -0
- data/library/control_panel/control_panel.rb +8 -5
- data/library/dxf/dxf.rb +6 -0
- data/library/file_chooser/chooser.rb +10 -9
- data/library/file_chooser/file_chooser.rb +10 -9
- data/library/library_proxy/library_proxy.rb +2 -0
- data/library/net/net.rb +7 -0
- data/library/simplex_noise/simplex_noise.rb +2 -0
- data/library/slider/slider.rb +23 -22
- data/library/vector_utils/vector_utils.rb +4 -0
- data/library/video_event/video_event.rb +4 -1
- data/pom.rb +37 -36
- data/pom.xml +7 -7
- data/propane.gemspec +16 -12
- data/src/main/java/monkstone/ColorUtil.java +13 -1
- data/src/main/java/monkstone/MathToolModule.java +253 -203
- data/src/main/java/monkstone/PropaneLibrary.java +2 -2
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
- data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -3
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
- data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
- data/src/main/java/processing/awt/PImageAWT.java +377 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
- data/src/main/java/processing/awt/PSurfaceAWT.java +309 -209
- data/src/main/java/processing/awt/ShimAWT.java +581 -0
- data/src/main/java/processing/core/PApplet.java +4510 -4503
- data/src/main/java/processing/core/PConstants.java +477 -447
- data/src/main/java/processing/core/PFont.java +914 -880
- data/src/main/java/processing/core/PGraphics.java +193 -177
- data/src/main/java/processing/core/PImage.java +611 -309
- data/src/main/java/processing/core/PMatrix.java +172 -159
- data/src/main/java/processing/core/PMatrix2D.java +478 -415
- data/src/main/java/processing/core/PMatrix3D.java +762 -735
- data/src/main/java/processing/core/PShape.java +2888 -2652
- data/src/main/java/processing/core/PShapeOBJ.java +97 -92
- data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
- data/src/main/java/processing/core/PStyle.java +40 -37
- data/src/main/java/processing/core/PSurface.java +139 -97
- data/src/main/java/processing/core/PSurfaceNone.java +296 -218
- data/src/main/java/processing/core/PVector.java +997 -965
- data/src/main/java/processing/core/ThinkDifferent.java +15 -13
- data/src/main/java/processing/data/DoubleDict.java +756 -710
- data/src/main/java/processing/data/DoubleList.java +749 -696
- data/src/main/java/processing/data/FloatDict.java +748 -702
- data/src/main/java/processing/data/FloatList.java +751 -697
- data/src/main/java/processing/data/IntDict.java +720 -673
- data/src/main/java/processing/data/IntList.java +699 -633
- data/src/main/java/processing/data/JSONArray.java +931 -873
- data/src/main/java/processing/data/JSONObject.java +1262 -1165
- data/src/main/java/processing/data/JSONTokener.java +351 -341
- data/src/main/java/processing/data/LongDict.java +710 -663
- data/src/main/java/processing/data/LongList.java +701 -635
- data/src/main/java/processing/data/Sort.java +37 -41
- data/src/main/java/processing/data/StringDict.java +525 -486
- data/src/main/java/processing/data/StringList.java +626 -580
- data/src/main/java/processing/data/Table.java +3690 -3510
- data/src/main/java/processing/data/TableRow.java +182 -183
- data/src/main/java/processing/data/XML.java +957 -883
- data/src/main/java/processing/dxf/RawDXF.java +404 -0
- data/src/main/java/processing/event/Event.java +87 -67
- data/src/main/java/processing/event/KeyEvent.java +48 -41
- data/src/main/java/processing/event/MouseEvent.java +88 -113
- data/src/main/java/processing/event/TouchEvent.java +10 -6
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
- data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
- 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 +289 -270
- data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
- data/src/main/java/processing/opengl/LinePath.java +547 -500
- data/src/main/java/processing/opengl/LineStroker.java +588 -581
- data/src/main/java/processing/opengl/PGL.java +3047 -2914
- data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
- data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
- data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
- data/src/main/java/processing/opengl/PShader.java +1266 -1257
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
- data/src/main/java/processing/opengl/Texture.java +1492 -1401
- data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
- data/test/create_test.rb +21 -20
- data/test/deglut_spec_test.rb +4 -2
- data/test/helper_methods_test.rb +49 -20
- data/test/math_tool_test.rb +39 -32
- data/test/native_folder.rb +47 -0
- data/test/respond_to_test.rb +3 -2
- data/test/sketches/key_event.rb +2 -2
- data/test/sketches/library/my_library/my_library.rb +3 -0
- data/test/test_helper.rb +2 -0
- data/test/vecmath_spec_test.rb +35 -22
- data/vendors/Rakefile +33 -62
- metadata +56 -48
- 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/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,73 +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.load;
|
26
|
-
|
27
|
-
import processing.core.PApplet;
|
28
|
-
import processing.core.PImage;
|
29
|
-
|
30
|
-
import javax.swing.*;
|
31
|
-
import java.awt.*;
|
32
|
-
import java.awt.color.ColorSpace;
|
33
|
-
import java.awt.image.BufferedImage;
|
34
|
-
import java.util.Base64;
|
35
|
-
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Strategy for loading images from Base64 strings.
|
39
|
-
*/
|
40
|
-
public class Base64StringImageLoadStrategy implements ImageLoadStrategy {
|
41
|
-
|
42
|
-
@Override
|
43
|
-
public PImage load(PApplet pApplet, String content, String extension) {
|
44
|
-
byte[] decodedBytes = Base64.getDecoder().decode(content);
|
45
|
-
|
46
|
-
if(decodedBytes == null){
|
47
|
-
System.err.println("Decode Error on image: " + content.substring(0, 20));
|
48
|
-
return null;
|
49
|
-
}
|
50
|
-
|
51
|
-
Image awtImage = new ImageIcon(decodedBytes).getImage();
|
52
|
-
|
53
|
-
if (awtImage instanceof BufferedImage) {
|
54
|
-
BufferedImage buffImage = (BufferedImage) awtImage;
|
55
|
-
int space = buffImage.getColorModel().getColorSpace().getType();
|
56
|
-
if (space == ColorSpace.TYPE_CMYK) {
|
57
|
-
return null;
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
PImage loadedImage = new PImage(
|
62
|
-
awtImage,
|
63
|
-
ImageLoadUtil.checkExtensionRequiresAlpha(extension)
|
64
|
-
);
|
65
|
-
|
66
|
-
if (loadedImage.width == -1) {
|
67
|
-
// error...
|
68
|
-
}
|
69
|
-
|
70
|
-
return loadedImage;
|
71
|
-
}
|
72
|
-
|
73
|
-
}
|
@@ -1,70 +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.load;
|
26
|
-
|
27
|
-
import processing.core.PApplet;
|
28
|
-
import processing.core.PImage;
|
29
|
-
|
30
|
-
|
31
|
-
/**
|
32
|
-
* Image load strategy which uses a secondary strategy if failed.
|
33
|
-
*
|
34
|
-
* <p>
|
35
|
-
* Image loading strategy strategy which attempts to load an image first through a "primary
|
36
|
-
* strategy" and, if the primary failed, it then attemps loading through an alternative "secondary
|
37
|
-
* strategy".
|
38
|
-
* </p>
|
39
|
-
*/
|
40
|
-
public class FallbackImageLoadStrategy implements ImageLoadStrategy {
|
41
|
-
|
42
|
-
private ImageLoadStrategy primaryStrategy;
|
43
|
-
private ImageLoadStrategy secondaryStrategy;
|
44
|
-
|
45
|
-
/**
|
46
|
-
* Create a new fallback image loading strategy.
|
47
|
-
*
|
48
|
-
* @param newPrimaryStrategy The strategy to try first.
|
49
|
-
* @param newSecondaryStrategy The strategy to try if the first fails.
|
50
|
-
*/
|
51
|
-
public FallbackImageLoadStrategy(ImageLoadStrategy newPrimaryStrategy,
|
52
|
-
ImageLoadStrategy newSecondaryStrategy) {
|
53
|
-
|
54
|
-
primaryStrategy = newPrimaryStrategy;
|
55
|
-
secondaryStrategy = newSecondaryStrategy;
|
56
|
-
}
|
57
|
-
|
58
|
-
@Override
|
59
|
-
public PImage load(PApplet pApplet, String path, String extension) {
|
60
|
-
try {
|
61
|
-
return primaryStrategy.load(pApplet, path, extension);
|
62
|
-
} catch (Exception e) {
|
63
|
-
// show error, but move on to the stuff below, see if it'll work
|
64
|
-
e.printStackTrace();
|
65
|
-
|
66
|
-
return secondaryStrategy.load(pApplet, path, extension);
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
|
-
}
|
@@ -1,132 +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
|
-
|
26
|
-
package processing.core.util.image.load;
|
27
|
-
|
28
|
-
import processing.core.PApplet;
|
29
|
-
import processing.core.PImage;
|
30
|
-
import processing.core.util.io.InputFactory;
|
31
|
-
|
32
|
-
import javax.imageio.ImageIO;
|
33
|
-
import java.awt.image.BufferedImage;
|
34
|
-
import java.io.IOException;
|
35
|
-
import java.io.InputStream;
|
36
|
-
import java.util.concurrent.atomic.AtomicReference;
|
37
|
-
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Use Java 1.4 ImageIO methods to load an image.
|
41
|
-
*/
|
42
|
-
public class ImageIoImageLoadStrategy implements ImageLoadStrategy {
|
43
|
-
|
44
|
-
private final AtomicReference<String[]> cachedLoadImageFormats;
|
45
|
-
|
46
|
-
public ImageIoImageLoadStrategy() {
|
47
|
-
cachedLoadImageFormats = new AtomicReference<>(null);
|
48
|
-
}
|
49
|
-
|
50
|
-
/**
|
51
|
-
* Load an image after checking that its format is supported.
|
52
|
-
*
|
53
|
-
* @param pApplet The PApplet on whose behalf an image is being loaded. If null, cannot use sketch
|
54
|
-
* relative file paths.
|
55
|
-
* @param path The path to the file like "subdirectory/file.png". Note that paths without
|
56
|
-
* extensions are supported and the extension is not read off this path but instead must be
|
57
|
-
* specified in the extension parameter.
|
58
|
-
* @param extension The extension of the file to open.
|
59
|
-
* @return The newly loaded image.
|
60
|
-
*/
|
61
|
-
@Override
|
62
|
-
public PImage load(PApplet pApplet, String path, String extension) {
|
63
|
-
String[] loadImageFormats = getLoadImageFormats();
|
64
|
-
|
65
|
-
if (loadImageFormats != null) {
|
66
|
-
for (String loadImageFormat : loadImageFormats) {
|
67
|
-
if (extension.equals(loadImageFormat)) {
|
68
|
-
return loadImageIOInner(pApplet, path);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
// failed, could not load image after all those attempts
|
74
|
-
System.err.println("Could not find a method to load " + path);
|
75
|
-
return null;
|
76
|
-
}
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Get the list of supported image formats.
|
80
|
-
*
|
81
|
-
* @return List of image formats like "png" that are supported by this strategy.
|
82
|
-
*/
|
83
|
-
private String[] getLoadImageFormats() {
|
84
|
-
cachedLoadImageFormats.compareAndSet(null, ImageIO.getReaderFormatNames());
|
85
|
-
return cachedLoadImageFormats.get();
|
86
|
-
}
|
87
|
-
|
88
|
-
/**
|
89
|
-
* Load an image without checking that its format is supported.
|
90
|
-
*
|
91
|
-
* @param pApplet The PApplet on whose behalf an image is being loaded. If null, cannot use sketch
|
92
|
-
* relative file paths.
|
93
|
-
* @param path The path to the file like "subdirectory/file.png". Note that paths without
|
94
|
-
* extensions are supported and the extension is not read off this path but instead must be
|
95
|
-
* specified in the extension parameter.
|
96
|
-
* @return The newly loaded image.
|
97
|
-
*/
|
98
|
-
private PImage loadImageIOInner(PApplet pApplet, String filename) {
|
99
|
-
InputStream stream = InputFactory.createInput(pApplet, filename);
|
100
|
-
if (stream == null) {
|
101
|
-
System.err.println("The image " + filename + " could not be found.");
|
102
|
-
return null;
|
103
|
-
}
|
104
|
-
|
105
|
-
try {
|
106
|
-
BufferedImage bi = ImageIO.read(stream);
|
107
|
-
|
108
|
-
int width = bi.getWidth();
|
109
|
-
int height = bi.getHeight();
|
110
|
-
int[] pixels = new int[width * height];
|
111
|
-
|
112
|
-
bi.getRGB(0, 0, width, height, pixels, 0, width);
|
113
|
-
|
114
|
-
// check the alpha for this image
|
115
|
-
// was gonna call getType() on the image to see if RGB or ARGB,
|
116
|
-
// but it's not actually useful, since gif images will come through
|
117
|
-
// as TYPE_BYTE_INDEXED, which means it'll still have to check for
|
118
|
-
// the transparency. also, would have to iterate through all the other
|
119
|
-
// types and guess whether alpha was in there, so.. just gonna stick
|
120
|
-
// with the old method.
|
121
|
-
PImage outgoing = new PImage(width, height, pixels, true, pApplet);
|
122
|
-
|
123
|
-
stream.close();
|
124
|
-
// return the image
|
125
|
-
return outgoing;
|
126
|
-
|
127
|
-
} catch (IOException e) {
|
128
|
-
return null;
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
}
|
@@ -1,48 +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.load;
|
26
|
-
|
27
|
-
import processing.core.PApplet;
|
28
|
-
import processing.core.PImage;
|
29
|
-
|
30
|
-
|
31
|
-
/**
|
32
|
-
* Interface for strategies to load different image formats and through different methods.
|
33
|
-
*/
|
34
|
-
public interface ImageLoadStrategy {
|
35
|
-
|
36
|
-
/**
|
37
|
-
* Load an image.
|
38
|
-
*
|
39
|
-
* @param pApplet The PApplet on whose behalf an image is being loaded.
|
40
|
-
* @param path The path to the file like "subdirectory/file.png". Note that paths without
|
41
|
-
* extensions are supported and the extension is not read off this path but instead must be
|
42
|
-
* specified in the extension parameter.
|
43
|
-
* @param extension The extension of the file to open.
|
44
|
-
* @return The PImage loaded from the given path.
|
45
|
-
*/
|
46
|
-
PImage load(PApplet pApplet, String path, String extension);
|
47
|
-
|
48
|
-
}
|
@@ -1,45 +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.load;
|
26
|
-
|
27
|
-
|
28
|
-
/**
|
29
|
-
* Convenience functions for use while loading images.
|
30
|
-
*/
|
31
|
-
public class ImageLoadUtil {
|
32
|
-
|
33
|
-
/**
|
34
|
-
* Determine if a file requires alpha channel checking.
|
35
|
-
*
|
36
|
-
* @param extension The file extension.
|
37
|
-
* @return True if one needs to look for alpha channel and false otherwise.
|
38
|
-
*/
|
39
|
-
public static boolean checkExtensionRequiresAlpha(String extension) {
|
40
|
-
return extension.equals("gif") ||
|
41
|
-
extension.equals("png") ||
|
42
|
-
extension.equals("unknown");
|
43
|
-
}
|
44
|
-
|
45
|
-
}
|
@@ -1,255 +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.load;
|
26
|
-
|
27
|
-
import processing.core.PApplet;
|
28
|
-
import processing.core.PConstants;
|
29
|
-
import processing.core.PImage;
|
30
|
-
|
31
|
-
import java.io.IOException;
|
32
|
-
import java.io.InputStream;
|
33
|
-
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Strategy for loading a RLE-compressed TGA image.
|
37
|
-
*/
|
38
|
-
public class TgaImageLoadStrategy implements ImageLoadStrategy {
|
39
|
-
|
40
|
-
@Override
|
41
|
-
public PImage load(PApplet pApplet, String path, String extension) {
|
42
|
-
try {
|
43
|
-
PImage image = loadNoCatch(pApplet, path);
|
44
|
-
return image;
|
45
|
-
} catch (IOException e) {
|
46
|
-
e.printStackTrace();
|
47
|
-
return null;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
/**
|
52
|
-
* Targa image loader for RLE-compressed TGA files which throws exceptions.
|
53
|
-
* <p>
|
54
|
-
* Rewritten for 0115 to read/write RLE-encoded targa images.
|
55
|
-
* For 0125, non-RLE encoded images are now supported, along with
|
56
|
-
* images whose y-order is reversed (which is standard for TGA files).
|
57
|
-
* <p>
|
58
|
-
* A version of this function is in MovieMaker.java. Any fixes here
|
59
|
-
* should be applied over in MovieMaker as well.
|
60
|
-
* <p>
|
61
|
-
* Known issue with RLE encoding and odd behavior in some apps:
|
62
|
-
* https://github.com/processing/processing/issues/2096
|
63
|
-
* Please help!
|
64
|
-
*/
|
65
|
-
private PImage loadNoCatch(PApplet pApplet, String filename) throws IOException {
|
66
|
-
InputStream is = pApplet.createInput(filename);
|
67
|
-
if (is == null) return null;
|
68
|
-
|
69
|
-
byte header[] = new byte[18];
|
70
|
-
int offset = 0;
|
71
|
-
do {
|
72
|
-
int count = is.read(header, offset, header.length - offset);
|
73
|
-
if (count == -1) return null;
|
74
|
-
offset += count;
|
75
|
-
} while (offset < 18);
|
76
|
-
|
77
|
-
/*
|
78
|
-
header[2] image type code
|
79
|
-
2 (0x02) - Uncompressed, RGB images.
|
80
|
-
3 (0x03) - Uncompressed, black and white images.
|
81
|
-
10 (0x0A) - Run-length encoded RGB images.
|
82
|
-
11 (0x0B) - Compressed, black and white images. (grayscale?)
|
83
|
-
|
84
|
-
header[16] is the bit depth (8, 24, 32)
|
85
|
-
|
86
|
-
header[17] image descriptor (packed bits)
|
87
|
-
0x20 is 32 = origin upper-left
|
88
|
-
0x28 is 32 + 8 = origin upper-left + 32 bits
|
89
|
-
|
90
|
-
7 6 5 4 3 2 1 0
|
91
|
-
128 64 32 16 8 4 2 1
|
92
|
-
*/
|
93
|
-
|
94
|
-
int format = 0;
|
95
|
-
|
96
|
-
if (((header[2] == 3) || (header[2] == 11)) && // B&W, plus RLE or not
|
97
|
-
(header[16] == 8) && // 8 bits
|
98
|
-
((header[17] == 0x8) || (header[17] == 0x28))) { // origin, 32 bit
|
99
|
-
format = PConstants.ALPHA;
|
100
|
-
|
101
|
-
} else if (((header[2] == 2) || (header[2] == 10)) && // RGB, RLE or not
|
102
|
-
(header[16] == 24) && // 24 bits
|
103
|
-
((header[17] == 0x20) || (header[17] == 0))) { // origin
|
104
|
-
format = PConstants.RGB;
|
105
|
-
|
106
|
-
} else if (((header[2] == 2) || (header[2] == 10)) &&
|
107
|
-
(header[16] == 32) &&
|
108
|
-
((header[17] == 0x8) || (header[17] == 0x28))) { // origin, 32
|
109
|
-
format = PConstants.ARGB;
|
110
|
-
}
|
111
|
-
|
112
|
-
if (format == 0) {
|
113
|
-
System.err.println("Unknown .tga file format for " + filename);
|
114
|
-
//" (" + header[2] + " " +
|
115
|
-
//(header[16] & 0xff) + " " +
|
116
|
-
//hex(header[17], 2) + ")");
|
117
|
-
return null;
|
118
|
-
}
|
119
|
-
|
120
|
-
int w = ((header[13] & 0xff) << 8) + (header[12] & 0xff);
|
121
|
-
int h = ((header[15] & 0xff) << 8) + (header[14] & 0xff);
|
122
|
-
PImage outgoing = pApplet.createImage(w, h, format);
|
123
|
-
|
124
|
-
// where "reversed" means upper-left corner (normal for most of
|
125
|
-
// the modernized world, but "reversed" for the tga spec)
|
126
|
-
//boolean reversed = (header[17] & 0x20) != 0;
|
127
|
-
// https://github.com/processing/processing/issues/1682
|
128
|
-
boolean reversed = (header[17] & 0x20) == 0;
|
129
|
-
|
130
|
-
if ((header[2] == 2) || (header[2] == 3)) { // not RLE encoded
|
131
|
-
if (reversed) {
|
132
|
-
int index = (h-1) * w;
|
133
|
-
switch (format) {
|
134
|
-
case PConstants.ALPHA:
|
135
|
-
for (int y = h-1; y >= 0; y--) {
|
136
|
-
for (int x = 0; x < w; x++) {
|
137
|
-
outgoing.pixels[index + x] = is.read();
|
138
|
-
}
|
139
|
-
index -= w;
|
140
|
-
}
|
141
|
-
break;
|
142
|
-
case PConstants.RGB:
|
143
|
-
for (int y = h-1; y >= 0; y--) {
|
144
|
-
for (int x = 0; x < w; x++) {
|
145
|
-
outgoing.pixels[index + x] =
|
146
|
-
is.read() | (is.read() << 8) | (is.read() << 16) |
|
147
|
-
0xff000000;
|
148
|
-
}
|
149
|
-
index -= w;
|
150
|
-
}
|
151
|
-
break;
|
152
|
-
case PConstants.ARGB:
|
153
|
-
for (int y = h-1; y >= 0; y--) {
|
154
|
-
for (int x = 0; x < w; x++) {
|
155
|
-
outgoing.pixels[index + x] =
|
156
|
-
is.read() | (is.read() << 8) | (is.read() << 16) |
|
157
|
-
(is.read() << 24);
|
158
|
-
}
|
159
|
-
index -= w;
|
160
|
-
}
|
161
|
-
}
|
162
|
-
} else { // not reversed
|
163
|
-
int count = w * h;
|
164
|
-
switch (format) {
|
165
|
-
case PConstants.ALPHA:
|
166
|
-
for (int i = 0; i < count; i++) {
|
167
|
-
outgoing.pixels[i] = is.read();
|
168
|
-
}
|
169
|
-
break;
|
170
|
-
case PConstants.RGB:
|
171
|
-
for (int i = 0; i < count; i++) {
|
172
|
-
outgoing.pixels[i] =
|
173
|
-
is.read() | (is.read() << 8) | (is.read() << 16) |
|
174
|
-
0xff000000;
|
175
|
-
}
|
176
|
-
break;
|
177
|
-
case PConstants.ARGB:
|
178
|
-
for (int i = 0; i < count; i++) {
|
179
|
-
outgoing.pixels[i] =
|
180
|
-
is.read() | (is.read() << 8) | (is.read() << 16) |
|
181
|
-
(is.read() << 24);
|
182
|
-
}
|
183
|
-
break;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
} else { // header[2] is 10 or 11
|
188
|
-
int index = 0;
|
189
|
-
int px[] = outgoing.pixels;
|
190
|
-
|
191
|
-
while (index < px.length) {
|
192
|
-
int num = is.read();
|
193
|
-
boolean isRLE = (num & 0x80) != 0;
|
194
|
-
if (isRLE) {
|
195
|
-
num -= 127; // (num & 0x7F) + 1
|
196
|
-
int pixel = 0;
|
197
|
-
switch (format) {
|
198
|
-
case PConstants.ALPHA:
|
199
|
-
pixel = is.read();
|
200
|
-
break;
|
201
|
-
case PConstants.RGB:
|
202
|
-
pixel = 0xFF000000 |
|
203
|
-
is.read() | (is.read() << 8) | (is.read() << 16);
|
204
|
-
//(is.read() << 16) | (is.read() << 8) | is.read();
|
205
|
-
break;
|
206
|
-
case PConstants.ARGB:
|
207
|
-
pixel = is.read() |
|
208
|
-
(is.read() << 8) | (is.read() << 16) | (is.read() << 24);
|
209
|
-
break;
|
210
|
-
}
|
211
|
-
for (int i = 0; i < num; i++) {
|
212
|
-
px[index++] = pixel;
|
213
|
-
if (index == px.length) break;
|
214
|
-
}
|
215
|
-
} else { // write up to 127 bytes as uncompressed
|
216
|
-
num += 1;
|
217
|
-
switch (format) {
|
218
|
-
case PConstants.ALPHA:
|
219
|
-
for (int i = 0; i < num; i++) {
|
220
|
-
px[index++] = is.read();
|
221
|
-
}
|
222
|
-
break;
|
223
|
-
case PConstants.RGB:
|
224
|
-
for (int i = 0; i < num; i++) {
|
225
|
-
px[index++] = 0xFF000000 |
|
226
|
-
is.read() | (is.read() << 8) | (is.read() << 16);
|
227
|
-
//(is.read() << 16) | (is.read() << 8) | is.read();
|
228
|
-
}
|
229
|
-
break;
|
230
|
-
case PConstants.ARGB:
|
231
|
-
for (int i = 0; i < num; i++) {
|
232
|
-
px[index++] = is.read() | //(is.read() << 24) |
|
233
|
-
(is.read() << 8) | (is.read() << 16) | (is.read() << 24);
|
234
|
-
//(is.read() << 16) | (is.read() << 8) | is.read();
|
235
|
-
}
|
236
|
-
break;
|
237
|
-
}
|
238
|
-
}
|
239
|
-
}
|
240
|
-
|
241
|
-
if (!reversed) {
|
242
|
-
int[] temp = new int[w];
|
243
|
-
for (int y = 0; y < h/2; y++) {
|
244
|
-
int z = (h-1) - y;
|
245
|
-
System.arraycopy(px, y*w, temp, 0, w);
|
246
|
-
System.arraycopy(px, z*w, px, y*w, w);
|
247
|
-
System.arraycopy(temp, 0, px, z*w, w);
|
248
|
-
}
|
249
|
-
}
|
250
|
-
}
|
251
|
-
is.close();
|
252
|
-
return outgoing;
|
253
|
-
}
|
254
|
-
|
255
|
-
}
|