Skip to content

Package: RotateQuadrantJ2DOp

RotateQuadrantJ2DOp

nameinstructionbranchcomplexitylinemethod
RotateQuadrantJ2DOp()
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%
execute(RotateQuadrantOp, EditableImage, BufferedImage)
M: 104 C: 0
0%
M: 10 C: 0
0%
M: 7 C: 0
0%
M: 30 C: 0
0%
M: 1 C: 0
0%
static {...}
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%

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.Graphics2D;
30: import java.awt.geom.AffineTransform;
31: import java.awt.image.BufferedImage;
32: import java.awt.image.Raster;
33: import it.tidalwave.image.EditableImage;
34: import it.tidalwave.image.op.OperationImplementation;
35: import it.tidalwave.image.op.RotateQuadrantOp;
36: import lombok.extern.slf4j.Slf4j;
37:
38: /***********************************************************************************************************************
39: *
40: * @author Fabrizio Giudici
41: *
42: **********************************************************************************************************************/
43: @Slf4j
44: public class RotateQuadrantJ2DOp extends OperationImplementation<RotateQuadrantOp, BufferedImage>
45: {
46: /*******************************************************************************************************************
47: *
48: * {@inheritDoc}
49: *
50: ******************************************************************************************************************/
51: @Override
52: protected BufferedImage execute (final RotateQuadrantOp operation,
53: final EditableImage image,
54: final BufferedImage bufferedImage)
55: {
56: final var degrees = operation.getDegrees();
57: log.debug("rotateQuadrant(" + degrees + ")");
58: Java2DUtils.logImage(log, ">>>> source bufferedImage", bufferedImage);
59:
60:• if (degrees == 0)
61: {
62: return bufferedImage;
63: }
64:
65: final var newWidth = bufferedImage.getWidth();
66: final var newHeight = bufferedImage.getHeight();
67:
68: var sampleModel = bufferedImage.getSampleModel();
69:
70:• if ((degrees == 90) || (degrees == 270))
71: {
72: // newWidth = bufferedImage.getHeight();
73: // newHeight = bufferedImage.getWidth();
74: sampleModel = sampleModel.createCompatibleSampleModel(bufferedImage.getHeight(), bufferedImage.getWidth());
75: }
76:
77: final var newRaster = Raster.createWritableRaster(sampleModel, null);
78: final var colorModel = bufferedImage.getColorModel();
79: final var result =
80: new BufferedImage(colorModel, newRaster, false, Java2DUtils.getProperties(bufferedImage));
81:
82: // BufferedImage result = Java2DUtils.createCompatibleImage(bufferedImage, newWidth, newHeight);
83: final var g2d = (Graphics2D)result.getGraphics();
84:
85: try
86: {
87: final var radians = Math.toRadians(degrees);
88: g2d.transform(AffineTransform.getRotateInstance(radians));
89:
90: var x = 0;
91: var y = 0;
92:
93:• switch (degrees)
94: {
95: case 90:
96: y = -bufferedImage.getHeight();
97:
98: break;
99:
100: case 180:
101: x = -bufferedImage.getWidth();
102: y = -bufferedImage.getHeight();
103:
104: break;
105:
106: case 270:
107: x = -bufferedImage.getWidth();
108:
109: break;
110: }
111:
112: g2d.drawImage(bufferedImage, x, y, null);
113: }
114:
115: finally
116: {
117: g2d.dispose();
118: }
119:
120: Java2DUtils.logImage(log, ">>>> rotateQuadrant() returning ", result);
121:
122: return result;
123: }
124: }