FileDocCategorySizeDatePackage
BufferToBufferedImage.javaAPI DocJMF 2.1.1e1879Mon May 12 12:20:46 BST 2003com.sun.media.util

BufferToBufferedImage

public class BufferToBufferedImage extends BufferToImage

Fields Summary
Constructors Summary
public BufferToBufferedImage()

	super(null);
	Class.forName("java.awt.Graphics2D");
    
public BufferToBufferedImage(VideoFormat format)

	super(format);
	Class.forName("java.awt.Graphics2D");
    
Methods Summary
public java.awt.ImagecreateImage(javax.media.Buffer buffer)

	RGBFormat format = (RGBFormat) buffer.getFormat();
	int rMask, gMask, bMask;
	Object data = buffer.getData();
	DirectColorModel dcm;

	rMask = format.getRedMask();
	gMask = format.getGreenMask();
	bMask = format.getBlueMask();
	int [] masks = new int[3];
	masks[0] = rMask;
	masks[1] = gMask;
	masks[2] = bMask;

	DataBuffer db = new DataBufferInt((int[])data,
					  format.getLineStride() *
					  format.getSize().height);

	SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
							  format.getLineStride(),
							  format.getSize().height,
							  masks);
	WritableRaster wr = Raster.createWritableRaster(sm, db, new Point(0, 0));

	dcm = new DirectColorModel(24, rMask, gMask, bMask);
	BufferedImage sourceImage = new BufferedImage((ColorModel)dcm, wr, true, null);
	
	AffineTransform at = new AffineTransform(1.0f, 0,
						 0   , 1.0f,
						 0   , 0);
	AffineTransformOp ato = new AffineTransformOp(at, null);

	BufferedImage outputImage = ato.createCompatibleDestImage((BufferedImage)sourceImage,
								  (ColorModel)dcm);
	

	ato.filter(sourceImage, outputImage);
	//System.err.println("Filtered");
	return outputImage;