Clover icon

Magnolia Imaging Module 3.4.2-SUPPORT-10161

  1. Project Clover database Tue Jul 16 2019 23:33:19 EEST
  2. Package info.magnolia.imaging

File OutputFormat.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

12
19
6
1
150
76
12
0.63
3.17
6
2
35.1% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
OutputFormat 43 19 35.1% 12 0
1.0100%
 

Contributing tests

This file is covered by 43 tests. .

Source view

1    /**
2    * This file Copyright (c) 2007-2018 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.imaging;
35   
36    import javax.imageio.ImageWriteParam;
37   
38    /**
39    * A simple bean holding image formatName output configuration. This is used to get the appropriate
40    * ImageWriter and applied to its underlying <code>javax.imageio.ImageWriteParam</code>.
41    * It's also exposing a simpler API, making it easier to configure through a tree/gui.
42    */
 
43    public class OutputFormat implements Cloneable {
44    private String formatName;
45    private boolean progressive;
46    private int quality;
47    private String compressionType;
48   
49    /**
50    * @deprecated since 2.1, implement {@link ImageGenerator#getOutputFormat(ParameterProvider)} instead
51    */
52    private boolean dynamicFormatType;
53   
 
54  12 toggle public OutputFormat() {
55    }
56   
 
57  1 toggle public OutputFormat(String formatName, boolean progressive, int quality, String compressionType) {
58  1 this.formatName = formatName;
59  1 this.progressive = progressive;
60  1 this.quality = quality;
61  1 this.compressionType = compressionType;
62    }
63   
64    /**
65    * @deprecated since 2.1, implement {@link ImageGenerator#getOutputFormat(ParameterProvider)} instead
66    */
 
67  1 toggle public OutputFormat(String formatName, boolean progressive, int quality, String compressionType, boolean dynamicFormatType) {
68  1 this(formatName, progressive, quality, compressionType);
69  1 this.dynamicFormatType = dynamicFormatType;
70    }
71   
 
72  52 toggle public void applyTo(ImageWriteParam param) {
73  52 if (param.canWriteProgressive()) {
74  51 param.setProgressiveMode(progressive ? ImageWriteParam.MODE_DEFAULT : ImageWriteParam.MODE_DISABLED);
75    }
76   
77  52 if (param.canWriteCompressed()) {
78  47 if (compressionType != null) {
79  2 param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
80  2 param.setCompressionType(compressionType);
81    }
82  47 if (quality > 0) {
83  43 if (param.getCompressionMode() != ImageWriteParam.MODE_EXPLICIT) {
84  42 param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
85    }
86  43 final float compressionQuality = ((float) quality) / 100;
87  43 param.setCompressionQuality(compressionQuality);
88    }
89    }
90    }
91   
92    // there's probably a better way ...
93   
 
94  18 toggle public boolean supportsTransparency() {
95  18 return !"jpg".equalsIgnoreCase(formatName) && !"jpeg".equalsIgnoreCase(formatName);
96    }
97   
98    // -- generated getters and setters
99   
 
100    toggle public String getFormatName() {
101    return formatName;
102    }
103   
 
104    toggle public void setFormatName(String formatName) {
105    this.formatName = formatName;
106    }
107   
 
108    toggle public boolean isProgressive() {
109    return progressive;
110    }
111   
 
112    toggle public void setProgressive(boolean progressive) {
113    this.progressive = progressive;
114    }
115   
 
116    toggle public int getQuality() {
117    return quality;
118    }
119   
 
120    toggle public void setQuality(int quality) {
121    this.quality = quality;
122    }
123   
 
124    toggle public String getCompressionType() {
125    return compressionType;
126    }
127   
 
128    toggle public void setCompressionType(String compressionType) {
129    this.compressionType = compressionType;
130    }
131   
132    /**
133    * @deprecated since 2.1, implement {@link ImageGenerator#getOutputFormat(ParameterProvider)} instead
134    */
 
135    toggle public boolean getDynamicFormatType() {
136    return dynamicFormatType;
137    }
138   
139    /**
140    * @deprecated since 2.1, implement {@link ImageGenerator#getOutputFormat(ParameterProvider)} instead
141    */
 
142    toggle public void setDynamicFormatType(boolean dynamicFormatType) {
143    this.dynamicFormatType = dynamicFormatType;
144    }
145   
 
146  2 toggle @Override
147    public OutputFormat clone() throws CloneNotSupportedException {
148  2 return (OutputFormat) super.clone();
149    }
150    }