Changeset 225
- Timestamp:
- 04/22/06 23:55:27 (2 years ago)
- Files:
-
- misc/java/src/edu/cmu/cs/cc3/misc/FakePixbuf.java (modified) (2 diffs)
- misc/java/src/edu/cmu/cs/cc3/misc/Pixbuf.java (modified) (1 diff)
- misc/java/src/edu/cmu/cs/cc3/misc/Test.java (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
misc/java/src/edu/cmu/cs/cc3/misc/FakePixbuf.java
r224 r225 119 119 seekLeft(); 120 120 121 if (coi == CHANNEL_ALL) { 121 switch (coi) { 122 case CHANNEL_ALL: 122 123 for (int j = 0; j < width; j++) { 123 124 int offset = r * width + j * 3; … … 129 130 } 130 131 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; 135 192 } 193 skip((rawWidth - x) / 2); 136 194 137 195 // advance by y_step misc/java/src/edu/cmu/cs/cc3/misc/Pixbuf.java
r224 r225 118 118 return width; 119 119 } 120 121 public int getChannels() { 122 return coi == CHANNEL_ALL ? 3 : 1; 123 } 120 124 121 125 private void updateFrameBounds() { misc/java/src/edu/cmu/cs/cc3/misc/Test.java
r224 r225 4 4 import java.awt.GridLayout; 5 5 import java.awt.color.ColorSpace; 6 import java.awt.event.ActionEvent; 7 import java.awt.event.ActionListener; 6 8 import java.awt.image.BufferedImage; 7 9 … … 10 12 import javax.swing.event.ChangeListener; 11 13 12 public class Test implements ChangeListener {14 public class Test implements ChangeListener, ActionListener { 13 15 14 16 /** … … 27 29 final JSpinner xStep, yStep, x0, x1, y0, y1; 28 30 31 final JComboBox coi; 32 29 33 Pixbuf p = new FakePixbuf(); 30 34 31 35 public Test() { 32 36 jf = new JFrame("cc3 test"); … … 44 48 y1 = new JSpinner(new SpinnerNumberModel(FakePixbuf.RAW_HEIGHT, 0, 45 49 FakePixbuf.RAW_HEIGHT, 1)); 50 coi = new JComboBox(new String[] { "Red", "Green", "Blue", "All" }); 51 coi.setSelectedIndex(3); 52 coi.setEditable(false); 46 53 47 54 xStep.addChangeListener(this); … … 51 58 y0.addChangeListener(this); 52 59 y1.addChangeListener(this); 60 coi.addActionListener(this); 53 61 54 62 reset(); … … 70 78 ((Integer) yStep.getValue()).intValue()); 71 79 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); 74 84 75 85 fillImage(b, p); … … 84 94 85 95 private void addControls(JPanel p) { 86 p.setLayout(new GridLayout( 6, 2));96 p.setLayout(new GridLayout(7, 2)); 87 97 p.add(new JLabel("xStep")); 88 98 p.add(xStep); … … 97 107 p.add(new JLabel("y1")); 98 108 p.add(y1); 109 p.add(new JLabel("COI")); 110 p.add(coi); 99 111 } 100 112 … … 104 116 byte row[] = p.allocateRows(1); 105 117 106 System.out.println(row.length);107 System.out.println("w: " + p.getWidth() + ", h: " + p.getHeight());108 118 for (int y = 0; y < p.getHeight(); y++) { 109 119 int i = 0; 110 120 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 } 115 134 } 116 135 } … … 121 140 } 122 141 142 public void actionPerformed(ActionEvent e) { 143 reset(); 144 } 145 123 146 }
