|
|
@ -332,8 +332,10 @@ public class JavaCamera2View extends CameraBridgeViewBase { |
|
|
|
Image.Plane[] planes = mImage.getPlanes(); |
|
|
|
Image.Plane[] planes = mImage.getPlanes(); |
|
|
|
int w = mImage.getWidth(); |
|
|
|
int w = mImage.getWidth(); |
|
|
|
int h = mImage.getHeight(); |
|
|
|
int h = mImage.getHeight(); |
|
|
|
|
|
|
|
assert(planes[0].getPixelStride() == 1); |
|
|
|
ByteBuffer y_plane = planes[0].getBuffer(); |
|
|
|
ByteBuffer y_plane = planes[0].getBuffer(); |
|
|
|
mGray = new Mat(h, w, CvType.CV_8UC1, y_plane); |
|
|
|
int y_plane_step = planes[0].getRowStride(); |
|
|
|
|
|
|
|
mGray = new Mat(h, w, CvType.CV_8UC1, y_plane, y_plane_step); |
|
|
|
return mGray; |
|
|
|
return mGray; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -349,11 +351,14 @@ public class JavaCamera2View extends CameraBridgeViewBase { |
|
|
|
assert(planes[0].getPixelStride() == 1); |
|
|
|
assert(planes[0].getPixelStride() == 1); |
|
|
|
assert(planes[2].getPixelStride() == 2); |
|
|
|
assert(planes[2].getPixelStride() == 2); |
|
|
|
ByteBuffer y_plane = planes[0].getBuffer(); |
|
|
|
ByteBuffer y_plane = planes[0].getBuffer(); |
|
|
|
|
|
|
|
int y_plane_step = planes[0].getRowStride(); |
|
|
|
ByteBuffer uv_plane1 = planes[1].getBuffer(); |
|
|
|
ByteBuffer uv_plane1 = planes[1].getBuffer(); |
|
|
|
|
|
|
|
int uv_plane1_step = planes[1].getRowStride(); |
|
|
|
ByteBuffer uv_plane2 = planes[2].getBuffer(); |
|
|
|
ByteBuffer uv_plane2 = planes[2].getBuffer(); |
|
|
|
Mat y_mat = new Mat(h, w, CvType.CV_8UC1, y_plane); |
|
|
|
int uv_plane2_step = planes[2].getRowStride(); |
|
|
|
Mat uv_mat1 = new Mat(h / 2, w / 2, CvType.CV_8UC2, uv_plane1); |
|
|
|
Mat y_mat = new Mat(h, w, CvType.CV_8UC1, y_plane, y_plane_step); |
|
|
|
Mat uv_mat2 = new Mat(h / 2, w / 2, CvType.CV_8UC2, uv_plane2); |
|
|
|
Mat uv_mat1 = new Mat(h / 2, w / 2, CvType.CV_8UC2, uv_plane1, uv_plane1_step); |
|
|
|
|
|
|
|
Mat uv_mat2 = new Mat(h / 2, w / 2, CvType.CV_8UC2, uv_plane2, uv_plane2_step); |
|
|
|
long addr_diff = uv_mat2.dataAddr() - uv_mat1.dataAddr(); |
|
|
|
long addr_diff = uv_mat2.dataAddr() - uv_mat1.dataAddr(); |
|
|
|
if (addr_diff > 0) { |
|
|
|
if (addr_diff > 0) { |
|
|
|
assert(addr_diff == 1); |
|
|
|
assert(addr_diff == 1); |
|
|
@ -369,30 +374,45 @@ public class JavaCamera2View extends CameraBridgeViewBase { |
|
|
|
ByteBuffer u_plane = planes[1].getBuffer(); |
|
|
|
ByteBuffer u_plane = planes[1].getBuffer(); |
|
|
|
ByteBuffer v_plane = planes[2].getBuffer(); |
|
|
|
ByteBuffer v_plane = planes[2].getBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
y_plane.get(yuv_bytes, 0, w*h); |
|
|
|
int yuv_bytes_offset = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int y_plane_step = planes[0].getRowStride(); |
|
|
|
|
|
|
|
if (y_plane_step == w) { |
|
|
|
|
|
|
|
y_plane.get(yuv_bytes, 0, w*h); |
|
|
|
|
|
|
|
yuv_bytes_offset = w*h; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
int padding = y_plane_step - w; |
|
|
|
|
|
|
|
for (int i = 0; i < h; i++){ |
|
|
|
|
|
|
|
y_plane.get(yuv_bytes, yuv_bytes_offset, w); |
|
|
|
|
|
|
|
yuv_bytes_offset += w; |
|
|
|
|
|
|
|
if (i < h - 1) { |
|
|
|
|
|
|
|
y_plane.position(y_plane.position() + padding); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
assert(yuv_bytes_offset == w * h); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int chromaRowStride = planes[1].getRowStride(); |
|
|
|
int chromaRowStride = planes[1].getRowStride(); |
|
|
|
int chromaRowPadding = chromaRowStride - w/2; |
|
|
|
int chromaRowPadding = chromaRowStride - w/2; |
|
|
|
|
|
|
|
|
|
|
|
int offset = w*h; |
|
|
|
|
|
|
|
if (chromaRowPadding == 0){ |
|
|
|
if (chromaRowPadding == 0){ |
|
|
|
// When the row stride of the chroma channels equals their width, we can copy
|
|
|
|
// When the row stride of the chroma channels equals their width, we can copy
|
|
|
|
// the entire channels in one go
|
|
|
|
// the entire channels in one go
|
|
|
|
u_plane.get(yuv_bytes, offset, w*h/4); |
|
|
|
u_plane.get(yuv_bytes, yuv_bytes_offset, w*h/4); |
|
|
|
offset += w*h/4; |
|
|
|
yuv_bytes_offset += w*h/4; |
|
|
|
v_plane.get(yuv_bytes, offset, w*h/4); |
|
|
|
v_plane.get(yuv_bytes, yuv_bytes_offset, w*h/4); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// When not equal, we need to copy the channels row by row
|
|
|
|
// When not equal, we need to copy the channels row by row
|
|
|
|
for (int i = 0; i < h/2; i++){ |
|
|
|
for (int i = 0; i < h/2; i++){ |
|
|
|
u_plane.get(yuv_bytes, offset, w/2); |
|
|
|
u_plane.get(yuv_bytes, yuv_bytes_offset, w/2); |
|
|
|
offset += w/2; |
|
|
|
yuv_bytes_offset += w/2; |
|
|
|
if (i < h/2-1){ |
|
|
|
if (i < h/2-1){ |
|
|
|
u_plane.position(u_plane.position() + chromaRowPadding); |
|
|
|
u_plane.position(u_plane.position() + chromaRowPadding); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i = 0; i < h/2; i++){ |
|
|
|
for (int i = 0; i < h/2; i++){ |
|
|
|
v_plane.get(yuv_bytes, offset, w/2); |
|
|
|
v_plane.get(yuv_bytes, yuv_bytes_offset, w/2); |
|
|
|
offset += w/2; |
|
|
|
yuv_bytes_offset += w/2; |
|
|
|
if (i < h/2-1){ |
|
|
|
if (i < h/2-1){ |
|
|
|
v_plane.position(v_plane.position() + chromaRowPadding); |
|
|
|
v_plane.position(v_plane.position() + chromaRowPadding); |
|
|
|
} |
|
|
|
} |
|
|
|