Package: ScaleJ2DOp
ScaleJ2DOp
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ScaleJ2DOp() |
|
|
|
|
|
||||||||||||||||||||
execute(ScaleOp, 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.util.Arrays;
30: import java.util.List;
31: import java.awt.image.BufferedImage;
32: import java.awt.image.SinglePixelPackedSampleModel;
33: import it.tidalwave.image.EditableImage;
34: import it.tidalwave.image.Quality;
35: import it.tidalwave.image.op.OperationImplementation;
36: import it.tidalwave.image.op.ScaleOp;
37: import it.tidalwave.image.util.Platform;
38: import lombok.extern.slf4j.Slf4j;
39:
40: /***********************************************************************************************************************
41: *
42: * @author Fabrizio Giudici
43: *
44: **********************************************************************************************************************/
45: @Slf4j
46: public class ScaleJ2DOp extends OperationImplementation<ScaleOp, BufferedImage>
47: {
48: private static final List<String> BROKEN_LINUX_CLASSNAMES = Arrays.asList
49: (
50: "sun.awt.motif" +
51: ".X11RemoteOffScreenImage",
52: "sun.java2d.x11" +
53: ".X11RemoteOffScreenImage"
54: // Java 6
55: );
56:
57: /*******************************************************************************************************************
58: *
59: * {@inheritDoc}
60: *
61: ******************************************************************************************************************/
62: @Override
63: protected BufferedImage execute (final ScaleOp operation,
64: final EditableImage image,
65: final BufferedImage bufferedImage)
66: {
67: final var xScale = operation.getXScale();
68: final var yScale = operation.getYScale();
69: final var quality = operation.getQuality();
70: final var sampleModel = bufferedImage.getSampleModel();
71: log.debug("execute(" + xScale + ", " + yScale + ", " + quality);
72: Java2DUtils.logImage(log, ">>>> ", bufferedImage);
73: final var optimizedImage = sampleModel.getClass().equals(SinglePixelPackedSampleModel.class);
74: final BufferedImage result;
75: //
76: // On Mac OS X AffineTransform is extremely slow with non optimized images; but it's faster with optimized ones.
77: //
78:• if ((Platform.isMacOSX() && (quality == Quality.INTERMEDIATE)) && !optimizedImage)
79: {
80: result = Java2DUtils.scaleWithDrawImage(bufferedImage, xScale, yScale, quality);
81: }
82: //
83: // On Linux AffineTransform fails if the underlying class is X11RemoteOffScreenImage.
84: // See http://bluemarine.tidalwave.it/issues/browse/MST-62
85: //
86:• else if ((Platform.isLinux() && BROKEN_LINUX_CLASSNAMES.contains(bufferedImage.getClass().getName())))
87: {
88: result = Java2DUtils.scaleWithDrawImage(bufferedImage, xScale, yScale, quality);
89: }
90:
91: else
92: {
93: result = Java2DUtils.scaleWithAffineTransform(bufferedImage, xScale, yScale, quality);
94: }
95:
96: log.debug(">>>> Scaled image size is: w=" + result.getWidth() + " h=" + result.getHeight());
97:
98: return result;
99: }
100: }