public static Picture fromPictureHiBD(PictureHiBD pic) { int lowBitsNum = pic.getBitDepth() - 8; int lowBitsRound = (1 << lowBitsNum) >> 1; Picture result = Picture.createCroppedHiBD(pic.getWidth(), pic.getHeight(), lowBitsNum, pic.getColor(), pic.getCrop()); for (int i = 0; i < Math.min(pic.getData().length, result.getData().length); i++) { for (int j = 0; j < Math.min(pic.getData()[i].length, result.getData()[i].length); j++) { int val = pic.getData()[i][j]; int round = MathUtil.clip((val + lowBitsRound) >> lowBitsNum, 0, 255); result.getData()[i][j] = (byte) (round - 128); } } byte[][] lowBits = result.getLowBits(); if (lowBits != null) { for (int i = 0; i < Math.min(pic.getData().length, result.getData().length); i++) { for (int j = 0; j < Math.min(pic.getData()[i].length, result.getData()[i].length); j++) { int val = pic.getData()[i][j]; int round = MathUtil.clip((val + lowBitsRound) >> lowBitsNum, 0, 255); lowBits[i][j] = (byte) (val - (round << 2)); } } } return result; }
public void transform(PictureHiBD img, PictureHiBD dst) { int[] y = img.getData()[0]; int[][] dstData = dst.getData(); int off = 0, offSrc = 0; for (int i = 0; i < img.getHeight(); i++) { for (int j = 0; j < img.getWidth() >> 1; j++) { dstData[1][off] = 0; dstData[2][off] = 0; int offY = off << 1; RgbToYuv420pHiBD.rgb2yuv(y[offSrc++], y[offSrc++], y[offSrc++], dstData[0], offY, dstData[1], off, dstData[2], off); dstData[0][offY] = (dstData[0][offY] << upShift) >> downShift; RgbToYuv420pHiBD.rgb2yuv(y[offSrc++], y[offSrc++], y[offSrc++], dstData[0], offY + 1, dstData[1], off, dstData[2], off); dstData[0][offY + 1] = (dstData[0][offY + 1] << upShift) >> downShift; dstData[1][off] = (dstData[1][off] << upShift) >> downShiftChr; dstData[2][off] = (dstData[2][off] << upShift) >> downShiftChr; ++off; } } } }
private PictureHiBD toPictureHiBDInternal(PictureHiBD pic) { int[][] dstData = pic.getData(); for (int i = 0; i < data.length; i++) { int planeSize = getPlaneWidth(i) * getPlaneHeight(i); for (int j = 0; j < planeSize; j++) { dstData[i][j] = (data[i][j] + 128) << lowBitsNum; } } if (lowBits != null) { for (int i = 0; i < lowBits.length; i++) { int planeSize = getPlaneWidth(i) * getPlaneHeight(i); for (int j = 0; j < planeSize; j++) { dstData[i][j] += lowBits[i][j]; } } } return pic; }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof PictureHiBD)) return false; PictureHiBD other = (PictureHiBD) obj; if (other.getCroppedWidth() != getCroppedWidth() || other.getCroppedHeight() != getCroppedHeight() || other.getColor() != color) return false; for (int i = 0; i < getData().length; i++) if (!planeEquals(other, i)) return false; return true; }