@Override public void transform(PictureHiBD src, PictureHiBD dst) { if (src.getColor() != ColorSpace.RGB && src.getColor() != ColorSpace.BGR || dst.getColor() != ColorSpace.RGB && dst.getColor() != ColorSpace.BGR) { throw new IllegalArgumentException( "Expected RGB or BGR inputs, was: " + src.getColor() + ", " + dst.getColor()); } if (src.getCrop() != null || dst.getCrop() != null) throw new NotSupportedException("Cropped images not supported"); int[] dataSrc = src.getPlaneData(0); int[] dataDst = dst.getPlaneData(0); for (int i = 0; i < dataSrc.length; i += 3) { // src and dst can actually be the same array int tmp = dataSrc[i + 2]; dataDst[i + 2] = dataSrc[i]; dataDst[i] = tmp; } }
@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; }
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; }