Package: PaintJ2DOp
PaintJ2DOp
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PaintJ2DOp() |
|
|
|
|
|
||||||||||||||||||||
applyPreviewSettings(BufferedImage, PreviewSettings) |
|
|
|
|
|
||||||||||||||||||||
execute(PaintOp, EditableImage, BufferedImage) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
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 java.awt.RenderingHints;
30: import java.awt.image.BufferedImage;
31: import java.awt.image.DataBuffer;
32: import java.awt.image.LookupOp;
33: import java.awt.image.LookupTable;
34: import it.tidalwave.image.EditableImage;
35: import it.tidalwave.image.op.OperationImplementation;
36: import it.tidalwave.image.op.PaintOp;
37: import it.tidalwave.image.render.PreviewSettings;
38: import lombok.extern.slf4j.Slf4j;
39:
40: /***********************************************************************************************************************
41: *
42: * @author Fabrizio Giudici
43: *
44: **********************************************************************************************************************/
45: @Slf4j
46: public class PaintJ2DOp extends OperationImplementation<PaintOp, BufferedImage>
47: {
48: /*******************************************************************************************************************
49: *
50: * {@inheritDoc}
51: *
52: ******************************************************************************************************************/
53: @Override
54: protected BufferedImage execute (final PaintOp operation,
55: final EditableImage image,
56: final BufferedImage bufferedImage)
57: {
58: final var x = operation.getX();
59: final var y = operation.getY();
60: final var w = operation.getW();
61: final var h = operation.getH();
62: final var g2 = operation.getGraphics2D();
63: final var previewSettings = operation.getPreviewSettings();
64: final var imageObserver = operation.getImageObserver();
65: final var quality = operation.getQuality();
66: log.debug("execute(" + x + ", " + y + ", " + w + ", " + h + ", " + quality + ")");
67:
68:• if (w != 0)
69: {
70: final var saveRenderingHints = g2.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
71: final var interpolation = Java2DUtils.findRenderingHintsInterpolation(quality);
72: g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation);
73: g2.drawImage(applyPreviewSettings(bufferedImage, previewSettings), x, y, w, h, imageObserver);
74:
75:• if (saveRenderingHints != null)
76: {
77: g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, saveRenderingHints);
78: }
79: }
80:
81: else
82: {
83: g2.drawImage(applyPreviewSettings(bufferedImage, previewSettings), x, y, imageObserver);
84: }
85:
86: return bufferedImage;
87: }
88:
89: /*******************************************************************************************************************
90: *
91: *
92: ******************************************************************************************************************/
93:
94: // FIXME: ottimizzalo, fallo lavorare solo sulla subimage visualizzata
95: // FIXME: aggiungi un parametro sulla qualita', da mettere dentro PreviewSettings
96: private BufferedImage applyPreviewSettings (final BufferedImage image, final PreviewSettings previewSettings)
97: {
98: var theImage = image;
99:
100:• if (previewSettings != null)
101: {
102: final var size = DataBuffer.getDataTypeSize(image.getSampleModel().getDataType());
103: LookupTable lookupTable = null;
104:
105:• switch (size)
106: {
107: case 8:
108: case 32: // packed model
109: lookupTable = previewSettings.getLookupTable8bit();
110:
111: break;
112:
113: case 16:
114: lookupTable = previewSettings.getLookupTable16bit();
115:
116: break;
117:
118: default:
119: throw new IllegalArgumentException("DataSize is " + size);
120: }
121:
122:• if (lookupTable != null)
123: {
124: final var lOp = new LookupOp(lookupTable, null); // FIXME: hints
125: Java2DUtils.logImage(log, "applyPreviewSettings: ", image);
126: theImage = lOp.filter(image, null);
127: }
128: }
129:
130: return theImage;
131: }
132: }