📄 mediaframe.java
字号:
/**
* MediaFrame.java
*
* Created on 04. August 2003, 11:00
*
* Copyright (C) 2003 Markus Raab, Vienna University of Technology
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Contact address: raab@ims.tuwien.ac.at
*/
package org.vizir.media;
import java.awt.image.BufferedImage;
/**
* This class is represents one Frame of a MediaContent
*
* @author Markus Raab
* @version $Id: MediaFrame.java,v 1.3 2004/02/12 09:20:27 mr Exp $
*/
public class MediaFrame {
private int[] dataRGB = null;
private int width=0;
private int height=0;
/**
* Create a MediaFrame object of a BufferedImage.
* @param image
*/
public MediaFrame(BufferedImage image) {
width = image.getWidth();
height = image.getHeight();
dataRGB = image.getRGB(0,0,width,height,null,0,width);
}
/**
* Constructor with the image-data as byte array.
* @param buffer byte array of MediaFrame-data
* @param width with of the MediaFrame
* @param height height of the MediaFrame
*/
public MediaFrame(byte[] buffer, int width, int height) {
this.width = width;
this.height = height;
int length=buffer.length;
for (int i=0; i<length;i++)
this.dataRGB[i] = (int)buffer[i];
}
/**
* Constructor with the image-data as short array.
* @param buffer array of MediaFrame-data
* @param width with of the MediaFrame
* @param height height of the MediaFrame
*/
public MediaFrame(short[] buffer, int width, int height) {
this.width = width;
this.height = height;
int length=buffer.length;
for (int i=0; i<length;i++)
this.dataRGB[i] = (int)buffer[i];
}
/**
* Constructor with the image-data as int array.
* @param buffer array of MediaFrame-data
* @param width with of the MediaFrame
* @param height height of the MediaFrame
*/
public MediaFrame(int[] buffer, int width, int height) {
this.width=width;
this.height=height;
this.dataRGB=buffer;
}
/**
* Return one Pixel of the MediaFrame at the specified position.
* @param x X-position of Pixel
* @param y Y-position of Pixel
* @return Pixel at specified position
*/
public Pixel getPixelAt(int x, int y){
int data=dataRGB[y*width+x];
return Pixel.createFromInt(data,Pixel.NO_CONVERSION,0x00ff0000,0x0000ff00,0x000000ff);
}
/**
* Return one Pixel of the MediaFrame at the specified position with the specified conversion
* @param x X-position of the Pixel
* @param y Y-position of the Pixel
* @param conversion color space conversion
* @return
*/
public Pixel getPixelAt(int x, int y, int conversion){
int data=dataRGB[y*width+x];
return Pixel.createFromInt(data,conversion,0x00ff0000,0x0000ff00,0x000000ff);
}
/**
* Return one component of the specified pixel
* @param x X-position of the Pixel
* @param y Y-position of the Pixel
* @param componentMask Masking bits for component.
* @return specified component of Pixel at x,y
*/
public int getComponentAt(int x, int y, int componentMask){
int componentShift = 0;
if (componentMask != 0) while ((componentMask >> componentShift) % 2 == 0) componentShift++;
return ((dataRGB[y*width+x] & componentMask) >> componentShift);
}
/**
* Return the RGB-data of the MediaFrame as an int array. Each value represents one Pixel
* @return
*/
private int[] getDataRGB(){
return dataRGB;
}
/**
* Return the width of the MediaFrame
* @return
*/
public int getWidth(){
return this.width;
}
/**
* Return the height of the MediaFrame
* @return
*/
public int getHeight(){
return this.height;
}
/**
* return the length of the dataRGB array
* @return
*/
public int getLength(){
return dataRGB.length;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -