本文整理汇总了Java中javax.media.Buffer.getData方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.getData方法的具体用法?Java Buffer.getData怎么用?Java Buffer.getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.media.Buffer
的用法示例。
在下文中一共展示了Buffer.getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import javax.media.Buffer; //导入方法依赖的package包/类
public int process(Buffer in, Buffer out) {
// This is the "Callback" to access individual frames.
accessFrame(in);
// Swap the data between the input & output.
Object data = in.getData();
in.setData(out.getData());
out.setData(data);
// Copy the input attributes to the output
out.setFormat(in.getFormat());
out.setLength(in.getLength());
out.setOffset(in.getOffset());
return BUFFER_PROCESSED_OK;
}
示例2: validateByteArraySize
import javax.media.Buffer; //导入方法依赖的package包/类
byte[] validateByteArraySize(Buffer buffer,int newSize) {
Object objectArray=buffer.getData();
byte[] typedArray;
if (objectArray instanceof byte[]) { // is correct type AND not null
typedArray=(byte[])objectArray;
if (typedArray.length >= newSize ) { // is sufficient capacity
return typedArray;
}
byte[] tempArray=new byte[newSize]; // re-alloc array
System.arraycopy(typedArray,0,tempArray,0,typedArray.length);
typedArray = tempArray;
} else {
typedArray = new byte[newSize];
}
buffer.setData(typedArray);
return typedArray;
}
示例3: read
import javax.media.Buffer; //导入方法依赖的package包/类
public void read(Buffer buffer) throws IOException {
synchronized (this) {
Object outdata = buffer.getData();
if (outdata == null || !(outdata.getClass() == Format.intArray) ||
((int[])outdata).length < maxDataLength) {
outdata = new int[maxDataLength];
buffer.setData(outdata);
}
buffer.setFormat( rgbFormat );
buffer.setTimeStamp( (long) (seqNo * (1000 / frameRate) * 1000000) );
BufferedImage bi = robot.createScreenCapture(
new Rectangle(x, y, width, height));
bi.getRGB(0, 0, width, height,
(int[])outdata, 0, width);
buffer.setSequenceNumber( seqNo );
buffer.setLength(maxDataLength);
buffer.setFlags(Buffer.FLAG_KEY_FRAME);
buffer.setHeader( null );
seqNo++;
}
}
示例4: readHeader
import javax.media.Buffer; //导入方法依赖的package包/类
/** Reads the image header.
* Does nothing if the header has already been loaded.
*/
private void readHeader() throws IOException {
if (image == null) {
ImageReader r = new JPEGImageReader(getOriginatingProvider());
Object in = getInput();
if (in instanceof Buffer) {
Buffer buffer = (Buffer) in;
in=buffer.getData();
}
if (in instanceof byte[]) {
r.setInput(new MemoryCacheImageInputStream(AVIBMPDIB.prependDHTSeg((byte[]) in)));
} else if (in instanceof ImageInputStream) {
r.setInput(AVIBMPDIB.prependDHTSeg((ImageInputStream) in));
} else {
r.setInput(AVIBMPDIB.prependDHTSeg((InputStream) in));
}
image = r.read(0);
}
}
示例5: mute
import javax.media.Buffer; //导入方法依赖的package包/类
/**
* Replaces the media data contained in a specific <tt>Buffer</tt> with a
* compatible representation of silence.
*
* @param buffer the <tt>Buffer</tt> the data contained in which is to be
* replaced with silence
*/
public static void mute(Buffer buffer)
{
Object data = buffer.getData();
if (data != null)
{
Class<?> dataClass = data.getClass();
final int fromIndex = buffer.getOffset();
final int toIndex = fromIndex + buffer.getLength();
if (Format.byteArray.equals(dataClass))
Arrays.fill((byte[]) data, fromIndex, toIndex, (byte) 0);
else if (Format.intArray.equals(dataClass))
Arrays.fill((int[]) data, fromIndex, toIndex, 0);
else if (Format.shortArray.equals(dataClass))
Arrays.fill((short[]) data, fromIndex, toIndex, (short) 0);
buffer.setData(data);
}
}
示例6: process
import javax.media.Buffer; //导入方法依赖的package包/类
/**
* Updates the image to be drawn on the graphics context.
*
* @param buffer the RAW image data.
* @param size the dimension of the image in the buffer.
*/
void process(Buffer buffer, Dimension size)
{
if (mis == null || !this.size.equals(size))
{
this.size = size;
mis =
new MemoryImageSource(size.width, size.height,
(int[]) buffer.getData(), buffer.getOffset(), size.width);
}
else
{
mis.newPixels((int[]) buffer.getData(), ColorModel.getRGBdefault(),
buffer.getOffset(), size.width);
}
this.repaint();
}
示例7: bufferToImage
import javax.media.Buffer; //导入方法依赖的package包/类
/**
* Description of the Method
*
* @param buffer Description of the Parameter
* @return Description of the Return Value
*/
public BufferedImage bufferToImage(Buffer buffer) {
RGBFormat format = (RGBFormat) buffer.getFormat();
int rMask;
int gMask;
int 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);
return new BufferedImage(dcm, wr, true, null);
}
示例8: read
import javax.media.Buffer; //导入方法依赖的package包/类
public void read(Buffer buffer) throws IOException {
synchronized (this) {
Object outdata = buffer.getData();
if (outdata == null || !(outdata.getClass() == Format.byteArray) ||
((byte[])outdata).length < maxDataLength) {
outdata = new byte[maxDataLength];
buffer.setData(outdata);
}
if (videoData) {
buffer.setFormat( rgbFormat );
buffer.setTimeStamp( (long) (seqNo * (1000 / frameRate) * 1000000) );
int lineNo = (seqNo * 2) % size.height;
int chunkStart = lineNo * size.width * 3;
System.arraycopy(data, chunkStart,
outdata, 0,
maxDataLength - (chunkStart));
if (chunkStart != 0) {
System.arraycopy(data, 0,
outdata, maxDataLength - chunkStart,
chunkStart);
}
} else {
buffer.setFormat( audioFormat );
buffer.setTimeStamp( 1000000000 / 8 );
for (int i = 0; i < 1000; i++) {
((byte[])outdata)[i] = (byte) (Math.sin(i / freq) * 32);
freq = (freq + 0.01);
if (freq > 10.0)
freq = 2.0;
}
}
buffer.setSequenceNumber( seqNo );
buffer.setLength(maxDataLength);
buffer.setFlags(0);
buffer.setHeader( null );
seqNo++;
}
}
示例9: doVideoEffect
import javax.media.Buffer; //导入方法依赖的package包/类
void doVideoEffect(Buffer dest, Buffer source /*next*/,
float effectRatio) {
//System.err.println("Doing effect at " + effectRatio);
// Assume wipe
byte[] destData = (byte[]) dest.getData();
byte[] srcData = (byte[]) source.getData();
RGBFormat rgb = (RGBFormat) dest.getFormat();
int videoHeight = rgb.getSize().height;
int stride = rgb.getLineStride();
if (effectRatio > 1.0f)
effectRatio = 1.0f;
if (effectRatio <= 0.0f)
return;
if (effectVideo[currentLocator].equalsIgnoreCase("Scroll")) {
int nInLines = (int) (videoHeight * effectRatio);
if (nInLines == 0)
return;
System.arraycopy(destData, nInLines * stride,
destData, 0,
(videoHeight - nInLines) * stride);
System.arraycopy(srcData, 0,
destData, (videoHeight - nInLines) * stride,
nInLines * stride);
} else if (effectVideo[currentLocator].equalsIgnoreCase("Fade")) {
for (int y = 0; y < videoHeight * stride; y++) {
destData[y] = (byte)
((destData[y] & 0xFF) * (1.0 - effectRatio) +
(srcData[y] & 0xFF) * effectRatio);
}
}
}
示例10: read
import javax.media.Buffer; //导入方法依赖的package包/类
public void read(Buffer buffer) {
//System.err.println("entering read");
synchronized (this) {
while (!dataPending) {
try {
wait();
} catch (InterruptedException ie) {
}
}
}
//System.err.println("... in read");
// Swap
Object data = buffer.getData();
Format format = buffer.getFormat();
Object header = buffer.getHeader();
buffer.setData(pendingBuffer.getData());
buffer.setFormat(pendingBuffer.getFormat());
buffer.setHeader(pendingBuffer.getHeader());
buffer.setTimeStamp(pendingBuffer.getTimeStamp());
buffer.setFlags(pendingBuffer.getFlags() | Buffer.FLAG_NO_SYNC);
buffer.setLength(pendingBuffer.getLength());
buffer.setOffset(pendingBuffer.getOffset());
buffer.setSequenceNumber(pendingBuffer.getSequenceNumber());
pendingBuffer.setData(data);
pendingBuffer.setFormat(format);
pendingBuffer.setHeader(header);
dataPending = false;
synchronized (this) {
notifyAll();
}
}
示例11: process
import javax.media.Buffer; //导入方法依赖的package包/类
@Override
public int process(Buffer input, Buffer output) {
//System.err.println("ZMBVDecoder " + input.getTimeStamp());
if (input.isDiscard()) {
output.setDiscard(true);
return BUFFER_PROCESSED_OK;
}
if (input.isEOM()) {
output.setEOM(true);
output.setData(null);
return BUFFER_PROCESSED_OK;
}
output.copy(input);
output.setFormat(outputFormat);
output.setData(pixels);
output.setOffset(0);
output.setLength(pixels.length);
//if (input.)
byte[] inDat = (byte[]) input.getData();
int[] swap = prevPixels;
prevPixels = pixels;
pixels = swap;
// Detect if frames were skipped
long sequenceNumber = input.getSequenceNumber();
boolean framesWereSkipped = (sequenceNumber != previousSequenceNumber + 1);
boolean isKeyframe = state.decode(inDat, input.getOffset(), input.getLength(), pixels, prevPixels, outputFormat.getSize().width, outputFormat.getSize().height,
framesWereSkipped);
if (framesWereSkipped && !isKeyframe) {
output.setDiscard(true);
} else {
previousSequenceNumber = sequenceNumber;
}
setFlag(output, Buffer.FLAG_KEY_FRAME, isKeyframe);
return BUFFER_PROCESSED_OK;
}
示例12: printDataInfo
import javax.media.Buffer; //导入方法依赖的package包/类
void printDataInfo(Buffer buffer) {
byte[] data = (byte[])buffer.getData();
try {
out.write (data, buffer.getOffset(), buffer.getLength());
} catch (IOException e) {
BrokerFactory.getLoggingBroker().logError(e);
}
for (int i = buffer.getOffset(); i < buffer.getLength(); i++) {
int n = data[i];
if (n < 0) n+=256;
if (lastSample == -1) lastSample = n;
boolean thisMove = Math.abs(n-lastSample) > minimumSilenceThreshold;
lastSample = n;
if (inSilence && thisMove) {
if (inSilence) {
inSilence = false;
fireSilenceChange(inSilence);
}
}
if ((!inSilence) && (thisMove)) {
silenceLength = 0;
}
if ((!inSilence) && (!thisMove)) {
silenceLength ++;
if (silenceLength > minimumSilenceLength) {
inSilence = true;
fireSilenceChange(inSilence);
}
}
currentIndex++;
}
if (buffer.isEOM())
System.err.println(" Got EOM!");
}
示例13: process
import javax.media.Buffer; //导入方法依赖的package包/类
/**
* Processes the data now and make it ready for the texture.
*
* @param buffer The source for the data
* @return A control code indicating success or failure
*/
public synchronized int process(Buffer buffer)
{
if(buffer.isEOM())
return BUFFER_PROCESSED_OK;
Format inf = buffer.getFormat();
if(inf == null)
return BUFFER_PROCESSED_FAILED;
if((inf != currentFormat) || !buffer.getFormat().equals(currentFormat))
{
if(setInputFormat(inf) != null)
return BUFFER_PROCESSED_FAILED;
}
Object data = buffer.getData();
if(!(data instanceof byte[]))
return BUFFER_PROCESSED_FAILED;
// Take the pixels and write them out to individual bytes
byte[] src_pixels = (byte[])data;
int num_pixels = frameWidth * frameHeight * 3;
System.arraycopy(src_pixels, 0, inProgressFrame, 0, num_pixels);
// Swap the two buffers and set the ready flag.
byte[] tmp = processedFrame;
processedFrame = inProgressFrame;
inProgressFrame = tmp;
newFrameAvailable = true;
// Convert and write to our local image
return BUFFER_PROCESSED_OK;
}
示例14: process
import javax.media.Buffer; //导入方法依赖的package包/类
public int process(Buffer inputBuffer, Buffer outputBuffer){
// == prolog
if (isEOM(inputBuffer) ) {
propagateEOM(outputBuffer);
return BUFFER_PROCESSED_OK;
}
byte [] inBuffer = (byte[])inputBuffer.getData();
int inLength = inputBuffer.getLength();
int inOffset = inputBuffer.getOffset();
int samplesNumber = inLength;
AudioFormat af = (AudioFormat) inputBuffer.getFormat();
if (enabled) {
int shiftZero = 0;
int shiftOne = 8;
if (af.getEndian() == AudioFormat.BIG_ENDIAN) {
shiftZero = 8;
shiftOne = 0;
}
// == main
int spa = ((int) af.getSampleRate() * af.getChannels()) / nPowersPerSec;
long npa = 1000000000L / nPowersPerSec;
long timeStamp = inputBuffer.getTimeStamp(); // in nanos
float average = 0;
long cspa = 0;
for (int i = 0; i < inLength; i += 2) {
short sample = (short)
(((0xFF & inBuffer[inOffset + i]) << shiftZero) |
((0xFF & inBuffer[inOffset + i + 1]) << shiftOne));
float normal = (float) sample;
average = average + normal * normal;
cspa++;
if (cspa == spa) {
cspa = 0;
average = (float) Math.sqrt((average / spa)) / 32768;
push(timeStamp, average);
timeStamp += npa;
average = 0;
}
}
}
// == epilog
inputBuffer.setData(outputBuffer.getData());
outputBuffer.setFormat(af);
outputBuffer.setData(inBuffer);
outputBuffer.setLength(inLength);
outputBuffer.setOffset(inOffset);
outputBuffer.setTimeStamp(inputBuffer.getTimeStamp());
outputBuffer.setFlags(inputBuffer.getFlags());
return BUFFER_PROCESSED_OK;
}
示例15: read
import javax.media.Buffer; //导入方法依赖的package包/类
/**
* This is called from the Processor to read a frame worth
* of video data.
*/
public void read(Buffer buf) throws IOException {
// Check if we've finished all the frames.
if (nextImage >= images.size()) {
// We are done. Set EndOfMedia.
System.err.println("Done reading all images.");
buf.setEOM(true);
buf.setOffset(0);
buf.setLength(0);
ended = true;
return;
}
String imageFile = (String)images.elementAt(nextImage);
nextImage++;
System.err.println(" - reading image file: " + imageFile);
// Open a random access file for the next image.
RandomAccessFile raFile;
raFile = new RandomAccessFile(imageFile, "r");
byte data[] = null;
// Check the input buffer type & size.
if (buf.getData() instanceof byte[])
data = (byte[])buf.getData();
// Check to see the given buffer is big enough for the frame.
if (data == null || data.length < raFile.length()) {
data = new byte[(int)raFile.length()];
buf.setData(data);
}
// Read the entire JPEG image from the file.
raFile.readFully(data, 0, (int)raFile.length());
System.err.println(" read " + raFile.length() + " bytes.");
buf.setOffset(0);
buf.setLength((int)raFile.length());
buf.setFormat(format);
buf.setFlags(buf.getFlags() | Buffer.FLAG_KEY_FRAME);
// Close the random access file.
raFile.close();
}