JMF Complete VideoFormat - Java javax.media

Java examples for javax.media:Format

Description

JMF Complete VideoFormat

Demo Code

//  Copyright (c) 2010 MC Cubed, Inc. All rights reserved.
import java.awt.Dimension;
import java.util.Collection;
import java.util.LinkedList;
import javax.media.Format;
import javax.media.format.VideoFormat;
import javax.media.format.IndexedColorFormat;
import javax.media.format.*;
import javax.media.protocol.ContentDescriptor;
import java.util.Map.Entry;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.LinkedList;

public class Main{
    public static VideoFormat CompleteFormat(VideoFormat videoFormat,
            Dimension size, float frameRate) {
        VideoFormat format;/*from  ww w  .  j a v a2 s . com*/
        int lineSize, dataSize, pixelStride;

        if (videoFormat instanceof RGBFormat) {
            RGBFormat baseFormat = (RGBFormat) videoFormat;
            pixelStride = baseFormat.getPixelStride();
            lineSize = (size != null) ? (int) size.getWidth() * pixelStride
                    : Format.NOT_SPECIFIED;
            dataSize = (size != null) ? lineSize * (int) size.getHeight()
                    : Format.NOT_SPECIFIED;
            format = new RGBFormat(size, dataSize,
                    baseFormat.getDataType(), frameRate,
                    baseFormat.getBitsPerPixel(), baseFormat.getRedMask(),
                    baseFormat.getGreenMask(), baseFormat.getBlueMask(),
                    baseFormat.getPixelStride(), lineSize,
                    baseFormat.getFlipped(), baseFormat.getEndian());
        } else if (videoFormat instanceof YUVFormat) {
            YUVFormat baseFormat = (YUVFormat) videoFormat;
            dataSize = (size != null) ? (int) size.getWidth()
                    * (int) size.getHeight() : Format.NOT_SPECIFIED;
            format = new YUVFormat(size, dataSize,
                    baseFormat.getDataType(), frameRate,
                    baseFormat.getYuvType(), (int) size.getWidth(), 1,
                    baseFormat.getOffsetY(), baseFormat.getOffsetU(),
                    baseFormat.getOffsetV());
        } else if (videoFormat instanceof IndexedColorFormat) {
            IndexedColorFormat baseFormat = (IndexedColorFormat) videoFormat;
            int bpp = baseFormat.getMapSize();
            lineSize = (size != null) ? (int) size.getWidth() * bpp / 8
                    : Format.NOT_SPECIFIED;
            dataSize = (size != null) ? (int) size.getHeight() * lineSize
                    : Format.NOT_SPECIFIED;
            format = new IndexedColorFormat(size, dataSize,
                    baseFormat.getDataType(), frameRate, lineSize,
                    baseFormat.getMapSize(), baseFormat.getRedValues(),
                    baseFormat.getGreenValues(), baseFormat.getBlueValues());
        } else {
            format = null;
        }
        return format;
    }
}

Related Tutorials