FileDocCategorySizeDatePackage
RGBScaler.javaAPI DocJMF 2.1.1e6000Mon May 12 12:20:46 BST 2003com.sun.media.codec.video.colorspace

RGBScaler

public class RGBScaler extends BasicCodec
This the pure java RGB scaler. It works on 24-bit RGB data. It has two quality settings 0.5 or less implies nearest neighbour. more the 0.5 implies bilinear. NOTE: bilinear not yet implemented

Fields Summary
protected float
quality
private int
nativeData
private static boolean
nativeAvailable
Constructors Summary
public RGBScaler()

 

     
	try {
	    JMFSecurityManager.loadLibrary("jmutil");
	} catch (Throwable t) {
	}
    
	this(null);
    
public RGBScaler(Dimension sizeOut)

	inputFormats = new Format[] {
	    new RGBFormat(null,
			  Format.NOT_SPECIFIED,
			  Format.byteArray,
			  Format.NOT_SPECIFIED,
			  24,
			  3, 2, 1,
			  3, Format.NOT_SPECIFIED,
			  Format.FALSE,
			  Format.NOT_SPECIFIED)
	};
	
	if (sizeOut != null)
	    setOutputSize(sizeOut);
    
Methods Summary
public voidclose()

	super.close();
	if (nativeAvailable && nativeData != 0) {
	    try {
		nativeClose();
	    } catch (Throwable t) {
	    }
	}
    
public java.lang.StringgetName()

	return "RGB Scaler";
    
public javax.media.Format[]getSupportedOutputFormats(javax.media.Format input)

	if (input == null) {
	    return outputFormats;
	}
	
	if (matches(input, inputFormats) != null) {
	    // Need to use the incoming frame rate for the output
	    float frameRate = ((VideoFormat)input).getFrameRate();
	    VideoFormat frameRateFormat = new VideoFormat(null,
							  null,
							  Format.NOT_SPECIFIED,
							  null,
							  frameRate);
	    
	    return new Format[] { outputFormats[0].intersects(frameRateFormat) };
	} else {
	    return new Format[0];
	}
    
private native voidnativeClose()

private native voidnativeScale(java.lang.Object inData, long inBytes, java.lang.Object outData, long outBytes, int psIn, int lsIn, int wIn, int hIn, int psOut, int lsOut, int wOut, int hOut)

protected voidnearestNeighbour(javax.media.Buffer inBuffer, javax.media.Buffer outBuffer)

	RGBFormat vfIn = (RGBFormat) inBuffer.getFormat();
	Dimension sizeIn = vfIn.getSize();
	RGBFormat vfOut = (RGBFormat) outBuffer.getFormat();
	Dimension sizeOut = vfOut.getSize();
	int pixStrideIn = vfIn.getPixelStride();
	int pixStrideOut = vfOut.getPixelStride();
	int lineStrideIn = vfIn.getLineStride();
	int lineStrideOut = vfOut.getLineStride();
	float horRatio = (float) sizeIn.width / sizeOut.width;
	float verRatio = (float) sizeIn.height / sizeOut.height;
	Object inObj;
	Object outObj;
	long inBytes = 0;
	long outBytes = 0;

	if (nativeAvailable) {
	    inObj = getInputData(inBuffer);
	    outObj = validateData(outBuffer, 0, true);
	    inBytes = getNativeData(inObj);
	    outBytes = getNativeData(outObj);
	} else {
	    inObj = inBuffer.getData();
	    outObj = outBuffer.getData();
	}

	// Try it the first time assuming native is available
	// If not, set nativeAvailable to false and use the
	// java version
	if (nativeAvailable) {
	    try {
		nativeScale(inObj, inBytes, outObj, outBytes,
			    pixStrideIn, lineStrideIn,
			    sizeIn.width, sizeIn.height,
			    pixStrideOut, lineStrideOut,
			    sizeOut.width, sizeOut.height);
	    } catch (Throwable t) {
		nativeAvailable = false;
	    }
	}
	
	if (!nativeAvailable) {
	    byte [] inData = (byte[]) inObj;
	    byte [] outData = (byte[]) outObj;
	    for (int y = 0; y < sizeOut.height; y++) {
		int ptrOut = y * lineStrideOut;
		int ptrIn = (int) (y * verRatio) * lineStrideIn;
		for (int x = 0; x < sizeOut.width; x++) {
		    int ptrIn2 = ptrIn + (int) (x * horRatio) * pixStrideIn;
		    outData[ptrOut] = inData[ptrIn2];
		    outData[ptrOut + 1] = inData[ptrIn2 + 1];
		    outData[ptrOut + 2] = inData[ptrIn2 + 2];
		    ptrOut += pixStrideOut;
		}
	    }
	}
    
public intprocess(javax.media.Buffer inBuffer, javax.media.Buffer outBuffer)

	//System.err.println("Input = " + inputFormat + "\nOutput = " + outputFormat);
	int outputDataLength = ((VideoFormat)outputFormat).getMaxDataLength();

	outBuffer.setLength(outputDataLength);
	outBuffer.setFormat(outputFormat);

	if (quality <= 0.5f) {
	    nearestNeighbour(inBuffer, outBuffer);
	}
	
	//outBuffer.setDiscard(true);
	return BUFFER_PROCESSED_OK;

    
public javax.media.FormatsetInputFormat(javax.media.Format input)

	if (matches(input, inputFormats) == null)
	    return null;
	else
	    return input;
    
public javax.media.FormatsetOutputFormat(javax.media.Format output)

	if (output == null || matches(output, outputFormats) == null)
	    return null;
	RGBFormat incoming = (RGBFormat) output;
	
	Dimension size = incoming.getSize();
	int maxDataLength = incoming.getMaxDataLength();
	int lineStride = incoming.getLineStride();
	float frameRate = incoming.getFrameRate();
	int flipped = incoming.getFlipped();
	int endian = incoming.getEndian();

	if (size == null)
	    return null;
	if (maxDataLength < size.width * size.height * 3)
	    maxDataLength = size.width * size.height * 3;
	if (lineStride < size.width * 3)
	    lineStride = size.width * 3;
	if (flipped != Format.FALSE)
	    flipped = Format.FALSE;
	
	outputFormat = outputFormats[0].intersects(new RGBFormat(size,
						        maxDataLength,
							null,
							frameRate,
							Format.NOT_SPECIFIED,
							Format.NOT_SPECIFIED,
							Format.NOT_SPECIFIED,
							Format.NOT_SPECIFIED,
							Format.NOT_SPECIFIED,
							lineStride,
							Format.NOT_SPECIFIED,
							Format.NOT_SPECIFIED));
	return outputFormat;
    
public voidsetOutputSize(java.awt.Dimension sizeOut)

	outputFormats = new Format[] {
	    new RGBFormat(sizeOut,
			  sizeOut.width * sizeOut.height * 3,
			  Format.byteArray,
			  Format.NOT_SPECIFIED,
			  24,
			  3, 2, 1,
			  3, sizeOut.width * 3,
			  Format.FALSE,
			  Format.NOT_SPECIFIED)
	};