Creates a JMF Buffer
object for the given AWT Image
and frameRate. If the frameRate parameter of the output format is
not relevant to your needs, then any value can be specified as the
frameRate. If you are generating live video data that is to be
presented by JMF, then you should specify a reasonable value between
1 and 60 for the frameRate.The output buffer will have unspecified
values for the flags, sequenceNumber, header and timeStamp
fields. Only the format, data, offset and length
will
contain valid values.
int width, height, scan;
int [] data;
int redMask, greenMask, blueMask;
Dimension size;
PixelGrabber pg;
ColorModel cm;
DirectColorModel dcm;
Buffer buffer;
if (image == null)
return null;
// Need image observer to get the image size
if (iobs == null) {
iobs = new ImageObserver() {
public boolean imageUpdate(Image im, int info,
int x, int y, int w, int h) {
return false;
}
} ;
}
// Get the size
width = image.getWidth(iobs);
height = image.getHeight(iobs);
if (width < 1 || height < 1)
return null;
scan = (width + 3) & ~3;
size = new Dimension(width, height);
data = new int[scan * height];
// Get the pixels into an int array
pg = new PixelGrabber(image, 0, 0, width, height,
data, 0, scan);
try {
pg.grabPixels();
} catch (InterruptedException ie) {
return null;
}
cm = pg.getColorModel();
if (!(cm instanceof DirectColorModel)) // Cant do if not DCM
return null;
dcm = (DirectColorModel) cm;
redMask = dcm.getRedMask();
greenMask = dcm.getGreenMask();
blueMask = dcm.getBlueMask();
if ( (redMask | greenMask | blueMask) != 0xFFFFFF )
return null;
// Format for creating the buffer
RGBFormat rgb = new RGBFormat(size,
scan * height,
Format.intArray,
frameRate,
32,
redMask, greenMask, blueMask,
1, scan,
RGBFormat.FALSE,
Format.NOT_SPECIFIED);
buffer = new Buffer();
buffer.setOffset(0);
buffer.setLength(scan * height);
buffer.setHeader(null);
buffer.setFlags(0);
buffer.setData(data);
buffer.setFormat(rgb);
buffer.setTimeStamp(-1);
buffer.setSequenceNumber(0);
return buffer;