Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / src / javajs / img / Jpg64Encoder.java
1 // Version 1.0a
2 // Copyright (C) 1998, James R. Weeks and BioElectroMech.
3 // Visit BioElectroMech at www.obrador.com.  Email James@obrador.com.
4
5 // See license.txt for details about the allowed used of this software.
6 // This software is based in part on the work of the Independent JPEG Group.
7 // See IJGreadme.txt for details about the Independent JPEG Group's license.
8
9 // This encoder is inspired by the Java Jpeg encoder by Florian Raemy,
10 // studwww.eurecom.fr/~raemy.
11 // It borrows a great deal of code and structure from the Independent
12 // Jpeg Group's Jpeg 6a library, Copyright Thomas G. Lane.
13 // See license.txt for details 
14
15 /*
16  * JpegEncoder and its associated classes are Copyright (c) 1998, James R. Weeks and BioElectroMech
17  * see(Jmol/src/com/obrador/license.txt)
18  * 
19  * javajs.img.JpegEncoder.java was adapted by Bob Hanson
20  * for Jmol in the following ways:
21  * 
22  * 1) minor coding efficiencies were made in some for() loops.
23  * 2) methods not used by Jmol were commented out
24  * 3) method and variable signatures were modified to provide 
25  *    more appropriate method privacy.
26  * 4) additions for Java2Script compatibility 
27  * 
28  * Original files are maintained in the Jmol.src.com.obrador package, but
29  * these original files are not distributed with Jmol.
30  *   
31 */
32
33 package javajs.img;
34
35 import java.io.IOException;
36 import java.util.Map;
37
38 import javajs.util.Base64;
39 import javajs.util.OC;
40
41
42 public class Jpg64Encoder extends JpgEncoder {
43
44   private OC outTemp;
45
46   @Override
47   protected void setParams(Map<String, Object> params) {
48     defaultQuality = 75;
49     outTemp = (OC) params.remove("outputChannelTemp");
50     super.setParams(params);
51   }
52
53   @Override
54   protected void generate() throws IOException {
55     OC out0 = out;
56     out = outTemp;
57     super.generate();
58     byte[] bytes = Base64.getBytes64(out.toByteArray());
59     outTemp = null;
60     out = out0;
61     out.write(bytes, 0, bytes.length);
62   }
63
64 }