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 Picture(int width, int height, byte[][] data, byte[][] lowBits, ColorSpace color, int lowBitsNum, Rect crop) { this.width = width; this.height = height; this.data = data; this.lowBits = lowBits; this.color = color; this.lowBitsNum = lowBitsNum; this.crop = crop; if (color != null) { for (int i = 0; i < color.nComp; i++) { int mask = 0xff >> (8 - color.compWidth[i]); if ((width & mask) != 0) throw new IllegalArgumentException("Component " + i + " width should be a multiple of " + (1 << color.compWidth[i]) + " for colorspace: " + color); if (crop != null && (crop.getWidth() & mask) != 0) throw new IllegalArgumentException("Component " + i + " cropped width should be a multiple of " + (1 << color.compWidth[i]) + " for colorspace: " + color); mask = 0xff >> (8 - color.compHeight[i]); if ((height & mask) != 0) throw new IllegalArgumentException("Component " + i + " height should be a multiple of " + (1 << color.compHeight[i]) + " for colorspace: " + color); if (crop != null && (crop.getHeight() & mask) != 0) throw new IllegalArgumentException("Component " + i + " cropped height should be a multiple of " + (1 << color.compHeight[i]) + " for colorspace: " + color); } } }
private boolean planeEquals(Picture other, int plane) { int cw = color.compWidth[plane]; int ch = color.compHeight[plane]; int offA = other.getCrop() == null ? 0 : ((other.getCrop().getX() >> cw) + (other.getCrop().getY() >> ch) * (other.getWidth() >> cw)); int offB = crop == null ? 0 : ((crop.getX() >> cw) + (crop.getY() >> ch) * (width >> cw)); byte[] planeData = other.getPlaneData(plane); for (int i = 0; i < getCroppedHeight() >> ch; i++, offA += (other.getWidth() >> cw), offB += (width >> cw)) { for (int j = 0; j < getCroppedWidth() >> cw; j++) { if (planeData[offA + j] != data[plane][offB + j]) return false; } } return true; }
public int getCroppedHeight() { return crop == null ? height : crop.getHeight(); }
public int getCroppedWidth() { return crop == null ? width : crop.getWidth(); }
public int getStartX() { return crop == null ? 0 : crop.getX(); }
public int getStartY() { return crop == null ? 0 : crop.getY(); }
private boolean planeEquals(PictureHiBD other, int plane) { int cw = color.compWidth[plane]; int ch = color.compHeight[plane]; int offA = other.getCrop() == null ? 0 : ((other.getCrop().getX() >> cw) + (other.getCrop().getY() >> ch) * (other.getWidth() >> cw)); int offB = crop == null ? 0 : ((crop.getX() >> cw) + (crop.getY() >> ch) * (width >> cw)); int[] planeData = other.getPlaneData(plane); for (int i = 0; i < getCroppedHeight() >> ch; i++, offA += (other.getWidth() >> cw), offB += (width >> cw)) { for (int j = 0; j < getCroppedWidth() >> cw; j++) { if (planeData[offA + j] != data[plane][offB + j]) return false; } } return true; } }
public int getCroppedHeight() { return crop == null ? height : crop.getHeight(); }
public int getCroppedWidth() { return crop == null ? width : crop.getWidth(); }
public PictureHiBD cropped() { if (crop == null || (crop.getX() == 0 && crop.getY() == 0 && crop.getWidth() == width && crop.getHeight() == height)) return this; PictureHiBD result = PictureHiBD.create(crop.getWidth(), crop.getHeight(), color); for (int plane = 0; plane < color.nComp; plane++) { if (data[plane] == null) continue; cropSub(data[plane], crop.getX() >> color.compWidth[plane], crop.getY() >> color.compHeight[plane], crop.getWidth() >> color.compWidth[plane], crop.getHeight() >> color.compHeight[plane], width >> color.compWidth[plane], result.data[plane]); } return result; }
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 Picture cropped() { if (!cropNeeded()) return this; Picture result = Picture.create(crop.getWidth(), crop.getHeight(), color); if(color.planar) { for (int plane = 0; plane < data.length; plane++) { if (data[plane] == null) continue; cropSub(data[plane], crop.getX() >> color.compWidth[plane], crop.getY() >> color.compHeight[plane], crop.getWidth() >> color.compWidth[plane], crop.getHeight() >> color.compHeight[plane], width >> color.compWidth[plane], crop.getWidth() >> color.compWidth[plane], result.data[plane]); } } else { cropSub(data[0], crop.getX(), crop.getY(), crop.getWidth(), crop.getHeight(), width * color.nComp, crop.getWidth() * color.nComp, result.data[0]); } return result; }
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 void subImageWithFillPic8(Picture _in, Picture out, Rect rect) { int width = _in.getWidth(); int height = _in.getHeight(); ColorSpace color = _in.getColor(); byte[][] data = _in.getData(); for (int i = 0; i < data.length; i++) { subImageWithFill(data[i], width >> color.compWidth[i], height >> color.compHeight[i], out.getPlaneData(i), rect.getWidth() >> color.compWidth[i], rect.getHeight() >> color.compHeight[i], rect.getX() >> color.compWidth[i], rect.getY() >> color.compHeight[i]); } } }
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)); } }