Skip to content

Method: toString()

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;
28:
29: import javax.annotation.Nonnull;
30: import java.awt.image.Kernel;
31:
32: /***********************************************************************************************************************
33: *
34: * This class just adds to the standard Kernel the toString() implementation.
35: *
36: * @author Fabrizio Giudici
37: *
38: **********************************************************************************************************************/
39: public class Kernel2 extends Kernel
40: {
41: // private float[] data;
42:
43: /*******************************************************************************************************************
44: *
45: *
46: ******************************************************************************************************************/
47: public Kernel2 (final int width, final int height, final float[] data)
48: {
49: super(width, height, data);
50: // this.data = new float[data.length];
51: // System.arraycopy(data, 0, this.data, 0, data.length);
52: }
53:
54: /*******************************************************************************************************************
55: *
56: *
57: ******************************************************************************************************************/
58: @Override @Nonnull
59: public String toString()
60: {
61: final var buffer = new StringBuilder("Kernel2[");
62: buffer.append(getWidth());
63: buffer.append("x");
64: buffer.append(getHeight());
65: buffer.append(", ");
66:
67: buffer.append(getXOrigin());
68: buffer.append(";");
69: buffer.append(getYOrigin());
70:
71: final var data = getKernelData(null);
72:
73:• for (var i = 0; i < data.length; i++)
74: {
75:• if ((i % getWidth()) == 0)
76: {
77: buffer.append("\n ");
78: }
79:
80:• else if (i > 0)
81: {
82: buffer.append(", ");
83: }
84:
85: buffer.append(data[i]);
86: }
87:
88: buffer.append("]");
89:
90: return buffer.toString();
91: }
92: }