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.operations

File ImageOperationChain.java

 

Coverage histogram

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

Code metrics

0
8
5
1
131
63
5
0.62
1.6
5
1
55.2% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
ImageOperationChain 53 8 55.2% 5 0
1.0100%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /**
2    * This file Copyright (c) 2009-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.operations;
35   
36    import info.magnolia.imaging.ImageGenerator;
37    import info.magnolia.imaging.ImagingException;
38    import info.magnolia.imaging.OutputFormat;
39    import info.magnolia.imaging.ParameterProvider;
40    import info.magnolia.imaging.ParameterProviderFactory;
41   
42    import java.awt.image.BufferedImage;
43    import java.util.ArrayList;
44    import java.util.List;
45   
46    /**
47    * An implementation of ImageOperation and ImageGenerator which delegates
48    * to a list of other ImageOperation instances.
49    *
50    * @param <P> type of ParameterProvider
51    * @version $Id$
52    */
 
53    public class ImageOperationChain<P extends ParameterProvider<?>> implements ImageOperation<P>, ImageGenerator<P> {
54    private List<ImageOperation<P>> operations;
55    private ParameterProviderFactory parameterProviderFactory;
56   
57    /**
58    * The output format as configured by c2b.
59    */
60    private OutputFormat outputFormat;
61    private String name;
62   
 
63  8 toggle public ImageOperationChain() {
64  8 this.operations = new ArrayList<ImageOperation<P>>();
65    }
66   
 
67  13 toggle @Override
68    public BufferedImage generate(P params) throws ImagingException {
69    // We don't create an empty Image instance here, we're relying on operations
70    // from the info.magnolia.imaging.operations.load package to do so
71    // This might change in the future, especially if we want to overlay
72    // images, and even more so if those overlays need alpha blending.
73   
74  13 return apply(null, params);
75    }
76   
 
77  13 toggle @Override
78    public BufferedImage apply(BufferedImage source, P params) throws ImagingException {
79  13 BufferedImage result = source;
80  13 for (ImageOperation<P> op : operations) {
81  30 result = op.apply(result, params);
82    }
83  13 return result;
84    }
85   
 
86    toggle @Override
87    public String getName() {
88    return name;
89    }
90   
 
91    toggle public void setName(String name) {
92    this.name = name;
93    }
94   
 
95    toggle @Override
96    public ParameterProviderFactory getParameterProviderFactory() {
97    return parameterProviderFactory;
98    }
99   
 
100    toggle public void setParameterProviderFactory(ParameterProviderFactory parameterProviderFactory) {
101    this.parameterProviderFactory = parameterProviderFactory;
102    }
103   
 
104    toggle public OutputFormat getOutputFormat() {
105    return outputFormat;
106    }
107   
108    /**
109    * Returns the static output format as configured with c2b by delegating to {@link #getOutputFormat()}.
110    */
 
111  10 toggle @Override
112    public OutputFormat getOutputFormat(P params) {
113  10 return getOutputFormat();
114    }
115   
 
116    toggle public void setOutputFormat(OutputFormat outputFormat) {
117    this.outputFormat = outputFormat;
118    }
119   
 
120    toggle public List<ImageOperation<P>> getOperations() {
121    return operations;
122    }
123   
 
124    toggle public void setOperations(List<ImageOperation<P>> operations) {
125    this.operations = operations;
126    }
127   
 
128  18 toggle public void addOperation(ImageOperation<P> operation) {
129  18 operations.add(operation);
130    }
131    }