propane 3.2.0-java → 3.3.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +9 -0
  3. data/.mvn/wrapper/maven-wrapper.properties +3 -1
  4. data/CHANGELOG.md +3 -1
  5. data/README.md +4 -4
  6. data/lib/propane/app.rb +1 -1
  7. data/lib/propane/version.rb +1 -1
  8. data/pom.rb +79 -0
  9. data/pom.xml +32 -43
  10. data/propane.gemspec +2 -2
  11. data/src/main/java/japplemenubar/JAppleMenuBar.java +47 -41
  12. data/src/main/java/monkstone/vecmath/{AppRender.java → GfxRender.java} +12 -12
  13. data/src/main/java/processing/awt/PSurfaceAWT.java +3 -3
  14. data/src/main/java/processing/core/PApplet.java +14004 -14573
  15. data/src/main/java/processing/core/PGraphics.java +7563 -7213
  16. data/src/main/java/processing/core/PImage.java +2783 -3080
  17. data/src/main/java/processing/core/ThinkDifferent.java +120 -0
  18. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +161 -0
  19. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +169 -0
  20. data/src/main/java/processing/core/util/image/constants/TifConstants.java +45 -0
  21. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +80 -0
  22. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +73 -0
  23. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +70 -0
  24. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +132 -0
  25. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +48 -0
  26. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +45 -0
  27. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +255 -0
  28. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +98 -0
  29. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +49 -0
  30. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +48 -0
  31. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +179 -0
  32. data/src/main/java/processing/core/util/image/save/SaveImageException.java +41 -0
  33. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +198 -0
  34. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +91 -0
  35. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +57 -0
  36. data/src/main/java/processing/core/util/io/InputFactory.java +285 -0
  37. data/src/main/java/processing/core/util/io/PathUtil.java +109 -0
  38. data/vendors/Rakefile +1 -1
  39. metadata +30 -7
  40. data/src/main/java/processing/core/DesktopHandler.java +0 -94
@@ -0,0 +1,48 @@
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
+ }
@@ -0,0 +1,179 @@
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
+ }
@@ -0,0 +1,41 @@
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
+ }
@@ -0,0 +1,198 @@
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> &rarr; 24 bits
50
+ * <LI><TT>ARGB</TT> &rarr; 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
+ }