Changeset 222

Show
Ignore:
Timestamp:
04/22/06 15:21:25 (2 years ago)
Author:
goodea
Message:

works, with standard, broken algorithm

Files:

Legend:

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

    r221 r222  
    2020 
    2121        fifo = new byte[rawWidth / 2 * 4 * rawHeight]; 
    22          
     22 
    2323        int i = 0; 
    2424        for (int y = 0; y < rawHeight; y++) { 
     
    2727                int p1 = im.getRGB(x, y); 
    2828                int p2 = im.getRGB(x + 1, y); 
    29                  
     29 
     30                // simulate Bayer 
     31                // GR 
     32                // BG 
     33 
    3034                // G 
    3135                fifo[i] = (byte) ((p1 >>> 8) & 0xFF); 
    3236                // R 
    33                 fifo[i + 1] = (byte) ((p1 >>> 16) & 0xFF); 
     37                fifo[i + 1] = (byte) ((p2 >>> 16) & 0xFF); 
    3438                // G 
    3539                fifo[i + 2] = (byte) ((p2 >>> 8) & 0xFF); 
    3640                // B 
    37                 fifo[i + 3] = (byte) (p2 & 0xFF); 
    38                  
     41                fifo[i + 3] = (byte) (p1 & 0xFF); 
     42 
    3943                i += 4; 
    4044            } 
     
    5155    } 
    5256 
    53     byte read() { 
     57    byte readSubpixel() { 
    5458        return fifo[cursor++]; 
    5559    } 
    5660 
    57     void skip() { 
     61    void skipSubpixel() { 
    5862        cursor++; 
    5963    } 
    6064 
    61     @Override 
    62     public void readRows(byte[] data, int rows) { 
    63         // TODO Auto-generated method stub 
    64          
     65    private boolean secondGreenValid; 
     66 
     67    private byte secondGreen; 
     68 
     69    void read(byte[] pixel, int offset, byte[] saved, int sOffset, int off0, 
     70            int off1, int off2) { 
     71        if (xStep == 1) { 
     72            if (secondGreenValid) { 
     73                // use the second green 
     74                secondGreenValid = false; 
     75                pixel[offset + off0] = saved[sOffset + off0]; 
     76                pixel[offset + off1] = secondGreen; 
     77                pixel[offset + off2] = saved[sOffset + off2]; 
     78 
     79                return; 
     80            } 
     81 
     82            // 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 
     88            secondGreenValid = true; 
     89        } else { 
     90            skipSubpixel(); 
     91            pixel[offset + off0] = readSubpixel(); 
     92            pixel[offset + off1] = readSubpixel(); 
     93            pixel[offset + off2] = readSubpixel(); 
     94        } 
    6595    } 
    6696 
     97    void skip(int i) { 
     98        for (int z = 0; z < i; z++) { 
     99            skipSubpixel(); 
     100            skipSubpixel(); 
     101            skipSubpixel(); 
     102            skipSubpixel(); 
     103        } 
     104    } 
     105 
     106    @Override 
     107    public int readRows(byte[] data, int rows) { 
     108        // First read into frame 
     109        seekTop(); 
     110 
     111        for (int r = 0; r < rows; r++) { 
     112            int x = x0; 
     113            // First read into line 
     114            seekLeft(); 
     115 
     116            if (coi == CHANNEL_ALL) { 
     117                for (int j = 0; j < width; j++) { 
     118                    int offset = r * width + j * 3; 
     119                    read(data, offset, data, offset - 3, 0, 1, 2); 
     120 
     121                    // advance by x_step, but don't go over the edge 
     122                    if (xStep == 1) { 
     123 
     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                } 
     132            } else { 
     133                // XXX: single channel 
     134            } 
     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            } 
     146        } 
     147        return rows; 
     148    } 
     149 
     150    private void seekLeft() { 
     151        // TODO Auto-generated method stub 
     152 
     153    } 
     154 
     155    private void seekTop() { 
     156        // TODO Auto-generated method stub 
     157 
     158    } 
    67159} 
  • misc/java/src/edu/cmu/cs/cc3/misc/Pixbuf.java

    r221 r222  
    105105    } 
    106106 
    107     public abstract void readRows(byte[] data, int rows); 
     107    public abstract int readRows(byte[] data, int rows); 
    108108     
    109109    public void setCOI(int channel) { 
  • misc/java/src/edu/cmu/cs/cc3/misc/Test.java

    r221 r222  
    3030 
    3131        System.out.println(b); 
    32          
     32 
    3333        JLabel jp = new JLabel(new ImageIcon(b)); 
    3434        j.getContentPane().add(jp); 
     
    4848            p.readRows(row, 1); 
    4949            for (int x = 0; x < p.getWidth(); x++) { 
    50                 b.setRGB(x, y, row[i] << 16 | row[i + 1] << 8 | row[i + 2]); 
     50                b.setRGB(x, y, (row[i] & 0xFF) << 16 | (row[i + 1] & 0xFF) << 8 
     51                        | (row[i + 2] & 0xFF)); 
    5152                i += 3; 
    5253            }