Thanks to Mark and James for spending time on this topic.

> Eeek - this is quite a bad job of rounding!  (Actually, it is even a bad
> job of truncating!  But, in this case, one has to round.) Given that the
> outputs are generally 8-bit component values, being off by 1 is not so hot.

In my use case outputs are not 8-bit component values but 8-bit indexes that
will be rendered using an indexed color model. So +1 or -1 have dramatic
effects. Try this :


import java.awt.* ;
import java.awt.event.* ;
import java.awt.image.* ;
import java.awt.geom.*;
import javax.swing.* ;

class Main extends JFrame
{
        BufferedImage   image ;

        public Main() {
                setSize( new Dimension(200, 200) ) ;

                byte[]  r = new byte[5] ;
                byte[]  g = new byte[5] ;
                byte[]  b = new byte[5] ;

                r[0] = (byte)255 ;
                g[0] = (byte)0 ;
                b[0] = (byte)0 ;

                r[1] = (byte)0 ;
                g[1] = (byte)255 ;
                b[1] = (byte)0 ;

                r[2] = (byte)255 ;
                g[2] = (byte)0 ;
                b[2] = (byte)255 ;

                r[3] = (byte)0 ;
                g[3] = (byte)0 ;
                b[3] = (byte)255 ;

                r[4] = (byte)255 ;
                g[4] = (byte)255 ;
                b[4] = (byte)0 ;

                IndexColorModel cm = new IndexColorModel( 8, 5, r, g, b ) ;

                WritableRaster  r_src =
                Raster.createInterleavedRaster(
                        DataBuffer.TYPE_BYTE, 2, 2, 1, null ) ;

                r_src.setSample( 0, 0, 0, 0 ) ;
                r_src.setSample( 0, 1, 0, 4 ) ;
                r_src.setSample( 1, 0, 0, 4 ) ;
                r_src.setSample( 1, 1, 0, 0 ) ;

                AffineTransform t = new AffineTransform() ;
                t.scale( 100.0, 100.0 ) ;

                AffineTransformOp op =
                        new AffineTransformOp(
                                t, AffineTransformOp.TYPE_BILINEAR ) ;

                WritableRaster  r_dst = op.filter( r_src, null ) ;

                image = new BufferedImage(
                        cm, r_dst, cm.isAlphaPremultiplied(), null);

        }

        public void paint (Graphics g) {

                Graphics2D g2 = (Graphics2D) g;

                AffineTransformOp xop =
                        new AffineTransformOp(
                                new AffineTransform(),
                                AffineTransformOp.TYPE_NEAREST_NEIGHBOR ) ;

                g2.drawImage( image, xop, 0, 0 ) ;
        }

        public static void main( String args[] ) {
                new Main().setVisible( true ) ;
        }
}

No comment about the result you get.

The reason why I'm trying to use AffineTranformOp this way is that our
images are built from real-world datas. For instance a ground elevation map.
For each sample in the map we have a pixel in the image.
We define a finite color table and we associate every color in the table to
a range of elevations in the map.
Thus, the image is an indexed image. Suppose that the color table is
[white,red,black] and You have two contiguous pixels [0,2]. If we draw the
image using an AffineTransformOp that leads to three pixels, we want to
obtain [white,red,black], not [white,gray,black]. That's the reason why we
want to interpolate indexes, not colors.

Thanks for any suggestion.

Best regards.
Philippe.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to