public static PictureHiBD createPictureCropped(int width, int height, int[][] data, ColorSpace color, Rect crop) { return new PictureHiBD(width, height, data, color, 8, crop); }
public void copyFrom(PictureHiBD src) { if (!compatible(src)) throw new IllegalArgumentException("Can not copy to incompatible picture"); for (int plane = 0; plane < color.nComp; plane++) { if (data[plane] == null) continue; arraycopy(src.data[plane], 0, data[plane], 0, (width >> color.compWidth[plane]) * (height >> color.compHeight[plane])); } }
public PictureHiBD createCompatible() { return PictureHiBD.create(width, height, color); }
@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; }
@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; } }
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; }
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 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 createCropped(int width, int height, ColorSpace colorSpace, Rect crop) { return doCreate(width, height, colorSpace, 8, crop); }
public static PictureHiBD createWithDepth(int width, int height, ColorSpace colorSpace, int bitDepth) { return doCreate(width, height, colorSpace, bitDepth, null); }
public static PictureHiBD clonePicture(PictureHiBD other) { return new PictureHiBD(other.width, other.height, other.data, other.color, other.bitDepth, other.crop); }
public static PictureHiBD create(int width, int height, ColorSpace colorSpace) { return doCreate(width, height, colorSpace, 8, null); }
public static PictureHiBD doCreate(int width, int height, ColorSpace colorSpace, int bitDepth, Rect crop) { int[] planeSizes = new int[MAX_PLANES]; for (int i = 0; i < colorSpace.nComp; i++) { planeSizes[colorSpace.compPlane[i]] += (width >> colorSpace.compWidth[i]) * (height >> colorSpace.compHeight[i]); } int nPlanes = 0; for (int i = 0; i < MAX_PLANES; i++) nPlanes += planeSizes[i] != 0 ? 1 : 0; int[][] data = new int[nPlanes][]; for (int i = 0, plane = 0; i < MAX_PLANES; i++) { if (planeSizes[i] != 0) { data[plane++] = new int[planeSizes[i]]; } } return new PictureHiBD(width, height, data, colorSpace, 8, crop); }
public PictureHiBD toPictureHiBD() { PictureHiBD create = PictureHiBD.doCreate(width, height, color, lowBitsNum + 8, crop); return toPictureHiBDInternal(create); }
public PictureHiBD toPictureHiBDWithBuffer(int[][] buffer) { PictureHiBD create = new PictureHiBD(width, height, buffer, color, lowBitsNum + 8, crop); return toPictureHiBDInternal(create); }
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 PictureHiBD createPicture(int width, int height, int[][] data, ColorSpace color) { return new PictureHiBD(width, height, data, color, 8, new Rect(0, 0, width, height)); }