Skip to content

Package: Main

Main

nameinstructionbranchcomplexitylinemethod
Main()
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%
main(String[])
M: 134 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 36 C: 0
0%
M: 1 C: 0
0%
static {...}
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.mistral.example.histogramviewer;
28:
29: import java.security.AccessControlException;
30: import java.io.IOException;
31: import java.awt.BorderLayout;
32: import java.awt.Color;
33: import javax.swing.BorderFactory;
34: import javax.swing.JFrame;
35: import javax.swing.JLabel;
36: import javax.swing.JPanel;
37: import javax.swing.SwingConstants;
38: import it.tidalwave.image.EditableImage;
39: import it.tidalwave.image.java2d.ImplementationFactoryJ2D;
40: import it.tidalwave.image.op.HistogramOp;
41: import it.tidalwave.image.util.Platform;
42: import it.tidalwave.mistral.example.AbstractViewerPanel;
43:
44: /***********************************************************************************************************************
45: *
46: * @author Fabrizio Giudici
47: *
48: **********************************************************************************************************************/
49: public class Main
50: {
51: private static boolean jai = false;
52:
53: public static void main (final String[] args)
54: throws IOException
55: {
56:• if (!Platform.isMacOSX())
57: {
58: try
59: {
60: System.setProperty("swing.aatext", "true");
61: }
62: catch (AccessControlException e)
63: {
64: System.err.println("Can't set anti-aliased text because of: " + e);
65: }
66: }
67:
68: final var statusBar = new JLabel(" ", SwingConstants.LEFT);
69: statusBar.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
70: final var frame = new JFrame("Mistral Histogram Viewer example");
71: final var p = new JPanel(new BorderLayout());
72: p.add(statusBar, BorderLayout.SOUTH);
73: frame.getContentPane().add(p);
74:
75: final var histogramRenderer = new HistogramRenderer();
76: histogramRenderer.setBounds(20, 20, 200, 150);
77: final var panel = new JPanel();
78: panel.setLayout(null);
79: panel.setOpaque(false);
80: panel.add(histogramRenderer);
81: frame.setGlassPane(panel);
82: panel.setVisible(true);
83: histogramRenderer.setBackground(new Color(0, 0, 0, 128));
84: histogramRenderer.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
85: histogramRenderer.showComputing();
86: histogramRenderer.setVisible(true);
87:
88: final var viewerPanel = new AbstractViewerPanel()
89: {
90: {
91: setLayout(new BorderLayout());
92: add(imageRenderer, BorderLayout.CENTER);
93: }
94:
95: @Override
96: protected void onImageLoaded (final EditableImage image)
97: {
98: imageRenderer.setFitToDisplaySize(true);
99: //
100: // HistogramOp can take some time to perform.
101: //
102: final var thread = new Thread(() ->
103: {
104: histogramRenderer.start();
105: var time = System.currentTimeMillis();
106: final var histogram = image.executeInPlace(new HistogramOp()).getHistogram();
107: time = System.currentTimeMillis() - time;
108: histogramRenderer.setHistogram(histogram);
109: statusBar.setText("Computed in " + time + " msec " + (jai ? "with" : "without") + " JAI");
110: });
111:
112: thread.start();
113: }
114: };
115:
116: p.add(viewerPanel, BorderLayout.CENTER);
117: viewerPanel.loadImage("20040103-0080.jpg");
118:
119: frame.setSize(800, 554);
120: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
121: frame.setVisible(true);
122:
123: //
124: // Try to activate the JAI provider - if you manage, disable the Java2D
125: // implementation of HistogramOp.
126: //
127: try
128: {
129: Class.forName("it.tidalwave.image.jai.ImplementationFactoryJAI");
130: ImplementationFactoryJ2D.getDefault().unregisterImplementation(HistogramOp.class);
131: jai = true;
132: }
133: catch (Throwable e)
134: {
135: System.err.println("JAI is not available");
136: }
137: }
138: }