/* * @(#) ImageDataViewer.java 1.0 99/10/4 * Copyright (c) 1999 Larry Rodrigues */ package app; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import javax.swing.*; import javax.swing.event.*; import java.awt.color.*; import java.beans.*; import com.vistech.util.*; import vis.beans.plotter.*; import java.util.*; import com.sun.image.codec.jpeg.*; /** An application that displays image information. * @version 1.0 10 April 1999 * @author Lawrence Rodrigues */ public class ImageDataViewer extends JPanel { ImagePanel viewer; BufferedImage image = null; JTable imageInfoTable; JTable imageStatsTable; int imageWidth, imageHeight; JFrame plotFrame, histoFrame; public static BufferedImage readAsBufferedImage(String filename) { try { FileInputStream fis = new FileInputStream(filename); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(fis); BufferedImage bi = decoder.decodeAsBufferedImage(); return bi; } catch(Exception e) { System.out.println(e); return null; } } public void displayStats(ColorModel cm, SampleModel sm, DataBuffer db){ ColorSpace cs = cm.getColorSpace(); int numComponents = sm.getNumBands(); String name[] = new String[numComponents]; //System.out.println("num components = "+ numComponents); for(int i=0;i= numBins) y[numBins-1]++; y[k]++; } xyp.addGraph(x, y); xyp.addLegend(col[i], colstr[i]); y = new int[numBins]; } xyp.setTitleString(" "); xyp.setXLabelString("Sample Values"); xyp.setYLabelString("Frequency"); xyp.repaint(); }catch (Exception e) { System.out.println(e); } } public void loadAndDisplay(String filename){ image = readAsBufferedImage(filename); BufferedImage img = convertPackedToInterleaved(image); displayImage(img); } public void displayImage(BufferedImage img) { image = img; int width = img.getWidth(); int height = img.getHeight(); displayImageInfo(img); displayImage(img, width, height); } public void displayImage(BufferedImage img, int width, int height) { JFrame fr = new JFrame(); fr.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e){ System.exit(0); } } ); fr.setTitle("Image Data Viewer"); viewer = new ImagePanel(img); viewer.addMouseListener(new LaunchMenuAdapter()); JScrollPane infojs = new JScrollPane(imageInfoTable); infojs.setBorder(BorderFactory.createTitledBorder("Image Info")); JScrollPane statsjs = new JScrollPane(imageStatsTable); statsjs.setBorder(BorderFactory.createTitledBorder("Image Statistics")); JSplitPane vsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, statsjs,infojs); vsp.setDividerLocation((int)(height/4)); viewer.setPreferredSize(new Dimension(width, height)); JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, viewer, vsp); Container cp = fr.getContentPane(); fr.getContentPane().setLayout(new GridLayout(1,1)); cp.add(sp); fr.pack(); fr.setSize(new Dimension(width+ (int)(width/2), height)); fr.show(); sp.setDividerLocation(0.6); viewer.repaint(); } public static String[][] getImageInfo(BufferedImage img) { SampleModel sm = img.getSampleModel(); WritableRaster wr = img.getRaster(); DataBuffer db = wr.getDataBuffer(); ColorModel cm = img.getColorModel(); String str = ImageInfoUtil.getColorModelAsText(ImageInfoUtil.getColorModelType(cm)); ColorSpace cs = cm.getColorSpace(); String[][] rowData = new String[10][2]; int i =0; rowData[i][0] = "Color Model"; rowData[i++][1] = str; rowData[i][0] = "Color space"; rowData[i++][1] = ImageInfoUtil.getColorSpaceAsText(cs.getType()); rowData[i][0] = "Sample Model"; rowData[i++][1] = ImageInfoUtil.getSampleModelAsText(ImageInfoUtil.getSampleModelType(sm)); //DataBuffer db = wr.getDataBuffer(); rowData[i][0] = "Data type"; rowData[i++][1] = ImageInfoUtil.getDataTypeAsText(db.getDataType()); int numbands = sm.getNumBands(); rowData[i][0] = "Number of Bands"; rowData[i++][1] = Integer.toString(numbands); int numbanks = db.getNumBanks(); rowData[i][0] = "Number of Banks"; rowData[i++][1] = Integer.toString(numbanks); rowData[i][0] = "Width"; rowData[i++][1] = Integer.toString(img.getWidth()); rowData[i][0] = "Height"; rowData[i++][1] = Integer.toString(img.getHeight()); int scanlineStride=0; if(sm instanceof ComponentSampleModel) { ComponentSampleModel csm = (ComponentSampleModel)sm; scanlineStride = csm.getScanlineStride(); rowData[i][0] = "Scanline stride"; rowData[i++][1] = Integer.toString(scanlineStride); int pixelStride = csm.getPixelStride(); rowData[i][0] = "Pixel stride"; rowData[i++][1] = Integer.toString(pixelStride); //int[] bankIndices = csm.getBankIndices(); //System.out.println("bank indices = " ); //for(int j=0; j