public static Picture createPictureHiBD(int width, int height, byte[][] data, byte[][] lowBits, ColorSpace color, int lowBitsNum) { return new Picture(width, height, data, lowBits, color, lowBitsNum, new Rect(0, 0, width, height)); }
public static PictureHiBD createPictureWithDepth(int width, int height, int[][] data, ColorSpace color, int bitDepth) { return new PictureHiBD(width, height, data, color, bitDepth, new Rect(0, 0, width, height)); }
public static Picture createPicture(int width, int height, byte[][] data, ColorSpace color) { return new Picture(width, height, data, null, color, 0, new Rect(0, 0, width, height)); }
public static PictureHiBD createPicture(int width, int height, int[][] data, ColorSpace color) { return new PictureHiBD(width, height, data, color, 8, new Rect(0, 0, width, height)); }
public static Frame createFrame(SeqParameterSet sps, byte[][] buffer, int frameNum, SliceType frameType, MvList2D mvs, Frame[][][] refsUsed, int POC) { int width = sps.picWidthInMbsMinus1 + 1 << 4; int height = SeqParameterSet.getPicHeightInMbs(sps) << 4; Rect crop = null; if (sps.frameCroppingFlag) { int sX = sps.frameCropLeftOffset << 1; int sY = sps.frameCropTopOffset << 1; int w = width - (sps.frameCropRightOffset << 1) - sX; int h = height - (sps.frameCropBottomOffset << 1) - sY; crop = new Rect(sX, sY, w, h); } return new Frame(width, height, buffer, ColorSpace.YUV420, crop, frameNum, frameType, mvs, refsUsed, POC); }
@Override public Picture decodeField(ByteBuffer data, byte[][] data2, int field, int step) { Picture res = super.decodeField(data, data2, field, step); return new Picture(res.getWidth() >> 2, res.getHeight() >> 2, res.getData(), null, res.getColor(), 0, new Rect( 0, 0, res.getCroppedWidth() >> 2, res.getCroppedHeight() >> 2)); } }
@Override public Picture decodeField(ByteBuffer data, byte[][] data2, int field, int step) { Picture res = super.decodeField(data, data2, field, step); return new Picture(res.getWidth() >> 1, res.getHeight() >> 1, res.getData(), null, res.getColor(), 0, new Rect( 0, 0, res.getCroppedWidth() >> 1, res.getCroppedHeight() >> 1)); } }
private Picture decodeScan(ByteBuffer data, FrameHeader header, ScanHeader scan, VLC[] huffTables, int[][] quant, byte[][] data2, int field, int step) { int blockW = header.getHmax(); int blockH = header.getVmax(); int mcuW = blockW << 3; int mcuH = blockH << 3; int width = header.width; int height = header.height; int xBlocks = (width + mcuW - 1) >> (blockW + 2); int yBlocks = (height + mcuH - 1) >> (blockH + 2); int nn = blockW + blockH; Picture result = new Picture(xBlocks << (blockW + 2), yBlocks << (blockH + 2), data2, null, nn == 4 ? ColorSpace.YUV420J : (nn == 3 ? ColorSpace.YUV422J : ColorSpace.YUV444J), 0, new Rect(0, 0, width, height)); BitReader bits = BitReader.createBitReader(data); int[] dcPredictor = new int[] { 1024, 1024, 1024 }; for (int by = 0; by < yBlocks; by++) for (int bx = 0; bx < xBlocks && bits.moreData(); bx++) decodeMCU(bits, dcPredictor, quant, huffTables, result, bx, by, blockW, blockH, field, step); return result; }
public Picture decodeFrameHiBD(ByteBuffer data, byte[][] target, byte[][] lowBits) { FrameHeader fh = readFrameHeader(data); int codedWidth = (fh.width + 15) & ~0xf; int codedHeight = (fh.height + 15) & ~0xf; int lumaSize = codedWidth * codedHeight; int chromaSize = lumaSize >> (3 - fh.chromaType); if (target == null || target[0].length < lumaSize || target[1].length < chromaSize || target[2].length < chromaSize) { throw new RuntimeException("Provided output picture won't fit into provided buffer"); } if (fh.frameType == 0) { decodePicture(data, target, lowBits, codedWidth, codedHeight, codedWidth >> 4, fh.qMatLuma, fh.qMatChroma, fh.scan, 0, fh.chromaType); } else { decodePicture(data, target, lowBits, codedWidth, codedHeight >> 1, codedWidth >> 4, fh.qMatLuma, fh.qMatChroma, fh.scan, fh.topFieldFirst ? 1 : 2, fh.chromaType); decodePicture(data, target, lowBits, codedWidth, codedHeight >> 1, codedWidth >> 4, fh.qMatLuma, fh.qMatChroma, fh.scan, fh.topFieldFirst ? 2 : 1, fh.chromaType); } ColorSpace color = fh.chromaType == 2 ? ColorSpace.YUV422 : ColorSpace.YUV444; return new Picture(codedWidth, codedHeight, target, lowBits, color, lowBits == null ? 0 : 2, new Rect(0, 0, fh.width & color.getWidthMask(), fh.height & color.getHeightMask())); }
@Override public Picture decodeFrameHiBD(ByteBuffer data, byte[][] target, byte[][] lowBits) { FrameHeader fh = readFrameHeader(data); int codedWidth = ((fh.width + 15) & ~0xf) >> 1; int codedHeight = ((fh.height + 15) & ~0xf) >> 1; int lumaSize = codedWidth * codedHeight; int chromaSize = lumaSize >> 1; if (target == null || target[0].length < lumaSize || target[1].length < chromaSize || target[2].length < chromaSize) { throw new RuntimeException("Provided output picture won't fit into provided buffer"); } if (fh.frameType == 0) { decodePicture(data, target, lowBits, codedWidth, codedHeight, codedWidth >> 3, fh.qMatLuma, fh.qMatChroma, progressive_scan_4x4, 0, fh.chromaType); } else { decodePicture(data, target, lowBits, codedWidth, codedHeight >> 1, codedWidth >> 3, fh.qMatLuma, fh.qMatChroma, interlaced_scan_4x4, fh.topFieldFirst ? 1 : 2, fh.chromaType); decodePicture(data, target, lowBits, codedWidth, codedHeight >> 1, codedWidth >> 3, fh.qMatLuma, fh.qMatChroma, interlaced_scan_4x4, fh.topFieldFirst ? 2 : 1, fh.chromaType); } ColorSpace color = fh.chromaType == 2 ? ColorSpace.YUV422 : ColorSpace.YUV444; return new Picture(codedWidth, codedHeight, target, lowBits, color, lowBits == null ? 0 : 2, new Rect(0, 0, (fh.width >> 1) & color.getWidthMask(), (fh.height >> 1) & color.getHeightMask())); }
@Override public Picture decodeFrameHiBD(ByteBuffer data, byte[][] target, byte[][] lowBits) { FrameHeader fh = readFrameHeader(data); int codedWidth = ((fh.width + 15) & ~0xf) >> 2; int codedHeight = ((fh.height + 15) & ~0xf) >> 2; int lumaSize = codedWidth * codedHeight; int chromaSize = lumaSize >> 1; if (target == null || target[0].length < lumaSize || target[1].length < chromaSize || target[2].length < chromaSize) { throw new RuntimeException("Provided output picture won't fit into provided buffer"); } if (fh.frameType == 0) { decodePicture(data, target, lowBits, codedWidth, codedHeight, codedWidth >> 2, fh.qMatLuma, fh.qMatChroma, new int[] { 0, 1, 2, 3 }, 0, fh.chromaType); } else { decodePicture(data, target, lowBits, codedWidth, codedHeight >> 1, codedWidth >> 2, fh.qMatLuma, fh.qMatChroma, new int[] { 0, 2, 1, 3 }, fh.topFieldFirst ? 1 : 2, fh.chromaType); decodePicture(data, target, lowBits, codedWidth, codedHeight >> 1, codedWidth >> 2, fh.qMatLuma, fh.qMatChroma, new int[] { 0, 2, 1, 3 }, fh.topFieldFirst ? 2 : 1, fh.chromaType); } ColorSpace color = fh.chromaType == 2 ? ColorSpace.YUV422 : ColorSpace.YUV444; return new Picture(codedWidth, codedHeight, target, lowBits, color, lowBits == null ? 0 : 2, new Rect(0, 0, (fh.width >> 2) & color.getWidthMask(), (fh.height >> 2) & color.getHeightMask())); }
public Picture decodeFrameHiBD(ByteBuffer data, byte[][] target, byte[][] lowBits) { FrameHeader fh = readFrameHeader(data); int codedWidth = ((fh.width + 15) & ~0xf) >> 3; int codedHeight = ((fh.height + 15) & ~0xf) >> 3; int lumaSize = codedWidth * codedHeight; int chromaSize = lumaSize >> 1; if (target == null || target[0].length < lumaSize || target[1].length < chromaSize || target[2].length < chromaSize) { throw new RuntimeException("Provided output picture won't fit into provided buffer"); } if (fh.frameType == 0) { decodePicture(data, target, lowBits, codedWidth, codedHeight, codedWidth >> 1, fh.qMatLuma, fh.qMatChroma, new int[] { 0 }, 0, fh.chromaType); } else { decodePicture(data, target, lowBits, codedWidth, codedHeight >> 1, codedWidth >> 1, fh.qMatLuma, fh.qMatChroma, new int[] { 0 }, fh.topFieldFirst ? 1 : 2, fh.chromaType); decodePicture(data, target, lowBits, codedWidth, codedHeight >> 1, codedWidth >> 1, fh.qMatLuma, fh.qMatChroma, new int[] { 0 }, fh.topFieldFirst ? 2 : 1, fh.chromaType); } ColorSpace color = fh.chromaType == 2 ? ColorSpace.YUV422 : ColorSpace.YUV444; return new Picture(codedWidth, codedHeight, target, lowBits, color, lowBits == null ? 0 : 2, new Rect(0, 0, (fh.width >> 3) & color.getWidthMask(), (fh.height >> 3) & color.getHeightMask())); }
private Picture decodeIFrame(BitReader br, MPEG4DecodingContext ctx, byte[][] buffer) { Picture p = new Picture(ctx.mbWidth << 4, ctx.mbHeight << 4, buffer, null, ColorSpace.YUV420, 0, new Rect(0, 0, ctx.width, ctx.height)); int bound = 0;
@Override public Picture decodeFrame(ByteBuffer buffer, byte[][] buf) { PictureHeader ph = readHeader(buffer); if (refFrames[0] == null && ph.picture_coding_type > 1 || refFrames[1] == null && ph.picture_coding_type > 2) { throw new RuntimeException( "Not enough references to decode " + (ph.picture_coding_type == 1 ? "P" : "B") + " frame"); } Context context = initContext(sh, ph); Picture pic = new Picture(context.codedWidth, context.codedHeight, buf, null, context.color, 0, new Rect(0, 0, context.picWidth, context.picHeight)); if (ph.pictureCodingExtension != null && ph.pictureCodingExtension.picture_structure != Frame) { decodePicture(context, ph, buffer, buf, ph.pictureCodingExtension.picture_structure - 1, 1); ph = readHeader(buffer); context = initContext(sh, ph); decodePicture(context, ph, buffer, buf, ph.pictureCodingExtension.picture_structure - 1, 1); } else { decodePicture(context, ph, buffer, buf, 0, 0); } if (ph.picture_coding_type == MPEGConst.IntraCoded || ph.picture_coding_type == MPEGConst.PredictiveCoded) { Picture unused = refFrames[1]; refFrames[1] = refFrames[0]; refFrames[0] = copyAndCreateIfNeeded(pic, unused); } return pic; }
private Picture splitSlice(Picture result, int mbX, int mbY, int sliceMbCount, boolean unsafe, int vStep, int vOffset) { Picture out = Picture.createCroppedHiBD(sliceMbCount << 4, 16, result.getLowBitsNum(), YUV422, null); if (unsafe) { int mbHeightPix = 16 << vStep; Picture filled = Picture.create(sliceMbCount << 4, mbHeightPix, YUV422); ImageOP.subImageWithFillPic8(result, filled, new Rect(mbX << 4, mbY << (4 + vStep), sliceMbCount << 4, mbHeightPix)); split(filled, out, 0, 0, sliceMbCount, vStep, vOffset); } else { split(result, out, mbX, mbY, sliceMbCount, vStep, vOffset); } return out; }
new Rect(0, 0, ctx.width, ctx.height));
new Rect(0, 0, ctx.width, ctx.height));