diff --git a/CHANGELOG.md b/CHANGELOG.md index 40c5070e..3e19a09e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Prevent premature deallocations with `LeptonicaFrameConverter` ([issue bytedeco/javacpp#272](https://github.com/bytedeco/javacpp/issues/272)) * Fix `OpenCVFrameGrabber` from crashing when in `ImageMode.GRAY` * Add support for multiple inputs to `FFmpegFrameFilter` ([issue #955](https://github.com/bytedeco/javacv/issues/955)) * Fix fps in output of `FFmpegFrameRecorder` by setting deprecated `AVStream.codec.time_base` ([issue #1069](https://github.com/bytedeco/javacv/issues/1069)) diff --git a/src/main/java/org/bytedeco/javacv/LeptonicaFrameConverter.java b/src/main/java/org/bytedeco/javacv/LeptonicaFrameConverter.java index c7f8d819..549f9162 100644 --- a/src/main/java/org/bytedeco/javacv/LeptonicaFrameConverter.java +++ b/src/main/java/org/bytedeco/javacv/LeptonicaFrameConverter.java @@ -56,14 +56,15 @@ public PIX convert(Frame frame) { } else if (frame.opaque instanceof PIX) { return (PIX)frame.opaque; } else if (!isEqual(frame, pix)) { - pix = PIX.createHeader(frame.imageWidth, frame.imageHeight, frame.imageChannels * 8) - .wpl(frame.imageStride / 4 * Math.abs(frame.imageDepth) / 8); + Pointer data; if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { pixBuffer = ByteBuffer.allocateDirect(frame.imageHeight * frame.imageStride).order(ByteOrder.BIG_ENDIAN); - pix.data(new IntPointer(new Pointer(pixBuffer))); + data = new Pointer(pixBuffer); } else { - pix.data(new IntPointer(new Pointer(frame.image[0].position(0)))); + data = new Pointer(frame.image[0].position(0)); } + pix = PIX.create(frame.imageWidth, frame.imageHeight, frame.imageChannels * 8, data) + .wpl(frame.imageStride / 4 * Math.abs(frame.imageDepth) / 8); } if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {