MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / compress

Method compress

src/main/java/field/graphics/SlowJPEG.java:71–108  ·  view source on GitHub ↗
(String filename, Buffer dest, int width, int height)

Source from the content-addressed store, hash-verified

69 public void compress(String filename, Buffer dest, int width, int height)
70 {
71// throw new IllegalArgumentException("not implemented");
72 BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
73
74 ByteBuffer t = ByteBuffer.allocate(dest.limit());
75 dest.rewind();
76 t.put((ByteBuffer)dest);
77 t.rewind();
78 dest.rewind();
79
80 image.getRaster().setDataElements(0,0, t.array());
81
82 byte[] ddd = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
83 System.arraycopy(t.array(), 0, ddd, 0, ddd.length);
84//
85 try {
86 ImageWriter jj = ImageIO.getImageWritersByFormatName("jpg").next();
87 jj.setOutput(new FileImageOutputStream(new File(filename)));
88 JPEGImageWriteParam params = new JPEGImageWriteParam(null);
89 params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
90 params.setCompressionQuality(1f);
91 params.setSourceSubsampling(1,1,0,0);
92 jj.write(null, new IIOImage(image, null, null), params);
93 } catch (IOException e) {
94 e.printStackTrace();
95 }
96
97
98// try {
99// ImageWriter jj = ImageIO.getImageWritersByFormatName("png").next();
100// jj.setOutput(new FileImageOutputStream(new File(filename.replace(".jpg", ".png"))));
101// jj.write(null, new IIOImage(image, null, null), null);
102// } catch (IOException e) {
103// e.printStackTrace();
104// }
105
106 }
107
108
109
110 @Override
111 public int[] dimensions(String filename) {

Callers 7

generateMarkdownMethod · 0.45
getCompletionsForMethod · 0.45
getCompletionsForMethod · 0.45
generateMarkdownMethod · 0.45
callMethod · 0.45
callMethod · 0.45
callMethod · 0.45

Calls 6

getDataMethod · 0.80
nextMethod · 0.65
allocateMethod · 0.45
limitMethod · 0.45
putMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected