Update highgui+HighGui.java

toBufferedImage
Modifying the original array copying method here can double the speed.
pull/25322/head
sepperliu 1 year ago committed by Alexander Smorkalov
parent 13c95efa74
commit 45587f23db
  1. 7
      modules/highgui/misc/java/src/java/highgui+HighGui.java

@ -62,14 +62,9 @@ public final class HighGui {
if (m.channels() > 1) { if (m.channels() > 1) {
type = BufferedImage.TYPE_3BYTE_BGR; type = BufferedImage.TYPE_3BYTE_BGR;
} }
int bufferSize = m.channels() * m.cols() * m.rows();
byte[] b = new byte[bufferSize];
m.get(0, 0, b); // get all the pixels
BufferedImage image = new BufferedImage(m.cols(), m.rows(), type); BufferedImage image = new BufferedImage(m.cols(), m.rows(), type);
final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
System.arraycopy(b, 0, targetPixels, 0, b.length); m.get(0, 0, targetPixels);
return image; return image;
} }

Loading…
Cancel
Save