svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.impl / src / main / java / org / gvsig / fmap / raster / lib / legend / impl / operations / cmyktorgb / CMYKToRGBOperationFactory.java @ 44831
History | View | Annotate | Download (5.41 KB)
1 | 44831 | jjdelcerro | /* gvSIG. Desktop Geographic Information System.
|
---|---|---|---|
2 | *
|
||
3 | * Copyright ? 2007-2017 gvSIG Association
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
18 | * MA 02110-1301, USA.
|
||
19 | *
|
||
20 | * For any additional information, do not hesitate to contact us
|
||
21 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
22 | */
|
||
23 | package org.gvsig.raster.lib.legend.impl.operations.cmyktorgb; |
||
24 | |||
25 | import java.io.IOException; |
||
26 | import java.io.InputStream; |
||
27 | import java.util.Map; |
||
28 | |||
29 | import org.xmlpull.v1.XmlPullParserException; |
||
30 | |||
31 | import org.gvsig.raster.lib.buffer.api.Buffer; |
||
32 | import org.gvsig.raster.lib.buffer.api.BufferManager; |
||
33 | import org.gvsig.raster.lib.buffer.api.operations.Operation; |
||
34 | import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
||
35 | import org.gvsig.tools.ToolsLocator; |
||
36 | import org.gvsig.tools.dynobject.DynObject; |
||
37 | import org.gvsig.tools.dynobject.DynObjectManager; |
||
38 | import org.gvsig.tools.dynobject.DynStruct; |
||
39 | |||
40 | |||
41 | /**
|
||
42 | * @author fdiaz
|
||
43 | *
|
||
44 | */
|
||
45 | public class CMYKToRGBOperationFactory implements OperationFactory { |
||
46 | public static String NAME="CMYKToRGB"; |
||
47 | public static String DESCRIPTION="CMYK to RGB operation";//FIXME: |
||
48 | private DynStruct definition;
|
||
49 | |||
50 | /**
|
||
51 | *
|
||
52 | */
|
||
53 | public CMYKToRGBOperationFactory() {
|
||
54 | // TODO Auto-generated constructor stub
|
||
55 | } |
||
56 | |||
57 | /* (non-Javadoc)
|
||
58 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#createParameters()
|
||
59 | */
|
||
60 | @Override
|
||
61 | public DynObject createParameters() {
|
||
62 | DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
||
63 | if (definition == null) { |
||
64 | definition = createParametersDefinition(); |
||
65 | } |
||
66 | DynObject parameters = manager.createDynObject(definition); |
||
67 | return parameters;
|
||
68 | } |
||
69 | |||
70 | /* (non-Javadoc)
|
||
71 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#create()
|
||
72 | */
|
||
73 | @Override
|
||
74 | public Operation create() { |
||
75 | return new CMYKToRGBOperation(this); |
||
76 | } |
||
77 | |||
78 | /* (non-Javadoc)
|
||
79 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#createParametersDefinition()
|
||
80 | */
|
||
81 | @Override
|
||
82 | public DynStruct createParametersDefinition() {
|
||
83 | return registerParametersDefinition("CMYKToRGBOperationParameters", "/org/gvsig/raster/lib/legend/impl/operations/cmyktorgb/CMYKToRGBOperationParameters.xml"); |
||
84 | } |
||
85 | |||
86 | /* (non-Javadoc)
|
||
87 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#getName()
|
||
88 | */
|
||
89 | @Override
|
||
90 | public String getName() { |
||
91 | return NAME;
|
||
92 | } |
||
93 | |||
94 | /* (non-Javadoc)
|
||
95 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#getDescription()
|
||
96 | */
|
||
97 | @Override
|
||
98 | public String getDescription() { |
||
99 | return DESCRIPTION;
|
||
100 | } |
||
101 | |||
102 | /* (non-Javadoc)
|
||
103 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#isApplicable(org.gvsig.raster.lib.buffer.api.Buffer)
|
||
104 | */
|
||
105 | @Override
|
||
106 | public Applicable isApplicable(Buffer buffer) { |
||
107 | int bandsCount = buffer.getBandCount();
|
||
108 | int byteBandsCount = 0; |
||
109 | for(int band = 0; band<bandsCount; band++){ |
||
110 | if (buffer.getBandTypes()[band]==BufferManager.TYPE_BYTE) {
|
||
111 | byteBandsCount++; |
||
112 | } |
||
113 | } |
||
114 | if(byteBandsCount==bandsCount){
|
||
115 | return Applicable.YES;
|
||
116 | } else if (byteBandsCount==0) { |
||
117 | return Applicable.NO;
|
||
118 | } |
||
119 | return Applicable.UNKNOW;
|
||
120 | } |
||
121 | |||
122 | /* (non-Javadoc)
|
||
123 | * @see org.gvsig.raster.lib.buffer.api.operations.OperationFactory#isApplicable(org.gvsig.raster.lib.buffer.api.operations.Operation)
|
||
124 | */
|
||
125 | @Override
|
||
126 | public Applicable isApplicable(Operation operation) { |
||
127 | //FIXME:
|
||
128 | return Applicable.YES;
|
||
129 | } |
||
130 | |||
131 | protected DynStruct registerParametersDefinition(String name, String filename) { |
||
132 | DynStruct definition = null;
|
||
133 | |||
134 | DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
||
135 | definition = manager.get(name); |
||
136 | if ( definition == null) { |
||
137 | InputStream stream = this.getClass().getResourceAsStream(filename); |
||
138 | if( stream == null ) { |
||
139 | throw new IllegalArgumentException("File '"+filename+"' not found"); |
||
140 | } |
||
141 | Map<String, DynStruct> definitions = null; |
||
142 | try {
|
||
143 | definitions = manager.importDynClassDefinitions(stream, this.getClass().getClassLoader());
|
||
144 | } catch (XmlPullParserException e) {
|
||
145 | throw new IllegalArgumentException("DynClass '"+name+"' can't parse file '"+filename+"'",e); |
||
146 | } catch (IOException e) { |
||
147 | throw new IllegalArgumentException("DynClass '"+name+"' can't read file '"+filename+"'",e); |
||
148 | } |
||
149 | definition = definitions.get(name); |
||
150 | if ( definition == null) { |
||
151 | throw new IllegalArgumentException("DynClass '"+name+"' not found in file '"+filename+"'"); |
||
152 | } |
||
153 | } |
||
154 | return definition;
|
||
155 | } |
||
156 | |||
157 | } |