From 193d07229dfd3eb0b2219a58c3f3329e0957df31 Mon Sep 17 00:00:00 2001 From: alexcohn Date: Thu, 18 Jul 2019 15:53:37 +0300 Subject: [PATCH] fix Pixa.replacePix() fix JavaDoc enable and fix testPixaReplacePix see https://github.com/rmtheis/tess-two/issues/159#issuecomment-512792727 --- .../leptonica/android/test/PixaTest.java | 62 +++++++++---------- .../googlecode/leptonica/android/Pixa.java | 6 +- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/tess-two-test/src/com/googlecode/leptonica/android/test/PixaTest.java b/tess-two-test/src/com/googlecode/leptonica/android/test/PixaTest.java index 2b555bd52..5999733ae 100644 --- a/tess-two-test/src/com/googlecode/leptonica/android/test/PixaTest.java +++ b/tess-two-test/src/com/googlecode/leptonica/android/test/PixaTest.java @@ -146,38 +146,36 @@ private void internalTestPixaJoin(int sizeA, int sizeB) { pixaB.recycle(); } -// @SmallTest -// public void testPixaReplacePix() { -// Pixa pixa = Pixa.createPixa(0, 640, 480); -// -// // Populate the Pixa. -// addBlockToPixa(pixa, 0, 0, 640, 480, 8); -// -// Pix pix = new Pix(320, 240, 8); -// Box box = new Box(320, 240, 320, 240); -// -// // Replace the existing Pix. -// pixa.replacePix(0, pix, box); -// -// // Ensure the replacement was successful. -// Pix returnedPix = pixa.getPix(0); -// Box returnedBox = pixa.getBox(0); -// -// assertEquals(pix.getWidth(), returnedPix.getWidth()); -// assertEquals(pix.getHeight(), returnedPix.getHeight()); -// assertEquals(pix.getDepth(), returnedPix.getDepth()); -// -// assertEquals(box.getX(), returnedBox.getX()); -// assertEquals(box.getY(), returnedBox.getY()); -// assertEquals(box.getWidth(), returnedBox.getWidth()); -// assertEquals(box.getHeight(), returnedBox.getHeight()); -// -// pix.recycle(); -// box.recycle(); -// returnedPix.recycle(); -// returnedBox.recycle(); -// pixa.recycle(); -// } + @SmallTest + public void testPixaReplacePix() { + Pixa pixa = Pixa.createPixa(0, 640, 480); + + // Populate the Pixa. + addBlockToPixa(pixa, 0, 0, 640, 480, 8); + + Pix pix = new Pix(320, 240, 8); + Box box = new Box(320, 240, 320, 240); + + // Replace the existing Pix. + pixa.replacePix(0, pix, box); + + // Ensure the replacement was successful. + Pix returnedPix = pixa.getPix(0); + Box returnedBox = pixa.getBox(0); + + assertEquals(pix.getWidth(), returnedPix.getWidth()); + assertEquals(pix.getHeight(), returnedPix.getHeight()); + assertEquals(pix.getDepth(), returnedPix.getDepth()); + + assertEquals(box.getX(), returnedBox.getX()); + assertEquals(box.getY(), returnedBox.getY()); + assertEquals(box.getWidth(), returnedBox.getWidth()); + assertEquals(box.getHeight(), returnedBox.getHeight()); + + returnedPix.recycle(); + returnedBox.recycle(); + pixa.recycle(); + } @SmallTest public void testPixaMergeAndReplacePix() { diff --git a/tess-two/src/com/googlecode/leptonica/android/Pixa.java b/tess-two/src/com/googlecode/leptonica/android/Pixa.java index aba993857..2422c7947 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Pixa.java +++ b/tess-two/src/com/googlecode/leptonica/android/Pixa.java @@ -412,11 +412,11 @@ public ArrayList getBoxRects() { /** * Replaces the Pix and Box at the specified index with the specified Pix - * and Box, both of which may be recycled after calling this method. + * and Box, both of which should not be recycled after calling this method. * * @param index The index of the Pix to replace. - * @param pix The Pix to replace the existing Pix. - * @param box The Box to replace the existing Box. + * @param pix The Pix to replace the existing Pix; it becomes an alias of the one stored in Pixa. + * @param box The Box to replace the existing Box; it becomes an alias of the one stored in Pixa. */ public void replacePix(int index, Pix pix, Box box) { if (mRecycled)