Changeset 225

Show
Ignore:
Timestamp:
04/22/06 23:55:27 (2 years ago)
Author:
goodea
Message:

implement coi

Files:

Legend:

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

    r224 r225  
    119119            seekLeft(); 
    120120 
    121             if (coi == CHANNEL_ALL) { 
     121            switch (coi) { 
     122            case CHANNEL_ALL: 
    122123                for (int j = 0; j < width; j++) { 
    123124                    int offset = r * width + j * 3; 
     
    129130                } 
    130131 
    131                 skip((rawWidth - x) / 2); 
    132  
    133             } else { 
    134                 // XXX: single channel 
     132                break; 
     133            case CHANNEL_RED: 
     134                for (int j = 0; j < width; j++) { 
     135                    int offset = r * width + j; 
     136 
     137                    if ((j & 0x1) == 0 || xStep > 1) { 
     138                        // read 
     139                        skipSubpixel(); 
     140                        data[offset] = readSubpixel(); 
     141                        skipSubpixel(); 
     142                        skipSubpixel(); 
     143                    } else { 
     144                        data[offset] = data[offset - 1]; 
     145                    } 
     146 
     147                    // advance by x_step 
     148                    x += xStep; 
     149                    skip((xStep - 1) / 2); 
     150                } 
     151                break; 
     152 
     153            case CHANNEL_GREEN: 
     154                for (int j = 0; j < width; j++) { 
     155                    int offset = r * width + j; 
     156 
     157                    if ((j & 0x1) == 0 || xStep > 1) { 
     158                        // read 
     159                        data[offset] = readSubpixel(); 
     160                        skipSubpixel(); 
     161                        secondGreen = readSubpixel(); 
     162                        skipSubpixel(); 
     163                    } else { 
     164                        data[offset] = secondGreen; 
     165                    } 
     166 
     167                    // advance by x_step 
     168                    x += xStep; 
     169                    skip((xStep - 1) / 2); 
     170                } 
     171                break; 
     172 
     173            case CHANNEL_BLUE: 
     174                for (int j = 0; j < width; j++) { 
     175                    int offset = r * width + j; 
     176 
     177                    if ((j & 0x1) == 0 || xStep > 1) { 
     178                        // read 
     179                        skipSubpixel(); 
     180                        skipSubpixel(); 
     181                        skipSubpixel(); 
     182                        data[offset] = readSubpixel(); 
     183                    } else { 
     184                        data[offset] = data[offset - 1]; 
     185                    } 
     186 
     187                    // advance by x_step 
     188                    x += xStep; 
     189                    skip((xStep - 1) / 2); 
     190                } 
     191                break; 
    135192            } 
     193            skip((rawWidth - x) / 2); 
    136194 
    137195            // advance by y_step 
  • misc/java/src/edu/cmu/cs/cc3/misc/Pixbuf.java

    r224 r225  
    118118        return width; 
    119119    } 
     120     
     121    public int getChannels() { 
     122        return coi == CHANNEL_ALL ? 3 : 1; 
     123    } 
    120124 
    121125    private void updateFrameBounds() { 
  • misc/java/src/edu/cmu/cs/cc3/misc/Test.java

    r224 r225  
    44import java.awt.GridLayout; 
    55import java.awt.color.ColorSpace; 
     6import java.awt.event.ActionEvent; 
     7import java.awt.event.ActionListener; 
    68import java.awt.image.BufferedImage; 
    79 
     
    1012import javax.swing.event.ChangeListener; 
    1113 
    12 public class Test implements ChangeListener
     14public class Test implements ChangeListener, ActionListener
    1315 
    1416    /** 
     
    2729    final JSpinner xStep, yStep, x0, x1, y0, y1; 
    2830 
     31    final JComboBox coi; 
     32 
    2933    Pixbuf p = new FakePixbuf(); 
    30      
     34 
    3135    public Test() { 
    3236        jf = new JFrame("cc3 test"); 
     
    4448        y1 = new JSpinner(new SpinnerNumberModel(FakePixbuf.RAW_HEIGHT, 0, 
    4549                FakePixbuf.RAW_HEIGHT, 1)); 
     50        coi = new JComboBox(new String[] { "Red", "Green", "Blue", "All" }); 
     51        coi.setSelectedIndex(3); 
     52        coi.setEditable(false); 
    4653 
    4754        xStep.addChangeListener(this); 
     
    5158        y0.addChangeListener(this); 
    5259        y1.addChangeListener(this); 
     60        coi.addActionListener(this); 
    5361 
    5462        reset(); 
     
    7078                ((Integer) yStep.getValue()).intValue()); 
    7179 
    72         BufferedImage b = new BufferedImage(p.getWidth(), p.getHeight(), 
    73                 ColorSpace.TYPE_RGB); 
     80        p.setCOI(coi.getSelectedIndex()); 
     81 
     82        int cs = ColorSpace.TYPE_RGB; 
     83        BufferedImage b = new BufferedImage(p.getWidth(), p.getHeight(), cs); 
    7484 
    7585        fillImage(b, p); 
     
    8494 
    8595    private void addControls(JPanel p) { 
    86         p.setLayout(new GridLayout(6, 2)); 
     96        p.setLayout(new GridLayout(7, 2)); 
    8797        p.add(new JLabel("xStep")); 
    8898        p.add(xStep); 
     
    97107        p.add(new JLabel("y1")); 
    98108        p.add(y1); 
     109        p.add(new JLabel("COI")); 
     110        p.add(coi); 
    99111    } 
    100112 
     
    104116        byte row[] = p.allocateRows(1); 
    105117 
    106         System.out.println(row.length); 
    107         System.out.println("w: " + p.getWidth() + ", h: " + p.getHeight()); 
    108118        for (int y = 0; y < p.getHeight(); y++) { 
    109119            int i = 0; 
    110120            p.readRows(row, 1); 
    111             for (int x = 0; x < p.getWidth(); x++) { 
    112                 b.setRGB(x, y, (row[i] & 0xFF) << 16 | (row[i + 1] & 0xFF) << 8 
    113                         | (row[i + 2] & 0xFF)); 
    114                 i += 3; 
     121 
     122            if (p.getChannels() == 3) { 
     123                for (int x = 0; x < p.getWidth(); x++) { 
     124                    b.setRGB(x, y, (row[i] & 0xFF) << 16 
     125                            | (row[i + 1] & 0xFF) << 8 | (row[i + 2] & 0xFF)); 
     126                    i += 3; 
     127                } 
     128            } else { 
     129                for (int x = 0; x < p.getWidth(); x++) { 
     130                    b.setRGB(x, y, (row[i] & 0xFF) << 16 
     131                            | (row[i] & 0xFF) << 8 | (row[i] & 0xFF)); 
     132                    i += 1; 
     133                } 
    115134            } 
    116135        } 
     
    121140    } 
    122141 
     142    public void actionPerformed(ActionEvent e) { 
     143        reset(); 
     144    } 
     145 
    123146}