Package: CreateOp
CreateOp
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CreateOp(int, int, EditableImage.DataType) |
|
|
|
|
|
||||||||||||||||||||
CreateOp(int, int, EditableImage.DataType, Color) |
|
|
|
|
|
||||||||||||||||||||
CreateOp(int, int, EditableImage.DataType, double[]) |
|
|
|
|
|
||||||||||||||||||||
getDataType() |
|
|
|
|
|
||||||||||||||||||||
getFiller() |
|
|
|
|
|
||||||||||||||||||||
getHeight() |
|
|
|
|
|
||||||||||||||||||||
getWidth() |
|
|
|
|
|
||||||||||||||||||||
toDoubles(Color, EditableImage.DataType) |
|
|
|
|
|
||||||||||||||||||||
toString() |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * Mistral: open source imaging engine
5: * http://tidalwave.it/projects/mistral
6: *
7: * Copyright (C) 2003 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/mistral-src
23: * git clone https://github.com/tidalwave-it/mistral-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.image.op;
28:
29: import java.awt.Color;
30: import it.tidalwave.image.EditableImage;
31:
32: /***********************************************************************************************************************
33: *
34: * @author Fabrizio Giudici
35: *
36: **********************************************************************************************************************/
37: public class CreateOp extends AbstractCreateOp
38: {
39: private final int width;
40: private final int height;
41: private final EditableImage.DataType dataType;
42: private final double[] filler;
43:
44: /*******************************************************************************************************************
45: *
46: * Create a black monochromatic image (i.e. made of a single band) with the
47: * specified data type.
48: *
49: * @param width the image width
50: * @param height the image height
51: * @param dataType the data type
52: *
53: ******************************************************************************************************************/
54: public CreateOp (final int width, final int height, final EditableImage.DataType dataType)
55: {
56: this(width, height, dataType, 0f);
57: }
58:
59: /*******************************************************************************************************************
60: *
61: * Create an RGB image with the specified data type.
62: *
63: * @param width the image width
64: * @param height the image height
65: * @param dataType the data type
66: * @param color the filler color
67: *
68: ******************************************************************************************************************/
69: public CreateOp (final int width, final int height, final EditableImage.DataType dataType, final Color color)
70: {
71: this(width, height, dataType, toDoubles(color, dataType));
72: }
73:
74: /*******************************************************************************************************************
75: *
76: * Create a multi-band image with the specified data type. Ploase note that
77: * while the <code>filler</code> param is <code>double</code>, its valid
78: * range depends on the <code>dataType</code>. For instance, while for
79: * <code>FLOAT</code> and <code>DOUBLE</code> types the range is 0.0..1.0,
80: * for <code>BYTE<code> is 0..255, for <code>UNSIGNED_SHORT</code> is
81: * 0..65535 and so on.
82: *
83: * @param width the image width
84: * @param height the image height
85: * @param dataType the data type
86: * @param filler the filler values
87: *
88: ******************************************************************************************************************/
89: public CreateOp (final int width, final int height, final EditableImage.DataType dataType, final double... filler)
90: {
91:• if (width <= 0)
92: {
93: throw new IllegalArgumentException("width must be positive");
94: }
95:
96:• if (height <= 0)
97: {
98: throw new IllegalArgumentException("height must be positive");
99: }
100:
101:• if (dataType == null)
102: {
103: throw new IllegalArgumentException("dataType cannot be null");
104: }
105:
106:• if ((filler == null) || (filler.length == 0))
107: {
108: throw new IllegalArgumentException("filler cannot be null or 0-sized");
109: }
110:
111: this.width = width;
112: this.height = height;
113: this.dataType = dataType;
114: this.filler = filler;
115: }
116:
117: /*******************************************************************************************************************
118: *
119: *
120: ******************************************************************************************************************/
121: public int getWidth()
122: {
123: return width;
124: }
125:
126: /*******************************************************************************************************************
127: *
128: *
129: ******************************************************************************************************************/
130: public int getHeight()
131: {
132: return height;
133: }
134:
135: /*******************************************************************************************************************
136: *
137: *
138: ******************************************************************************************************************/
139: public EditableImage.DataType getDataType()
140: {
141: return dataType;
142: }
143:
144: /*******************************************************************************************************************
145: *
146: *
147: ******************************************************************************************************************/
148: public double[] getFiller()
149: {
150: return filler;
151: }
152:
153: /*******************************************************************************************************************
154: *
155: * {@inheritDoc}
156: *
157: ******************************************************************************************************************/
158: @Override
159: public String toString()
160: {
161: return "CreateOp(" + width + ", " + height + ", " + dataType + ", " + filler + ")";
162: }
163:
164: /*******************************************************************************************************************
165: *
166: *
167: ******************************************************************************************************************/
168: private static double[] toDoubles (final Color color, final EditableImage.DataType dataType)
169: {
170: final double[] result = {color.getRed(), color.getGreen(), color.getBlue()};
171: double scale = 1;
172: final var F = 1.0 / 255.0;
173:
174:• switch (dataType)
175: {
176: case BYTE:
177: break;
178:
179: case SHORT:
180: scale = F * (Math.pow(2, 15) - 1);
181:
182: break;
183:
184: case UNSIGNED_SHORT:
185: scale = F * (Math.pow(2, 16) - 1);
186:
187: break;
188:
189: case INT:
190: scale = F * (Math.pow(2, 31) - 1);
191:
192: break;
193:
194: case FLOAT:
195: case DOUBLE:
196: scale = F;
197: break;
198:
199: default:
200: throw new IllegalArgumentException("toDoubles: " + dataType);
201: }
202:
203:• for (var i = 0; i < result.length; i++)
204: {
205: result[i] *= scale;
206: }
207:
208: return result;
209: }
210: }