Class PdfVisualTester
- java.lang.Object
-
- com.openhtmltopdf.pdfboxout.visualtester.PdfVisualTester
-
public class PdfVisualTester extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPdfVisualTester.PdfCompareResultstatic classPdfVisualTester.ProblemTypestatic classPdfVisualTester.TestImage
-
Field Summary
Fields Modifier and Type Field Description private static intLEFT_MARGIN_PXprivate static intLINE_HEIGHT_PXprivate static java.awt.image.BufferedImageONE_PX_IMAGE
-
Constructor Summary
Constructors Constructor Description PdfVisualTester()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static intcalcCombinedIntensity(int element)Calculate the combined intensity of a pixel and normalizes it to a value of at most 255.private static intcolor(int r, int g, int b)static java.util.List<PdfVisualTester.PdfCompareResult>comparePdfDocuments(byte[] expected, byte[] actual, java.lang.String testName, boolean keepSameImages)Compares two PDF documents by rendering each page to an image and comparing pixel by pixel.static java.awt.image.BufferedImagecreateDiffImage(java.awt.image.BufferedImage img1, java.awt.image.BufferedImage img2)private static intfade(int i)private static intfadeElement(int i)private static intgetActualPixel(java.awt.image.BufferedImage img, int x, int y)private static intgetElement(int expectedElement, int actualElement)private static intgetExpectedPixel(java.awt.image.BufferedImage img, int x, int y)private static booleanisImageDifferent(java.awt.image.BufferedImage imgExpected, java.awt.image.BufferedImage imgActual)Gets the data buffer of each image and compares.private static intlevelIntensity(int darkness, int maxIntensity)Levels the color intensity to at least 50 and at most maxIntensity.
-
-
-
Field Detail
-
LEFT_MARGIN_PX
private static final int LEFT_MARGIN_PX
- See Also:
- Constant Field Values
-
LINE_HEIGHT_PX
private static final int LINE_HEIGHT_PX
- See Also:
- Constant Field Values
-
ONE_PX_IMAGE
private static final java.awt.image.BufferedImage ONE_PX_IMAGE
-
-
Method Detail
-
comparePdfDocuments
public static java.util.List<PdfVisualTester.PdfCompareResult> comparePdfDocuments(byte[] expected, byte[] actual, java.lang.String testName, boolean keepSameImages) throws java.io.IOException
Compares two PDF documents by rendering each page to an image and comparing pixel by pixel.- Parameters:
expected-actual-testName-keepSameImages- Whether to return the images in the case they are good (ie. the same).- Returns:
- A list of
PdfVisualTester.PdfCompareResultinstances describing differences. - Throws:
java.lang.Exceptionjava.io.IOException
-
isImageDifferent
private static boolean isImageDifferent(java.awt.image.BufferedImage imgExpected, java.awt.image.BufferedImage imgActual)Gets the data buffer of each image and compares. NOTE: May be an expensive (memory and CPU) operation for large images.- Parameters:
imgExpected-imgActual-- Returns:
- whether imgExpected is different image compared to imgActual
-
createDiffImage
public static java.awt.image.BufferedImage createDiffImage(java.awt.image.BufferedImage img1, java.awt.image.BufferedImage img2)
-
getExpectedPixel
private static int getExpectedPixel(java.awt.image.BufferedImage img, int x, int y)
-
getActualPixel
private static int getActualPixel(java.awt.image.BufferedImage img, int x, int y)
-
getElement
private static int getElement(int expectedElement, int actualElement)
-
levelIntensity
private static int levelIntensity(int darkness, int maxIntensity)Levels the color intensity to at least 50 and at most maxIntensity.- Parameters:
darkness- color component to levelmaxIntensity- highest possible intensity cut off- Returns:
- A value that is at least 50 and at most maxIntensity
-
calcCombinedIntensity
private static int calcCombinedIntensity(int element)
Calculate the combined intensity of a pixel and normalizes it to a value of at most 255.- Parameters:
element-- Returns:
-
color
private static int color(int r, int g, int b)
-
fadeElement
private static int fadeElement(int i)
-
fade
private static int fade(int i)
-
-