[trunk] updated copyright and added copyright notice required by ISO, in each file...
[openjpeg.git] / src / bin / jpip / opj_viewer / src / RegimViewer.java
1 /*
2  * $Id$
3  *
4  * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
5  * Copyright (c) 2002-2014, Professor Benoit Macq
6  * Copyright (c) 2010-2011, Kaori Hagihara
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 import javax.swing.*;
32 import java.awt.*;
33 import java.awt.image.*;
34 import java.awt.geom.AffineTransform;
35
36 public class RegimViewer extends JPanel
37 {  
38     private PnmImage refpnm;
39     private int vw, vh;
40     private Image refimg;
41     private Image jpipImg;
42     private double[] affine_matrix;
43     private AffineTransform affine;
44     
45     public RegimViewer( String refname, double[] mat)
46     {
47         refpnm = new PnmImage( refname.replaceFirst("jp2", "pgm")); // decoding not realized
48         affine_matrix = new double[6];
49
50         affine_matrix[0] = mat[0];
51         affine_matrix[1] = mat[3];
52         affine_matrix[2] = mat[1];
53         affine_matrix[3] = mat[4];
54         affine_matrix[4] = mat[2];
55         affine_matrix[5] = mat[5];
56         
57         affine = new AffineTransform();
58
59         for( int i=0; i<3; i++){
60             for( int j=0; j<3; j++)
61                 System.out.print( mat[i*3+j] + " ");
62             System.out.println();
63         }
64     }
65     
66     public void projection( Image jpipimg, double scale)
67     {
68         jpipImg = jpipimg;
69         refimg = refpnm.createScaleImage( scale);
70         vw = refimg.getWidth(this);
71         vh = refimg.getHeight(this);
72         this.setSize( vw, vh);
73         
74         affine.setTransform( affine_matrix[0], affine_matrix[1], affine_matrix[2], affine_matrix[3], affine_matrix[4], affine_matrix[5]);
75         repaint();
76     }
77     
78     public void paint(Graphics g)
79     {
80         int iw, ih;
81         BufferedImage bi, bi2;
82         Graphics2D big, big2;
83         Graphics2D g2 = (Graphics2D) g;
84                 
85         g2.clearRect(0, 0, vw, vh);
86         
87         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
88                             RenderingHints.VALUE_ANTIALIAS_ON);
89         g2.setRenderingHint(RenderingHints.KEY_RENDERING,
90                             RenderingHints.VALUE_RENDER_QUALITY);
91         
92         iw = refimg.getWidth(this);
93         ih = refimg.getHeight(this);
94         
95         bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
96         big = bi.createGraphics();
97         big.drawImage(refimg, 0, 0, this);
98         
99         g2.drawImage(bi, 0, 0, this);
100
101         bi2 = new BufferedImage( jpipImg.getWidth(this), jpipImg.getHeight(this), BufferedImage.TYPE_INT_RGB);
102         big2 = bi2.createGraphics();
103         big2.drawImage( jpipImg, 0, 0, this);
104         
105         g2.setTransform(affine);
106
107         g2.drawImage(bi2, 0, 0, this);
108     }
109     
110     public Dimension get_imsize()
111     {
112         return (new Dimension( vw, vh));
113     }
114 }