Skip to content

Package: ImageModelJ2D

ImageModelJ2D

nameinstructionbranchcomplexitylinemethod
ImageModelJ2D()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
ImageModelJ2D(Object)
M: 5 C: 7
58%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 3
75%
M: 0 C: 1
100%
createCopy(boolean)
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
createImage(BufferedImage)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getBandCount()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getBufferedImage()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getColorModel()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDataType()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getFactory()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getHeight()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getInnerProperty(Class)
M: 22 C: 7
24%
M: 5 C: 1
17%
M: 3 C: 1
25%
M: 5 C: 2
29%
M: 0 C: 1
100%
getMemorySize()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getWidth()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 67
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
toObjectForDeserialization(RenderedImage)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toRenderedImageForSerialization()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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.java2d;
28:
29: import javax.annotation.Nonnegative;
30: import javax.annotation.Nonnull;
31: import java.util.HashMap;
32: import java.util.Map;
33: import java.awt.RenderingHints;
34: import java.awt.image.AffineTransformOp;
35: import java.awt.image.BufferedImage;
36: import java.awt.image.ColorModel;
37: import java.awt.image.RenderedImage;
38: import java.awt.image.SampleModel;
39: import it.tidalwave.image.EditableImage;
40: import it.tidalwave.image.ImageModel;
41: import it.tidalwave.image.InterpolationType;
42: import it.tidalwave.image.op.ImplementationFactory;
43: import lombok.NoArgsConstructor;
44: import lombok.extern.slf4j.Slf4j;
45:
46: /***********************************************************************************************************************
47: *
48: * An opaque class which encapsulates all the image manipulation logics,
49: * and allows the implementation of these logics to be transparently changed
50: * (e.g. by using or not JAI, etc...)
51: *
52: * @author Fabrizio Giudici
53: *
54: **********************************************************************************************************************/
55: @NoArgsConstructor /* for serialization */ @Slf4j
56: public class ImageModelJ2D extends ImageModel
57: {
58: private static final Map<InterpolationType, Object> interpolationMap = new HashMap<>();
59:
60: private static final Map<InterpolationType, Integer> interpolationMap2 = new HashMap<>();
61:
62: // private static final List<String> ICC_PROFILES_WORKAROUND = Arrays.asList(new String[]
63: // {
64: // "sRGB IEC61966-2.1", "Nikon sRGB 4.0.0.3000", "Nikon sRGB 4.0.0.3001"
65: // });
66:
67: static
68: {
69: interpolationMap.put(InterpolationType.FASTEST, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
70: interpolationMap.put(InterpolationType.NEAREST_NEIGHBOR, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
71: interpolationMap.put(InterpolationType.BILINEAR, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
72: interpolationMap.put(InterpolationType.BICUBIC, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
73: interpolationMap.put(InterpolationType.BEST, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
74:
75: interpolationMap2.put(InterpolationType.FASTEST, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
76: interpolationMap2.put(InterpolationType.NEAREST_NEIGHBOR, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
77: interpolationMap2.put(InterpolationType.BILINEAR, AffineTransformOp.TYPE_BILINEAR);
78: interpolationMap2.put(InterpolationType.BICUBIC, AffineTransformOp.TYPE_BILINEAR);
79: interpolationMap2.put(InterpolationType.BEST, AffineTransformOp.TYPE_BILINEAR);
80: }
81:
82: /*******************************************************************************************************************
83: *
84: * Creates a new EditableImage given a BufferedImage
85: *
86: * @param bufferedImage the buffered image
87: *
88: ******************************************************************************************************************/
89: public ImageModelJ2D (@Nonnull final Object bufferedImage)
90: {
91: super(bufferedImage);
92:
93:• if (!(bufferedImage instanceof BufferedImage))
94: {
95: throw new IllegalArgumentException("bufferedImage is not an instance of BufferedImage");
96: }
97: }
98:
99: /*******************************************************************************************************************
100: *
101: * {@inheritDoc}
102: *
103: ******************************************************************************************************************/
104: @Override @Nonnull
105: public ImplementationFactory getFactory()
106: {
107: return ImplementationFactoryJ2D.getDefault();
108: }
109:
110: /*******************************************************************************************************************
111: *
112: *
113: *
114: ******************************************************************************************************************/
115: @Nonnull
116: public static EditableImage createImage (@Nonnull final BufferedImage bufferedImage) // FIXME: try to remove this
117: {
118: return new EditableImage(new ImageModelJ2D(bufferedImage));
119: }
120:
121: /*******************************************************************************************************************
122: *
123: * {@inheritDoc}
124: *
125: ******************************************************************************************************************/
126: @Override @Nonnegative
127: public int getWidth()
128: {
129: return getBufferedImage().getWidth();
130: }
131:
132: /*******************************************************************************************************************
133: *
134: * {@inheritDoc}
135: *
136: ******************************************************************************************************************/
137: @Override @Nonnegative
138: public int getHeight()
139: {
140: return getBufferedImage().getHeight();
141: }
142:
143: /*******************************************************************************************************************
144: *
145: * {@inheritDoc}
146: *
147: ******************************************************************************************************************/
148: @Override @Nonnull
149: public EditableImage.DataType getDataType()
150: {
151: return EditableImage.DataType.valueOf(getBufferedImage().getRaster().getDataBuffer().getDataType());
152: }
153:
154: /*******************************************************************************************************************
155: *
156: * {@inheritDoc}
157: *
158: ******************************************************************************************************************/
159: @Override @Nonnegative
160: public int getBandCount()
161: {
162: return getBufferedImage().getRaster().getNumBands();
163: }
164:
165: /*******************************************************************************************************************
166: *
167: * {@inheritDoc}
168: *
169: ******************************************************************************************************************/
170: @Override @Nonnull
171: public ColorModel getColorModel()
172: {
173: return getBufferedImage().getColorModel();
174: }
175:
176: /*******************************************************************************************************************
177: *
178: * {@inheritDoc}
179: *
180: ******************************************************************************************************************/
181: @Override @Nonnegative
182: public long getMemorySize()
183: {
184:• return (getBufferedImage() == null) ? 0 : getBufferedImage().getRaster().getDataBuffer().getSize();
185: }
186:
187: /*******************************************************************************************************************
188: *
189: * {@inheritDoc}
190: *
191: ******************************************************************************************************************/
192: @Override @Nonnull
193: public EditableImage createCopy (final boolean copyContents)
194: {
195: log.trace("createCopy({})", copyContents);
196:
197: final var time = System.currentTimeMillis();
198: log.warn(">>>> **** WARNING CREATECOPY DISABLED");
199:
200: final var result = getBufferedImage(); // createCopy2(copyContents);
201: log.trace(">>>> createCopy() completed ok in {} msec", (System.currentTimeMillis() - time));
202:
203: return createImage(result);
204: }
205:
206: /* private BufferedImage createCopy2 (boolean copyContents)
207: {
208: SampleModel sampleModel = image.getSampleModel();
209: WritableRaster newRaster = Raster.createWritableRaster(sampleModel, null);
210: ColorModel colorModel = image.getColorModel();
211: BufferedImage result = new BufferedImage(colorModel, newRaster, false, getProperties(image));
212:
213: if (copyContents)
214: copyDataBuffer(image.getRaster(), newRaster);
215:
216: return result;
217: }*/
218:
219: /*******************************************************************************************************************
220: *
221: * {@inheritDoc}
222: *
223: ******************************************************************************************************************/
224: @Override @Nonnull @SuppressWarnings("unchecked")
225: public <T> T getInnerProperty (@Nonnull final Class<T> propertyClass)
226: {
227:• if (propertyClass.equals(BufferedImage.class))
228: {
229: return (T)getBufferedImage();
230: }
231:
232:• if (propertyClass.equals(SampleModel.class))
233: {
234: return (T)getBufferedImage().getSampleModel();
235: }
236:
237:• if (propertyClass.equals(ColorModel.class))
238: {
239: return (T)getBufferedImage().getColorModel();
240: }
241:
242: throw new IllegalArgumentException(propertyClass.getName());
243: }
244:
245: /*******************************************************************************************************************
246: *
247: * {@inheritDoc}
248: *
249: ******************************************************************************************************************/
250: @Override @Nonnull
251: protected RenderedImage toRenderedImageForSerialization()
252: {
253: return getBufferedImage();
254: }
255:
256: /*******************************************************************************************************************
257: *
258: * {@inheritDoc}
259: *
260: ******************************************************************************************************************/
261: @Override @Nonnull
262: protected Object toObjectForDeserialization (@Nonnull final RenderedImage renderedImage)
263: {
264: return renderedImage;
265: }
266:
267: @Nonnull
268: private BufferedImage getBufferedImage()
269: {
270: return (BufferedImage)model;
271: }
272:
273: /*
274: private void copyDataBuffer (WritableRaster raster, WritableRaster newRaster)
275: {
276: int type = raster.getDataBuffer().getDataType();
277:
278: switch (type)
279: {
280: case DataBuffer.TYPE_BYTE:
281: DataBufferByte sourceDataBuffer1 = (DataBufferByte)raster.getDataBuffer();
282: DataBufferByte destDataBuffer1 = (DataBufferByte)newRaster.getDataBuffer();
283: System.arraycopy(sourceDataBuffer1.getData(), 0,
284: destDataBuffer1.getData(), 0,
285: sourceDataBuffer1.getData().length);
286:
287: break;
288:
289: case DataBuffer.TYPE_USHORT:
290: DataBufferUShort sourceDataBuffer2 = (DataBufferUShort)raster.getDataBuffer();
291: DataBufferUShort destDataBuffer2 = (DataBufferUShort)newRaster.getDataBuffer();
292: System.arraycopy(sourceDataBuffer2.getData(), 0,
293: destDataBuffer2.getData(), 0,
294: sourceDataBuffer2.getData().length);
295:
296: break;
297:
298: default:
299: throw new IllegalArgumentException("Unsupported databuffer type: " + type);
300: }
301: }
302: */
303: }