propane 3.3.1-java → 3.6.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -2
- data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
- data/.mvn/wrapper/maven-wrapper.properties +2 -3
- data/.travis.yml +9 -0
- data/CHANGELOG.md +17 -5
- data/Gemfile +2 -0
- data/README.md +17 -8
- data/Rakefile +16 -30
- 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 +21 -15
- 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/mvnw +127 -51
- data/mvnw.cmd +182 -145
- data/pom.rb +53 -50
- data/pom.xml +17 -8
- data/propane.gemspec +13 -11
- 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 +2 -2
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- 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 +2164 -1661
- data/src/main/java/processing/awt/PImageAWT.java +377 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +280 -268
- data/src/main/java/processing/awt/PSurfaceAWT.java +942 -829
- data/src/main/java/processing/awt/ShimAWT.java +581 -0
- data/src/main/java/processing/core/PApplet.java +831 -824
- 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 +229 -213
- data/src/main/java/processing/core/PImage.java +620 -318
- data/src/main/java/processing/core/PMatrix.java +172 -159
- data/src/main/java/processing/core/PMatrix2D.java +478 -409
- 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 +436 -415
- data/src/main/java/processing/core/PShapeSVG.java +1702 -1479
- 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 -208
- data/src/main/java/processing/core/PVector.java +997 -965
- data/src/main/java/processing/core/ThinkDifferent.java +12 -17
- 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 -66
- 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 +54 -45
- 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,98 +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
|
-
import processing.core.util.image.constants.TifConstants;
|
31
|
-
|
32
|
-
|
33
|
-
/**
|
34
|
-
* Strategy for loading a tif image.
|
35
|
-
*/
|
36
|
-
public class TiffImageLoadStrategy implements ImageLoadStrategy {
|
37
|
-
|
38
|
-
@Override
|
39
|
-
public PImage load(PApplet pApplet, String path, String extension) {
|
40
|
-
byte bytes[] = pApplet.loadBytes(path);
|
41
|
-
PImage image = (bytes == null) ? null : loadFromBytes(bytes);
|
42
|
-
return image;
|
43
|
-
}
|
44
|
-
|
45
|
-
/**
|
46
|
-
* Load the tif image from bytes.
|
47
|
-
*
|
48
|
-
* @param tiff The bytes of the tif image.
|
49
|
-
* @return PImage created from the provided bytes.
|
50
|
-
*/
|
51
|
-
private PImage loadFromBytes(byte[] tiff) {
|
52
|
-
if ((tiff[42] != tiff[102]) || // width/height in both places
|
53
|
-
(tiff[43] != tiff[103])) {
|
54
|
-
System.err.println(TifConstants.TIFF_ERROR);
|
55
|
-
return null;
|
56
|
-
}
|
57
|
-
|
58
|
-
int width =
|
59
|
-
((tiff[30] & 0xff) << 8) | (tiff[31] & 0xff);
|
60
|
-
int height =
|
61
|
-
((tiff[42] & 0xff) << 8) | (tiff[43] & 0xff);
|
62
|
-
|
63
|
-
int count =
|
64
|
-
((tiff[114] & 0xff) << 24) |
|
65
|
-
((tiff[115] & 0xff) << 16) |
|
66
|
-
((tiff[116] & 0xff) << 8) |
|
67
|
-
(tiff[117] & 0xff);
|
68
|
-
if (count != width * height * 3) {
|
69
|
-
System.err.println(TifConstants.TIFF_ERROR + " (" + width + ", " + height +")");
|
70
|
-
return null;
|
71
|
-
}
|
72
|
-
|
73
|
-
// check the rest of the header
|
74
|
-
for (int i = 0; i < TifConstants.TIFF_HEADER.length; i++) {
|
75
|
-
if ((i == 30) || (i == 31) || (i == 42) || (i == 43) ||
|
76
|
-
(i == 102) || (i == 103) ||
|
77
|
-
(i == 114) || (i == 115) || (i == 116) || (i == 117)) continue;
|
78
|
-
|
79
|
-
if (tiff[i] != TifConstants.TIFF_HEADER[i]) {
|
80
|
-
System.err.println(TifConstants.TIFF_ERROR + " (" + i + ")");
|
81
|
-
return null;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
PImage outgoing = new PImage(width, height, PConstants.RGB);
|
86
|
-
int index = 768;
|
87
|
-
count /= 3;
|
88
|
-
for (int i = 0; i < count; i++) {
|
89
|
-
outgoing.pixels[i] =
|
90
|
-
0xFF000000 |
|
91
|
-
(tiff[index++] & 0xff) << 16 |
|
92
|
-
(tiff[index++] & 0xff) << 8 |
|
93
|
-
(tiff[index++] & 0xff);
|
94
|
-
}
|
95
|
-
return outgoing;
|
96
|
-
}
|
97
|
-
|
98
|
-
}
|
@@ -1,49 +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.save;
|
26
|
-
|
27
|
-
import java.io.IOException;
|
28
|
-
|
29
|
-
|
30
|
-
/**
|
31
|
-
* Interface for strategies that can save images to different formats or via different methods.
|
32
|
-
*/
|
33
|
-
public interface ImageSaveStrategy {
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Save an image.
|
37
|
-
*
|
38
|
-
* @param pixels The raw pixel values (described by format) to be saved.
|
39
|
-
* @param pixelWidth The width of the image in pixels.
|
40
|
-
* @param pixelHeight The height of the image in pixels.
|
41
|
-
* @param format The format as described in PConstants like PConstants.RGB.
|
42
|
-
* @param filename The path to which the image should be written.
|
43
|
-
* @return True if writting succeeded and false otherwise.
|
44
|
-
* @throws IOException Thrown if the file writing encountered an unexpected error.
|
45
|
-
*/
|
46
|
-
boolean save(int[] pixels, int pixelWidth, int pixelHeight, int format,
|
47
|
-
String filename) throws IOException;
|
48
|
-
|
49
|
-
}
|
@@ -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.save;
|
26
|
-
|
27
|
-
import java.io.BufferedOutputStream;
|
28
|
-
import java.io.FileNotFoundException;
|
29
|
-
import java.io.FileOutputStream;
|
30
|
-
import java.io.OutputStream;
|
31
|
-
|
32
|
-
|
33
|
-
/**
|
34
|
-
* Common convenience functions for file saving.
|
35
|
-
*/
|
36
|
-
public class ImageSaveUtil {
|
37
|
-
|
38
|
-
/**
|
39
|
-
* Create an output stream for a file.
|
40
|
-
*
|
41
|
-
* @param filename The filename at which the output stream should be created.
|
42
|
-
* @return The newly created output stream.
|
43
|
-
*/
|
44
|
-
public static OutputStream createForFile(String filename) throws FileNotFoundException {
|
45
|
-
return new BufferedOutputStream(new FileOutputStream(filename), 32768);
|
46
|
-
}
|
47
|
-
|
48
|
-
}
|
@@ -1,179 +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.save;
|
26
|
-
|
27
|
-
import processing.core.PApplet;
|
28
|
-
import processing.core.PConstants;
|
29
|
-
import processing.core.util.io.PathUtil;
|
30
|
-
|
31
|
-
import javax.imageio.*;
|
32
|
-
import javax.imageio.metadata.IIOInvalidTreeException;
|
33
|
-
import javax.imageio.metadata.IIOMetadata;
|
34
|
-
import javax.imageio.metadata.IIOMetadataNode;
|
35
|
-
import java.awt.image.BufferedImage;
|
36
|
-
import java.io.BufferedOutputStream;
|
37
|
-
import java.io.File;
|
38
|
-
import java.io.IOException;
|
39
|
-
import java.util.Iterator;
|
40
|
-
|
41
|
-
|
42
|
-
/**
|
43
|
-
* Strategy to use ImageIO functions to save an image.
|
44
|
-
*/
|
45
|
-
public class ImageWriterImageSaveStrategy implements ImageSaveStrategy {
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Use ImageIO functions from Java 1.4 and later to handle image save.
|
49
|
-
* Various formats are supported, typically jpeg, png, bmp, and wbmp.
|
50
|
-
* To get a list of the supported formats for writing, use: <BR>
|
51
|
-
* <TT>println(javax.imageio.ImageIO.getReaderFormatNames())</TT>
|
52
|
-
*/
|
53
|
-
@Override
|
54
|
-
public boolean save(int[] pixels, int pixelWidth, int pixelHeight, int format,
|
55
|
-
String path) throws IOException {
|
56
|
-
|
57
|
-
try {
|
58
|
-
int outputFormat = (format == PConstants.ARGB) ?
|
59
|
-
BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
|
60
|
-
|
61
|
-
String extension = PathUtil.cleanExtension(
|
62
|
-
PathUtil.parseExtension(path)
|
63
|
-
);
|
64
|
-
|
65
|
-
// JPEG and BMP images that have an alpha channel set get pretty unhappy.
|
66
|
-
// BMP just doesn't write, and JPEG writes it as a CMYK image.
|
67
|
-
// http://code.google.com/p/processing/issues/detail?id=415
|
68
|
-
if (isRgbImage(extension)) {
|
69
|
-
outputFormat = BufferedImage.TYPE_INT_RGB;
|
70
|
-
}
|
71
|
-
|
72
|
-
BufferedImage bimage = new BufferedImage(pixelWidth, pixelHeight, outputFormat);
|
73
|
-
bimage.setRGB(0, 0, pixelWidth, pixelHeight, pixels, 0, pixelWidth);
|
74
|
-
|
75
|
-
File file = new File(path);
|
76
|
-
|
77
|
-
ImageWriter writer = null;
|
78
|
-
ImageWriteParam param = null;
|
79
|
-
IIOMetadata metadata = null;
|
80
|
-
|
81
|
-
if (isJpeg(extension)) {
|
82
|
-
if ((writer = getImageIoWriter("jpeg")) != null) {
|
83
|
-
// Set JPEG quality to 90% with baseline optimization. Setting this
|
84
|
-
// to 1 was a huge jump (about triple the size), so this seems good.
|
85
|
-
// Oddly, a smaller file size than Photoshop at 90%, but I suppose
|
86
|
-
// it's a completely different algorithm.
|
87
|
-
param = writer.getDefaultWriteParam();
|
88
|
-
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
89
|
-
param.setCompressionQuality(0.9f);
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
if (isPng(extension)) {
|
94
|
-
if ((writer = getImageIoWriter("png")) != null) {
|
95
|
-
param = writer.getDefaultWriteParam();
|
96
|
-
if (false) {
|
97
|
-
metadata = getImageIoDpi(writer, param, 100);
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
|
-
|
102
|
-
if (writer != null) {
|
103
|
-
BufferedOutputStream output =
|
104
|
-
new BufferedOutputStream(PApplet.createOutput(file));
|
105
|
-
writer.setOutput(ImageIO.createImageOutputStream(output));
|
106
|
-
// writer.write(null, new IIOImage(bimage, null, null), param);
|
107
|
-
writer.write(metadata, new IIOImage(bimage, null, metadata), param);
|
108
|
-
writer.dispose();
|
109
|
-
|
110
|
-
output.flush();
|
111
|
-
output.close();
|
112
|
-
return true;
|
113
|
-
}
|
114
|
-
// If iter.hasNext() somehow fails up top, it falls through to here
|
115
|
-
return javax.imageio.ImageIO.write(bimage, extension, file);
|
116
|
-
|
117
|
-
} catch (Exception e) {
|
118
|
-
e.printStackTrace();
|
119
|
-
throw new IOException("image save failed.");
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
private ImageWriter getImageIoWriter(String extension) {
|
124
|
-
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(extension);
|
125
|
-
if (iter.hasNext()) {
|
126
|
-
return iter.next();
|
127
|
-
}
|
128
|
-
return null;
|
129
|
-
}
|
130
|
-
|
131
|
-
private IIOMetadata getImageIoDpi(ImageWriter writer, ImageWriteParam param, double dpi) {
|
132
|
-
// http://stackoverflow.com/questions/321736/how-to-set-dpi-information-in-an-image
|
133
|
-
ImageTypeSpecifier typeSpecifier =
|
134
|
-
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
|
135
|
-
IIOMetadata metadata =
|
136
|
-
writer.getDefaultImageMetadata(typeSpecifier, param);
|
137
|
-
|
138
|
-
if (!metadata.isReadOnly() && metadata.isStandardMetadataFormatSupported()) {
|
139
|
-
// for PNG, it's dots per millimeter
|
140
|
-
double dotsPerMilli = dpi / 25.4;
|
141
|
-
|
142
|
-
IIOMetadataNode horiz = new IIOMetadataNode("HorizontalPixelSize");
|
143
|
-
horiz.setAttribute("value", Double.toString(dotsPerMilli));
|
144
|
-
|
145
|
-
IIOMetadataNode vert = new IIOMetadataNode("VerticalPixelSize");
|
146
|
-
vert.setAttribute("value", Double.toString(dotsPerMilli));
|
147
|
-
|
148
|
-
IIOMetadataNode dim = new IIOMetadataNode("Dimension");
|
149
|
-
dim.appendChild(horiz);
|
150
|
-
dim.appendChild(vert);
|
151
|
-
|
152
|
-
IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
|
153
|
-
root.appendChild(dim);
|
154
|
-
|
155
|
-
try {
|
156
|
-
metadata.mergeTree("javax_imageio_1.0", root);
|
157
|
-
return metadata;
|
158
|
-
|
159
|
-
} catch (IIOInvalidTreeException e) {
|
160
|
-
System.err.println("Could not set the DPI of the output image");
|
161
|
-
e.printStackTrace();
|
162
|
-
}
|
163
|
-
}
|
164
|
-
return null;
|
165
|
-
}
|
166
|
-
|
167
|
-
private boolean isRgbImage(String extension) {
|
168
|
-
return extension.equals("bmp") || isJpeg(extension);
|
169
|
-
}
|
170
|
-
|
171
|
-
private boolean isJpeg(String extension) {
|
172
|
-
return extension.equals("jpg") || extension.equals("jpeg");
|
173
|
-
}
|
174
|
-
|
175
|
-
private boolean isPng(String extension) {
|
176
|
-
return extension.equals("png");
|
177
|
-
}
|
178
|
-
|
179
|
-
}
|
@@ -1,41 +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.save;
|
26
|
-
|
27
|
-
|
28
|
-
/**
|
29
|
-
* Exception describing an issue encountered while saving an image.
|
30
|
-
*/
|
31
|
-
public class SaveImageException extends RuntimeException {
|
32
|
-
|
33
|
-
/**
|
34
|
-
* Create a new exception with a description of why image saving failed.
|
35
|
-
* @param msg The message describing failure cause.
|
36
|
-
*/
|
37
|
-
public SaveImageException(String msg) {
|
38
|
-
super(msg);
|
39
|
-
}
|
40
|
-
|
41
|
-
}
|
@@ -1,198 +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.save;
|
26
|
-
|
27
|
-
import processing.core.PConstants;
|
28
|
-
|
29
|
-
import java.io.FileNotFoundException;
|
30
|
-
import java.io.IOException;
|
31
|
-
import java.io.OutputStream;
|
32
|
-
|
33
|
-
|
34
|
-
/**
|
35
|
-
* Strategy for creating tga (targa32) images.
|
36
|
-
*/
|
37
|
-
public class TgaImageSaveStrategy implements ImageSaveStrategy {
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Creates a Targa32 formatted byte sequence of specified
|
41
|
-
* pixel buffer using RLE compression.
|
42
|
-
* </p>
|
43
|
-
* Also figured out how to avoid parsing the image upside-down
|
44
|
-
* (there's a header flag to set the image origin to top-left)
|
45
|
-
* </p>
|
46
|
-
* Starting with revision 0092, the format setting is taken into account:
|
47
|
-
* <UL>
|
48
|
-
* <LI><TT>ALPHA</TT> images written as 8bit grayscale (uses lowest byte)
|
49
|
-
* <LI><TT>RGB</TT> → 24 bits
|
50
|
-
* <LI><TT>ARGB</TT> → 32 bits
|
51
|
-
* </UL>
|
52
|
-
* All versions are RLE compressed.
|
53
|
-
* </p>
|
54
|
-
* Contributed by toxi 8-10 May 2005, based on this RLE
|
55
|
-
* <A HREF="http://www.wotsit.org/download.asp?f=tga">specification</A>
|
56
|
-
*/
|
57
|
-
@Override
|
58
|
-
public boolean save(int[] pixels, int pixelWidth, int pixelHeight, int format,
|
59
|
-
String filename) throws FileNotFoundException {
|
60
|
-
|
61
|
-
OutputStream output = ImageSaveUtil.createForFile(filename);
|
62
|
-
|
63
|
-
byte header[] = new byte[18];
|
64
|
-
|
65
|
-
if (format == PConstants.ALPHA) { // save ALPHA images as 8bit grayscale
|
66
|
-
header[2] = 0x0B;
|
67
|
-
header[16] = 0x08;
|
68
|
-
header[17] = 0x28;
|
69
|
-
|
70
|
-
} else if (format == PConstants.RGB) {
|
71
|
-
header[2] = 0x0A;
|
72
|
-
header[16] = 24;
|
73
|
-
header[17] = 0x20;
|
74
|
-
|
75
|
-
} else if (format == PConstants.ARGB) {
|
76
|
-
header[2] = 0x0A;
|
77
|
-
header[16] = 32;
|
78
|
-
header[17] = 0x28;
|
79
|
-
|
80
|
-
} else {
|
81
|
-
throw new RuntimeException("Image format not recognized inside save()");
|
82
|
-
}
|
83
|
-
// set image dimensions lo-hi byte order
|
84
|
-
header[12] = (byte) (pixelWidth & 0xff);
|
85
|
-
header[13] = (byte) (pixelWidth >> 8);
|
86
|
-
header[14] = (byte) (pixelHeight & 0xff);
|
87
|
-
header[15] = (byte) (pixelHeight >> 8);
|
88
|
-
|
89
|
-
try {
|
90
|
-
output.write(header);
|
91
|
-
|
92
|
-
int maxLen = pixelHeight * pixelWidth;
|
93
|
-
int index = 0;
|
94
|
-
int col; //, prevCol;
|
95
|
-
int[] currChunk = new int[128];
|
96
|
-
|
97
|
-
// 8bit image exporter is in separate loop
|
98
|
-
// to avoid excessive conditionals...
|
99
|
-
if (format == PConstants.ALPHA) {
|
100
|
-
while (index < maxLen) {
|
101
|
-
boolean isRLE = false;
|
102
|
-
int rle = 1;
|
103
|
-
currChunk[0] = col = pixels[index] & 0xff;
|
104
|
-
while (index + rle < maxLen) {
|
105
|
-
if (col != (pixels[index + rle]&0xff) || rle == 128) {
|
106
|
-
isRLE = (rle > 1);
|
107
|
-
break;
|
108
|
-
}
|
109
|
-
rle++;
|
110
|
-
}
|
111
|
-
if (isRLE) {
|
112
|
-
output.write(0x80 | (rle - 1));
|
113
|
-
output.write(col);
|
114
|
-
|
115
|
-
} else {
|
116
|
-
rle = 1;
|
117
|
-
while (index + rle < maxLen) {
|
118
|
-
int cscan = pixels[index + rle] & 0xff;
|
119
|
-
if ((col != cscan && rle < 128) || rle < 3) {
|
120
|
-
currChunk[rle] = col = cscan;
|
121
|
-
} else {
|
122
|
-
if (col == cscan) rle -= 2;
|
123
|
-
break;
|
124
|
-
}
|
125
|
-
rle++;
|
126
|
-
}
|
127
|
-
output.write(rle - 1);
|
128
|
-
for (int i = 0; i < rle; i++) output.write(currChunk[i]);
|
129
|
-
}
|
130
|
-
index += rle;
|
131
|
-
}
|
132
|
-
} else { // export 24/32 bit TARGA
|
133
|
-
while (index < maxLen) {
|
134
|
-
boolean isRLE = false;
|
135
|
-
currChunk[0] = col = pixels[index];
|
136
|
-
int rle = 1;
|
137
|
-
// try to find repeating bytes (min. len = 2 pixels)
|
138
|
-
// maximum chunk size is 128 pixels
|
139
|
-
while (index + rle < maxLen) {
|
140
|
-
if (col != pixels[index + rle] || rle == 128) {
|
141
|
-
isRLE = (rle > 1); // set flag for RLE chunk
|
142
|
-
break;
|
143
|
-
}
|
144
|
-
rle++;
|
145
|
-
}
|
146
|
-
if (isRLE) {
|
147
|
-
output.write(128 | (rle - 1));
|
148
|
-
output.write(col & 0xff);
|
149
|
-
output.write(col >> 8 & 0xff);
|
150
|
-
output.write(col >> 16 & 0xff);
|
151
|
-
if (format == PConstants.ARGB) output.write(col >>> 24 & 0xff);
|
152
|
-
|
153
|
-
} else { // not RLE
|
154
|
-
rle = 1;
|
155
|
-
while (index + rle < maxLen) {
|
156
|
-
if ((col != pixels[index + rle] && rle < 128) || rle < 3) {
|
157
|
-
currChunk[rle] = col = pixels[index + rle];
|
158
|
-
} else {
|
159
|
-
// check if the exit condition was the start of
|
160
|
-
// a repeating colour
|
161
|
-
if (col == pixels[index + rle]) rle -= 2;
|
162
|
-
break;
|
163
|
-
}
|
164
|
-
rle++;
|
165
|
-
}
|
166
|
-
// write uncompressed chunk
|
167
|
-
output.write(rle - 1);
|
168
|
-
if (format == PConstants.ARGB) {
|
169
|
-
for (int i = 0; i < rle; i++) {
|
170
|
-
col = currChunk[i];
|
171
|
-
output.write(col & 0xff);
|
172
|
-
output.write(col >> 8 & 0xff);
|
173
|
-
output.write(col >> 16 & 0xff);
|
174
|
-
output.write(col >>> 24 & 0xff);
|
175
|
-
}
|
176
|
-
} else {
|
177
|
-
for (int i = 0; i < rle; i++) {
|
178
|
-
col = currChunk[i];
|
179
|
-
output.write(col & 0xff);
|
180
|
-
output.write(col >> 8 & 0xff);
|
181
|
-
output.write(col >> 16 & 0xff);
|
182
|
-
}
|
183
|
-
}
|
184
|
-
}
|
185
|
-
index += rle;
|
186
|
-
}
|
187
|
-
}
|
188
|
-
output.flush();
|
189
|
-
output.close();
|
190
|
-
return true;
|
191
|
-
|
192
|
-
} catch (IOException e) {
|
193
|
-
e.printStackTrace();
|
194
|
-
return false;
|
195
|
-
}
|
196
|
-
}
|
197
|
-
|
198
|
-
}
|