in java/org/libjpegturbo/turbojpeg/YUVImage.java [221:268]
private void setBuf(byte[][] planes, int[] offsets, int width, int[] strides,
int height, int subsamp, boolean alloc) {
if ((planes == null && !alloc) || width < 1 || height < 1 || subsamp < 0 ||
subsamp >= TJ.NUMSAMP)
throw new IllegalArgumentException("Invalid argument in YUVImage.setBuf()");
int nc = (subsamp == TJ.SAMP_GRAY ? 1 : 3);
if ((planes != null && planes.length != nc) ||
(offsets != null && offsets.length != nc) ||
(strides != null && strides.length != nc))
throw new IllegalArgumentException("YUVImage.setBuf(): planes, offsets, or strides array is the wrong size");
if (planes == null)
planes = new byte[nc][];
if (offsets == null)
offsets = new int[nc];
if (strides == null)
strides = new int[nc];
for (int i = 0; i < nc; i++) {
int pw = TJ.planeWidth(i, width, subsamp);
int ph = TJ.planeHeight(i, height, subsamp);
int planeSize = TJ.planeSizeYUV(i, width, strides[i], height, subsamp);
if (strides[i] == 0)
strides[i] = pw;
if (alloc) {
if (strides[i] < pw)
throw new IllegalArgumentException("Stride must be >= plane width when allocating a new YUV image");
planes[i] = new byte[strides[i] * ph];
}
if (planes[i] == null || offsets[i] < 0)
throw new IllegalArgumentException("Invalid argument in YUVImage.setBuf()");
if (strides[i] < 0 && offsets[i] - planeSize + pw < 0)
throw new IllegalArgumentException("Stride for plane " + i +
" would cause memory to be accessed below plane boundary");
if (planes[i].length < offsets[i] + planeSize)
throw new IllegalArgumentException("Image plane " + i +
" is not large enough");
}
yuvPlanes = planes;
yuvOffsets = offsets;
yuvWidth = width;
yuvStrides = strides;
yuvHeight = height;
yuvSubsamp = subsamp;
}