Buffered image using float data

Discussion in 'Java' started by Peter Ashford, May 2, 2005.

  1. Does anyone know whether there's anwyay to use floating point data to
    make a greyscale BufferedImage?

    I'd like this because I want an image I can edit and get the results
    directly in floating point format. There's a unsigned 16bit format
    which is better than 8bit, but I'm using the data for heightfield info
    which doesn't need to be restricted to 16 bit int accuracy.

    Ideas?

    TIA.
    Peter Ashford, May 2, 2005
    #1
    1. Advertising

  2. Peter Ashford

    Betty Guest

    "Peter Ashford" <> wrote in message
    news:...
    > Does anyone know whether there's anwyay to use floating point data to
    > make a greyscale BufferedImage?
    >
    > I'd like this because I want an image I can edit and get the results
    > directly in floating point format. There's a unsigned 16bit format
    > which is better than 8bit, but I'm using the data for heightfield info
    > which doesn't need to be restricted to 16 bit int accuracy.
    >

    You could keep your data in floating point separate from the BufferedImage
    and convert it when you want to put it on the screen.
    Betty, May 2, 2005
    #2
    1. Advertising

  3. Betty wrote:
    > "Peter Ashford" <> wrote in message
    > news:...
    >
    >>Does anyone know whether there's anwyay to use floating point data to
    >>make a greyscale BufferedImage?
    >>
    >>I'd like this because I want an image I can edit and get the results
    >>directly in floating point format. There's a unsigned 16bit format
    >>which is better than 8bit, but I'm using the data for heightfield info
    >>which doesn't need to be restricted to 16 bit int accuracy.
    >>

    >
    > You could keep your data in floating point separate from the BufferedImage
    > and convert it when you want to put it on the screen.
    >
    >


    True. However, I will be updating a 3d image on the basis on the data
    in the bitmap and editing the bitmap, converting the results and
    updating the 3d image will be much slower than getting the data directly
    from the bitmap in the correct format.

    More significantly, as the edits to the buffered image are being used to
    alter the heightmap, if the image uses 16bit int accuracy, it will apply
    that limitation to the float buffer. This is the problem I'm trying to
    avoid in the first place. If it weren't for this problem I could just
    use a 16bit greyscale image for the data and live with the resolution
    restraints.
    Peter Ashford, May 2, 2005
    #3
  4. "Peter Ashford" <> schreef in bericht
    news:...
    > Does anyone know whether there's anwyay to use floating point data to make a
    > greyscale BufferedImage?
    >
    > I'd like this because I want an image I can edit and get the results
    > directly in floating point format. There's a unsigned 16bit format which is
    > better than 8bit, but I'm using the data for heightfield info which doesn't
    > need to be restricted to 16 bit int accuracy.
    >
    > Ideas?


    SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_FLOAT, w, h, 1, w,
    new int[] {0});
    DataBuffer db = new DataBufferFloat(w * h);
    WritableRaster wr = Raster.createRaster(sm, db, null);
    ColorSpace cs = ColorSpace.getInstance(CS_GRAY);
    ColorModel cm = new ComponentColorModel(cs, false, true, Transparency.OPAQUE,
    DataBuffer.TYPE_FLOAT);
    BufferedImage bi = new BufferedImage(cm, wr, true, null);
    Boudewijn Dijkstra, May 2, 2005
    #4
  5. "Boudewijn Dijkstra" <> schreef in bericht
    news:427603ce$0$1368$...
    > "Peter Ashford" <> schreef in bericht
    > news:...
    >> Does anyone know whether there's anwyay to use floating point data to make
    >> a >> greyscale BufferedImage?
    >>
    >> I'd like this because I want an image I can edit and get the results
    >> directly in floating point format. There's a unsigned 16bit format which
    >> is >> better than 8bit, but I'm using the data for heightfield info which
    >> doesn't need to be restricted to 16 bit int accuracy.
    >>
    >> Ideas?


    Errors corrected from last try; test suite added. ;)


    public static void main(String[] args)
    {
    final int w = 320;
    final int h = 240;

    SampleModel sm = new ComponentSampleModel(
    DataBuffer.TYPE_FLOAT, w, h, 1, w, new int[] {0});
    DataBuffer db = new DataBufferFloat(w * h);
    WritableRaster wr = Raster.createWritableRaster(sm, db, null);
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorModel cm = new ComponentColorModel(
    cs, false, true, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
    final BufferedImage bi = new BufferedImage(cm, wr, true, null);

    Graphics2D g2 = bi.createGraphics();
    g2.setRenderingHint(
    RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.BLACK);
    g2.fillRect(0, 0, w, h);
    g2.setColor(Color.WHITE);
    g2.drawLine(0, 0, w, h);
    g2.drawLine(w, 0, 0, h);
    g2.drawOval(w/4, h/4, w/2, h/2);
    g2.dispose();

    Frame f = new Frame("Float Graphics");
    f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    System.exit(0);
    }
    });
    f.setLayout(new BorderLayout());
    Canvas c = new Canvas() {
    public void paint(Graphics g) {
    g.drawImage(bi, 0, 0, null);
    }
    };
    c.setSize(w, h);
    f.add(c, BorderLayout.CENTER);
    f.pack();
    f.show();
    }
    Boudewijn Dijkstra, May 2, 2005
    #5
  6. Boudewijn Dijkstra wrote:
    > "Boudewijn Dijkstra" <> schreef in bericht
    > news:427603ce$0$1368$...
    >
    >>"Peter Ashford" <> schreef in bericht
    >>news:...
    >>
    >>>Does anyone know whether there's anwyay to use floating point data to make
    >>>a >> greyscale BufferedImage?
    >>>
    >>>I'd like this because I want an image I can edit and get the results
    >>>directly in floating point format. There's a unsigned 16bit format which
    >>>is >> better than 8bit, but I'm using the data for heightfield info which
    >>>doesn't need to be restricted to 16 bit int accuracy.
    >>>
    >>>Ideas?

    >
    >
    > Errors corrected from last try; test suite added. ;)


    <code snipped>

    Awesome! Great! Thanks very much - looks like exactly what I needed.
    Thanks for the effort :eek:)

    Peter.
    Peter Ashford, May 2, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tochaotic4u
    Replies:
    2
    Views:
    4,033
    tochaotic4u
    Jul 3, 2003
  2. bd
    Replies:
    0
    Views:
    602
  3. Replies:
    9
    Views:
    660
    Michael Wojcik
    Aug 23, 2005
  4. Ex1991

    Image to Buffered Image?

    Ex1991, Mar 25, 2009, in forum: Java
    Replies:
    0
    Views:
    362
    Ex1991
    Mar 25, 2009
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,499
    James Kanze
    Oct 8, 2009
Loading...

Share This Page