set quality level higher when exporting JPEG images (issue #58)

This commit is contained in:
benfry
2012-11-29 12:40:02 +00:00
parent 244fdf7368
commit 0feb505d68
4 changed files with 54 additions and 8 deletions
+10
View File
@@ -35,6 +35,13 @@ PROCESSING 2.0b7 (REV 0215) - 25 November 2012
http://code.google.com/p/processing/issues/detail?id=1354
http://guides.macrumors.com/Keyboard_shortcuts&section=10#Text_Shortcuts
+ Set quality level higher when exporting JPEG images. This will result
in larger JPEG files with save() and saveFrame(), but the default quality
setting in the past was unacceptable for many/most projects.
http://code.google.com/p/processing/issues/detail?id=58
See the bug report link for how to implement in case you want to set
the quality lower (or even higher) than the new default.
+ Table row iterating syntax has changed. This code:
for (TableRow row : table) { ... }
has now changed to
@@ -185,6 +192,9 @@ PROCESSING 2.0b7 (REV 0215) - 25 November 2012
+ begin/endShape with a single vertex causing crash on P2D/P3D.
http://code.google.com/p/processing/issues/detail?id=1421
+ Using a PGraphics as a texture produces visual artifacts.
http://code.google.com/p/processing/issues/detail?id=1420
[ android ]
+ Like the desktop release, removed default imports. This includes:
+32 -4
View File
@@ -29,6 +29,8 @@ import java.awt.image.*;
import java.io.*;
import java.lang.reflect.Method;
import com.sun.image.codec.jpeg.*;
/**
* ( begin auto-generated from PImage.xml )
@@ -3067,11 +3069,15 @@ public class PImage implements PConstants, Cloneable {
int outputFormat = (format == ARGB) ?
BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
String extension =
path.substring(path.lastIndexOf('.') + 1).toLowerCase();
// JPEG and BMP images that have an alpha channel set get pretty unhappy.
// BMP just doesn't write, and JPEG writes it as a CMYK image.
// http://code.google.com/p/processing/issues/detail?id=415
String lower = path.toLowerCase();
if (lower.endsWith("bmp") || lower.endsWith("jpg") || lower.endsWith("jpeg")) {
// String lower = path.toLowerCase();
// if (lower.endsWith("bmp") || lower.endsWith("jpg") || lower.endsWith("jpeg")) {
if (extension.equals("bmp") || extension.equals("jpg") || extension.equals("jpeg")) {
outputFormat = BufferedImage.TYPE_INT_RGB;
}
@@ -3079,9 +3085,31 @@ public class PImage implements PConstants, Cloneable {
bimage.setRGB(0, 0, width, height, pixels, 0, width);
File file = new File(path);
String extension = path.substring(path.lastIndexOf('.') + 1);
return javax.imageio.ImageIO.write(bimage, extension, file);
if (extension.equals("jpg") || extension.equals("jpeg")) {
// ByteArrayOutputStream out = new ByteArrayOutputStream();
// JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
BufferedOutputStream output =
new BufferedOutputStream(new FileOutputStream(file));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage);
// Set JPEG quality to 90% with baseline optimization. Setting this
// to 1 was a huge jump (about triple the size), so this seems good.
// Oddly, a smaller file size than Photoshop at 90%, but it's a
// completely different algorithm, I suppose.
param.setQuality(0.9f, true);
// p.setQuality(1, true);
encoder.setJPEGEncodeParam(param);
encoder.encode(bimage);
output.flush();
output.close();
// FileOutputStream fo = new FileOutputStream(new File(path));
// out.writeTo(fo);
return true;
} else {
return javax.imageio.ImageIO.write(bimage, extension, file);
}
} catch (Exception e) {
e.printStackTrace();
+6 -4
View File
@@ -78,6 +78,12 @@ A set(x, y, PImage) doesn't work with P2D/P3D
A http://code.google.com/p/processing/issues/detail?id=1185
A Processing 2.0b6 p2d / p3d arraylist pvector display issues
A http://code.google.com/p/processing/issues/detail?id=1421
A Using a PGraphics as a texture produces visual artifacts in P2D/P3D.
A http://code.google.com/p/processing/issues/detail?id=1420
X set quality level higher when exporting JPEG images
o add ability to control jpeg compression level with save() and saveFrame()
o or just write a better example for this one?
X http://code.google.com/p/processing/issues/detail?id=58
_ implement mousePressed(Event) etc
_ better to do this instead of bringing back the magic event
@@ -624,10 +630,6 @@ _ http://code.google.com/p/processing/issues/detail?id=219
_ Semitransparent rect drawn over image not rendered correctly
_ http://code.google.com/p/processing/issues/detail?id=182
_ add ability to control jpeg compression level with save() and saveFrame()
_ or just write a better example for this one?
_ http://code.google.com/p/processing/issues/detail?id=58
CORE / PShape
+6
View File
@@ -60,6 +60,12 @@ earlier
X The sketch name can't begin with '_' (underscore)
X http://code.google.com/p/processing/issues/detail?id=859
_ add to build.xml
_ insert "@SuppressWarnings({"unused", "cast"})" into
_ JavaLexer, JavaRecognizer, PdeLexer, PdeRecognizer
_ from processing/mode/java/preproc/
2.0 FINAL / casey requests
_ errors that cannot be placed (i.e. missing brace)