Changeset 223

Show
Ignore:
Timestamp:
04/22/06 16:52:20 (2 years ago)
Author:
goodea
Message:

simplify things greatly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • misc/java/src/edu/cmu/cs/cc3/misc/FakePixbuf.java

    r222 r223  
    88public class FakePixbuf extends Pixbuf { 
    99 
     10    public static final int RAW_WIDTH = 88 * 2; 
     11 
     12    public static final int RAW_HEIGHT = 144; 
     13 
    1014    public FakePixbuf() { 
    11         super(88 * 2, 144); 
     15        super(RAW_WIDTH, RAW_HEIGHT); 
    1216 
    1317        // load the image 
     
    8185 
    8286            // otherwise, load a new thing 
    83             pixel[offset + off1] = readSubpixel(); // G 
    84             pixel[offset + off0] = readSubpixel(); // G 
    85             secondGreen = readSubpixel(); // G 
    86             pixel[offset + off2] = readSubpixel(); // G 
     87            pixel[offset + off1] = readSubpixel(); 
     88            pixel[offset + off0] = readSubpixel(); 
     89            secondGreen = readSubpixel(); 
     90            pixel[offset + off2] = readSubpixel(); 
    8791 
    8892            secondGreenValid = true; 
     
    119123                    read(data, offset, data, offset - 3, 0, 1, 2); 
    120124 
    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                } 
    123129 
    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 
    132132            } else { 
    133133                // XXX: single channel 
    134134            } 
    135135 
    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; 
    146139        } 
    147140        return rows; 
     
    149142 
    150143    private void seekLeft() { 
    151         // TODO Auto-generated method stub 
    152  
     144        skip(x0 / 2); 
    153145    } 
    154146 
    155147    private void seekTop() { 
    156         // TODO Auto-generated method stub 
     148        if (yLoc < y0) { 
     149            System.out.println("seekTop: y0 = " + y0); 
    157150 
     151            skip(rawWidth / 2 * y0); 
     152 
     153            yLoc = y0; 
     154        } 
    158155    } 
    159156} 
  • misc/java/src/edu/cmu/cs/cc3/misc/Test.java

    r222 r223  
    11package edu.cmu.cs.cc3.misc; 
    22 
    3 import java.awt.Color; 
     3import java.awt.BorderLayout; 
     4import java.awt.GridLayout; 
    45import java.awt.color.ColorSpace; 
    56import java.awt.image.BufferedImage; 
    67 
    7 import javax.swing.ImageIcon
    8 import javax.swing.JFrame
    9 import javax.swing.JLabel
     8import javax.swing.*
     9import javax.swing.event.ChangeEvent
     10import javax.swing.event.ChangeListener
    1011 
    11 public class Test
     12public class Test implements ChangeListener
    1213 
    1314    /** 
     
    1516     */ 
    1617    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() { 
    1763        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()); 
    1867 
    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()); 
    2570 
    2671        BufferedImage b = new BufferedImage(p.getWidth(), p.getHeight(), 
     
    2974        fillImage(b, p); 
    3075 
    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    } 
    3283 
    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); 
    3798    } 
    3899 
    39100    private static void fillImage(BufferedImage b, Pixbuf p) { 
    40         p.rewind(); 
     101//        p.rewind(); 
    41102 
    42103        byte row[] = p.allocateRows(1); 
     
    55116    } 
    56117 
     118    public void stateChanged(ChangeEvent e) { 
     119        reset(); 
     120    } 
     121 
    57122}