Changeset 223
- Timestamp:
- 04/22/06 16:52:20 (2 years ago)
- Files:
-
- misc/java/src/edu/cmu/cs/cc3/misc/FakePixbuf.java (modified) (4 diffs)
- misc/java/src/edu/cmu/cs/cc3/misc/Test.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
misc/java/src/edu/cmu/cs/cc3/misc/FakePixbuf.java
r222 r223 8 8 public class FakePixbuf extends Pixbuf { 9 9 10 public static final int RAW_WIDTH = 88 * 2; 11 12 public static final int RAW_HEIGHT = 144; 13 10 14 public FakePixbuf() { 11 super( 88 * 2, 144);15 super(RAW_WIDTH, RAW_HEIGHT); 12 16 13 17 // load the image … … 81 85 82 86 // otherwise, load a new thing 83 pixel[offset + off1] = readSubpixel(); // G84 pixel[offset + off0] = readSubpixel(); // G85 secondGreen = readSubpixel(); // G86 pixel[offset + off2] = readSubpixel(); // G87 pixel[offset + off1] = readSubpixel(); 88 pixel[offset + off0] = readSubpixel(); 89 secondGreen = readSubpixel(); 90 pixel[offset + off2] = readSubpixel(); 87 91 88 92 secondGreenValid = true; … … 119 123 read(data, offset, data, offset - 3, 0, 1, 2); 120 124 121 // advance by x_step, but don't go over the edge 122 if (xStep == 1) { 125 // advance by x_step 126 x += xStep; 127 skip((xStep - 1) / 2); 128 } 123 129 124 } else if (xStep + x >= x1) { 125 skip((rawWidth - x - 1) / 2); 126 } else { 127 // printf("inside the window\n"); 128 x += xStep; 129 skip((xStep - 1) / 2); 130 } 131 } 130 skip((rawWidth - x) / 2); 131 132 132 } else { 133 133 // XXX: single channel 134 134 } 135 135 136 // advance by y_step, but don't go over the edge 137 if (yStep == 1) { 138 yLoc++; 139 } else if (yStep + yLoc > y1) { 140 // we're done 141 yLoc += yStep; 142 } else { 143 skip((yStep - 1) * rawWidth / 2); 144 yLoc += yStep; 145 } 136 // advance by y_step 137 skip((yStep - 1) * rawWidth / 2); 138 yLoc += yStep; 146 139 } 147 140 return rows; … … 149 142 150 143 private void seekLeft() { 151 // TODO Auto-generated method stub 152 144 skip(x0 / 2); 153 145 } 154 146 155 147 private void seekTop() { 156 // TODO Auto-generated method stub 148 if (yLoc < y0) { 149 System.out.println("seekTop: y0 = " + y0); 157 150 151 skip(rawWidth / 2 * y0); 152 153 yLoc = y0; 154 } 158 155 } 159 156 } misc/java/src/edu/cmu/cs/cc3/misc/Test.java
r222 r223 1 1 package edu.cmu.cs.cc3.misc; 2 2 3 import java.awt.Color; 3 import java.awt.BorderLayout; 4 import java.awt.GridLayout; 4 5 import java.awt.color.ColorSpace; 5 6 import java.awt.image.BufferedImage; 6 7 7 import javax.swing. ImageIcon;8 import javax.swing. JFrame;9 import javax.swing. JLabel;8 import javax.swing.*; 9 import javax.swing.event.ChangeEvent; 10 import javax.swing.event.ChangeListener; 10 11 11 public class Test {12 public class Test implements ChangeListener { 12 13 13 14 /** … … 15 16 */ 16 17 public static void main(String[] args) { 18 new Test(); 19 } 20 21 JFrame jf; 22 23 JLabel img; 24 25 JPanel controls; 26 27 final JSpinner xStep, yStep, x0, x1, y0, y1; 28 29 public Test() { 30 jf = new JFrame("cc3 test"); 31 jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 32 33 xStep = new JSpinner(new SpinnerNumberModel(1, 1, FakePixbuf.RAW_WIDTH, 34 1)); 35 yStep = new JSpinner(new SpinnerNumberModel(1, 1, 36 FakePixbuf.RAW_HEIGHT, 1)); 37 x0 = new JSpinner(new SpinnerNumberModel(0, 0, FakePixbuf.RAW_WIDTH, 2)); 38 x1 = new JSpinner(new SpinnerNumberModel(FakePixbuf.RAW_WIDTH, 0, 39 FakePixbuf.RAW_WIDTH, 2)); 40 y0 = new JSpinner( 41 new SpinnerNumberModel(0, 0, FakePixbuf.RAW_HEIGHT, 1)); 42 y1 = new JSpinner(new SpinnerNumberModel(FakePixbuf.RAW_HEIGHT, 0, 43 FakePixbuf.RAW_HEIGHT, 1)); 44 45 xStep.addChangeListener(this); 46 yStep.addChangeListener(this); 47 x0.addChangeListener(this); 48 x1.addChangeListener(this); 49 y0.addChangeListener(this); 50 y1.addChangeListener(this); 51 52 reset(); 53 54 controls = new JPanel(); 55 addControls(controls); 56 jf.getContentPane().add(controls, BorderLayout.SOUTH); 57 58 jf.pack(); 59 jf.setVisible(true); 60 } 61 62 private void reset() { 17 63 Pixbuf p = new FakePixbuf(); 64 p.setROI(((Integer) x0.getValue()).intValue(), 65 ((Integer) y0.getValue()).intValue(), ((Integer) x1.getValue()) 66 .intValue(), ((Integer) y1.getValue()).intValue()); 18 67 19 JFrame j = new JFrame("cc3 test"); 20 j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 21 22 j.setSize(400, 400); 23 24 j.setBackground(Color.BLACK); 68 p.setSubsample(((Integer) xStep.getValue()).intValue(), 69 ((Integer) yStep.getValue()).intValue()); 25 70 26 71 BufferedImage b = new BufferedImage(p.getWidth(), p.getHeight(), … … 29 74 fillImage(b, p); 30 75 31 System.out.println(b); 76 if (img == null) { 77 img = new JLabel(new ImageIcon(b)); 78 } else { 79 img.setIcon(new ImageIcon(b)); 80 } 81 jf.getContentPane().add(img); 82 } 32 83 33 JLabel jp = new JLabel(new ImageIcon(b)); 34 j.getContentPane().add(jp); 35 36 j.setVisible(true); 84 private void addControls(JPanel p) { 85 p.setLayout(new GridLayout(6, 2)); 86 p.add(new JLabel("xStep")); 87 p.add(xStep); 88 p.add(new JLabel("yStep")); 89 p.add(yStep); 90 p.add(new JLabel("x0")); 91 p.add(x0); 92 p.add(new JLabel("x1")); 93 p.add(x1); 94 p.add(new JLabel("y0")); 95 p.add(y0); 96 p.add(new JLabel("y1")); 97 p.add(y1); 37 98 } 38 99 39 100 private static void fillImage(BufferedImage b, Pixbuf p) { 40 p.rewind();101 // p.rewind(); 41 102 42 103 byte row[] = p.allocateRows(1); … … 55 116 } 56 117 118 public void stateChanged(ChangeEvent e) { 119 reset(); 120 } 121 57 122 }
