FileDocCategorySizeDatePackage
RGBFormat.javaAPI DocJMF 2.1.1e13842Mon May 12 12:20:34 BST 2003javax.media.format

RGBFormat

public class RGBFormat extends VideoFormat
Describes uncompressed RGB data. The data is in interleaved form. RGB components can be packed into a short or an int. If the pixel components are packed, then the redMask, greenMask and blueMask fields specify the bit masks, otherwise they specify the order of arrangement of the components. For example:
  • 32-bit packed RGB stored as 32-bit integers would have the following masks: redMask = 0x00FF0000, greenMask = 0x0000FF00, blueMask = 0x000000FF.
  • 24-bit RGB stored as bytes would have the following masks: redMask = 1, greenMask = 2, blueMask = 3 and pixelStride = 3.
since
JMF 2.0

Fields Summary
protected int
redMask
Mask value for the Red component.
protected int
greenMask
Mask value for the Green component.
protected int
blueMask
Mask value for the Blue component.
protected int
bitsPerPixel
The number of bits required to represent a pixel, including all three color components.
protected int
pixelStride
Increment value of the array index from one pixel to the next.
protected int
lineStride
Increment value of the array index from the first pixel on line n to the first pixel on line n+1.
protected int
flipped
Indicates whether or not the lines in the video frame are flipped vertically (upside down).
protected int
endian
Endian ordering of the data where applicable
public static final int
BIG_ENDIAN
public static final int
LITTLE_ENDIAN
private static String
ENCODING
Constructors Summary
public RGBFormat()
Constructs a default RGBFormat.


              
      
	super(ENCODING);
	dataType = null;
    
public RGBFormat(Dimension size, int maxDataLength, Class dataType, float frameRate, int bitsPerPixel, int red, int green, int blue)
Constructs an RGBFormat object with the specified properties. The pixel stride is initialized to the default for the specified data type and bits per pixel. The line stride is initialized using the default pixel stride and specified frame width. The image is not flipped and the endian is LITTLE_ENDIAN.

param
size A Dimension that specifies the frame size.
param
maxDataLength The maximum length of a data chunk.
param
dataType The type of the data. For example, byte array.
param
frameRate The frame rate.
param
bitsPerPixel The number of bits representing a pixel.
param
red The mask for the red color component.
param
green The mask for the green color component.
param
blue The mask for the blue color component.

	super(ENCODING, size, maxDataLength, dataType, frameRate);
	this.bitsPerPixel = bitsPerPixel;
	this.redMask = red;
	this.greenMask = green;
	this.blueMask = blue;
	if (bitsPerPixel != NOT_SPECIFIED && dataType != null) {
	    pixelStride = bitsPerPixel / 8;
	    if (dataType != byteArray)
		pixelStride = 1;
	} else {
	    pixelStride = NOT_SPECIFIED;
	}
	if (size != null && pixelStride != NOT_SPECIFIED)
	    lineStride = pixelStride * size.width;
	else
	    lineStride = NOT_SPECIFIED;
	flipped = FALSE;
	if (bitsPerPixel == 16 && dataType == byteArray)
	    endian = LITTLE_ENDIAN;
	else
	    endian = NOT_SPECIFIED;
    
public RGBFormat(Dimension size, int maxDataLength, Class dataType, float frameRate, int bitsPerPixel, int red, int green, int blue, int pixelStride, int lineStride, int flipped, int endian)
Constructs an RGBFormat object with the specified properties.

param
size A Dimension that specifies the frame size.
param
maxDataLength The maximum length of a data chunk.
param
dataType The type of the data. For example, byte array.
param
frameRate The frame rate.
param
bitsPerPixel The number of bits representing a pixel.
param
red The mask for the red color component.
param
green The mask for the green color component.
param
blue The mask for the blue color component.
param
pixelStride The number of array elements between adjacent pixels.
param
flipped Indicates whether or not the lines in the video frame are flipped vertically (upside down). Format.TRUE indicates the image is flipped, Format.FALSE indicates that it is not.
param
endian The byte ordering used for this RGBFormat--BIG_ENDIAN or LITTLE_ENDIAN.

	super(ENCODING, size, maxDataLength, dataType, frameRate);
	this.bitsPerPixel = bitsPerPixel;
	this.redMask = red;
	this.greenMask = green;
	this.blueMask = blue;
	this.pixelStride = pixelStride;
	this.lineStride = lineStride;
	this.flipped = flipped;
	this.endian = endian;
    
Methods Summary
public java.lang.Objectclone()
Creates a clone of this RGBFormat.

return
A clone of this RGBFormat.

	RGBFormat f = new RGBFormat(size,
				    maxDataLength,
				    dataType,
				    frameRate,
				    bitsPerPixel,
				    redMask,
				    greenMask,
				    blueMask,
				    pixelStride,
				    lineStride,
				    flipped,
				    endian);
	f.copy(this);
	return f;
    
protected voidcopy(javax.media.Format f)
Copies the attributes from the specified Format into this RGBFormat.

param
f The Format to copy the attributes from.

	super.copy(f);
	if (f instanceof RGBFormat) {
	    RGBFormat other = (RGBFormat) f;
	    bitsPerPixel = other.bitsPerPixel;
	    redMask = other.redMask;
	    greenMask = other.greenMask;
	    blueMask = other.blueMask;
	    pixelStride = other.pixelStride;
	    lineStride = other.lineStride;
	    flipped = other.flipped;
	    endian = other.endian;
	}
    
public booleanequals(java.lang.Object format)
Compares the specified Format with this RGBFormat. Returns true only if the specified Format is a RGBFormat object and all of its attributes are identical to the attributes in this RGBFormat.

param
format The Format to compare.
return
true if the specified Format is the same as this one.

	if (format instanceof RGBFormat) {
	    RGBFormat other = (RGBFormat) format;
	    
	    return super.equals(format) &&
		bitsPerPixel == other.bitsPerPixel &&
		redMask == other.redMask &&
		greenMask == other.greenMask &&
		blueMask == other.blueMask &&
		pixelStride == other.pixelStride &&
		lineStride == other.lineStride &&
		endian == other.endian &&
		flipped == other.flipped;
	} else
	    return false;
    
public intgetBitsPerPixel()
Gets the number of bits required per pixel of data.

return
An integer representing the number of bits per pixel.

	return bitsPerPixel;
    
public intgetBlueMask()
Gets the mask for the blue component.

return
The blue mask.

	return blueMask;
    
public intgetEndian()
Gets the endian ordering of the data for unpacked 16-bit data.

return
An integer representing the endian ordering: BIG_ENDIAN, LITTLE_ENDIAN or NOT_SPECIFIED

	return endian;
    
public intgetFlipped()
Checks whether or not the video image is vertically flipped.

return
Format.TRUE if the video is flipped, Format.FALSE if it is not.

	return flipped;
    
public intgetGreenMask()
Gets the mask for the green component.

return
The green mask.

	return greenMask;
    
public intgetLineStride()
Gets the line stride--the number of array elements between adjacent rows of pixels.

return
An integer representing the line stride.

	return lineStride;
    
public intgetPixelStride()
Gets the pixel stride--the number of array elements between adjacent pixels.

return
An integer representing the pixel stride.

	return pixelStride;
    
public intgetRedMask()
Gets the mask for the red component.

return
The red mask.

	return redMask;
    
public javax.media.Formatintersects(javax.media.Format format)
Finds the attributes shared by two matching Format objects. If the specified Format does not match this one, the result is undefined.

param
The matching Format to intersect with this RGBFormat.
return
A Format object with its attributes set to those attributes common to both Format objects.
see
#matches

	Format fmt;
	if ((fmt = super.intersects(format)) == null)
	    return null;
	if (!(format instanceof RGBFormat))
	    return fmt;
	RGBFormat other = (RGBFormat)format;
	RGBFormat res = (RGBFormat)fmt;
	res.bitsPerPixel = (bitsPerPixel != NOT_SPECIFIED ?
			    bitsPerPixel : other.bitsPerPixel);
	res.pixelStride = (pixelStride != NOT_SPECIFIED ?
			   pixelStride : other.pixelStride);
	res.lineStride = (lineStride != NOT_SPECIFIED ?
			  lineStride : other.lineStride);
	res.redMask = (redMask != NOT_SPECIFIED ?
		       redMask : other.redMask);
	res.greenMask = (greenMask != NOT_SPECIFIED ?
			 greenMask : other.greenMask);
	res.blueMask = (blueMask != NOT_SPECIFIED ?
			blueMask : other.blueMask);
	res.flipped = (flipped != NOT_SPECIFIED ?
		       flipped : other.flipped);
	res.endian = (endian != NOT_SPECIFIED ?
		       endian : other.endian);
	
	return res;
    
public booleanmatches(javax.media.Format format)
Checks whether or not the specified Format matches this RGBFormat. Matches only compares the attributes that are defined in the specified Format, unspecified attributes are ignored.

The two Format objects do not have to be of the same class to match. For example, if "A" are "B" are being compared, a match is possible if "A" is derived from "B" or "B" is derived from "A". (The compared attributes must still match, or matches fails.)

param
format The Format to compare with this one.
return
true if the specified Format matches this one, false if it does not.

	if (!super.matches(format))
	    return false;
	if (!(format instanceof RGBFormat))
	    return true;

	RGBFormat other = (RGBFormat) format;

	boolean returnVal = 
	    (bitsPerPixel == NOT_SPECIFIED || other.bitsPerPixel == NOT_SPECIFIED ||
	     bitsPerPixel == other.bitsPerPixel) &&
	    
	    (redMask == NOT_SPECIFIED || other.redMask == NOT_SPECIFIED ||
	     redMask == other.redMask) &&
	    (greenMask == NOT_SPECIFIED || other.greenMask == NOT_SPECIFIED ||
	     greenMask == other.greenMask) &&
	    (blueMask == NOT_SPECIFIED || other.blueMask == NOT_SPECIFIED ||
	     blueMask == other.blueMask) &&
	    
	    (pixelStride == NOT_SPECIFIED || other.pixelStride == NOT_SPECIFIED ||
	     pixelStride == other.pixelStride) &&
	    
	    (endian == NOT_SPECIFIED || other.endian == NOT_SPECIFIED ||
	     endian == other.endian) &&

	    (flipped == NOT_SPECIFIED || other.flipped == NOT_SPECIFIED ||
	     flipped == other.flipped);

	return returnVal;
    
public javax.media.Formatrelax()
Generate a format that's less restrictive than this format but contains the basic attributes that will make this resulting format useful for format matching.

return
A Format that's less restrictive than the this format.

	RGBFormat fmt;
	if ((fmt = (RGBFormat)super.relax()) == null)
	    return null;

	fmt.lineStride = NOT_SPECIFIED;
	fmt.pixelStride = NOT_SPECIFIED;

	return fmt;
    
public java.lang.StringtoString()
Gets a String representation of the attributes of this RGBFormat. For example: "RGB, 352x240, ...".

return
A String that describes the format attributes.

	String s = getEncoding().toUpperCase();
	if (size != null)
	    s += ", " + size.width + "x" + size.height;
	if (frameRate != NOT_SPECIFIED)
	    s += ", FrameRate=" + ((int)(frameRate * 10) / 10f);
	if (maxDataLength != NOT_SPECIFIED)
	    s += ", Length=" + maxDataLength;
	s += ", " + bitsPerPixel + "-bit";
	s += ", Masks=" + redMask + ":" + greenMask + ":" + blueMask;
	if (pixelStride != 1)
	    s += ", PixelStride=" + pixelStride;
	s += ", LineStride=" + lineStride;
	if (flipped != NOT_SPECIFIED)
	    s += (flipped == Format.TRUE? ", Flipped" : "");
	if (dataType == byteArray && bitsPerPixel == 16 && endian != NOT_SPECIFIED)
	    s += (endian == BIG_ENDIAN? ", BigEndian" : ", LittleEndian");
	if (dataType != null && dataType != Format.byteArray)
	    s += ", " + dataType;
	return s;