mediaframe.java
来自「基于MPEG 7 标准,符合未来语义网架构,很值得参考」· Java 代码 · 共 176 行
JAVA
176 行
/*
* This file is part of Caliph & Emir.
*
* Caliph & Emir 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.
*
* Caliph & Emir 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 Caliph & Emir; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright statement:
* --------------------
* (c) 2002-2005 by VizIR project.
* Please contact Horst Eidenberger (hme@ims.tuwien.ac.at)
* for more information.
*
* Mathias Lux, mathias@juggle.at, http://www.juggle.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.2 2005/05/17 22:00:47 motte 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 + =
减小字号Ctrl + -
显示快捷键?