Class PdfVisualTester
java.lang.Object
com.openhtmltopdf.pdfboxout.visualtester.PdfVisualTester
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static enum
static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final BufferedImage
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
calcCombinedIntensity
(int element) Calculate the combined intensity of a pixel and normalizes it to a value of at most 255.private static int
color
(int r, int g, int b) static List
<PdfVisualTester.PdfCompareResult> comparePdfDocuments
(byte[] expected, byte[] actual, String testName, boolean keepSameImages) Compares two PDF documents by rendering each page to an image and comparing pixel by pixel.static BufferedImage
createDiffImage
(BufferedImage img1, BufferedImage img2) private static int
fade
(int i) private static int
fadeElement
(int i) private static int
getActualPixel
(BufferedImage img, int x, int y) private static int
getElement
(int expectedElement, int actualElement) private static int
getExpectedPixel
(BufferedImage img, int x, int y) private static boolean
isImageDifferent
(BufferedImage imgExpected, BufferedImage imgActual) Gets the data buffer of each image and compares.private static int
levelIntensity
(int darkness, int maxIntensity) Levels the color intensity to at least 50 and at most maxIntensity.
-
Field Details
-
LEFT_MARGIN_PX
private static final int LEFT_MARGIN_PX- See Also:
-
LINE_HEIGHT_PX
private static final int LINE_HEIGHT_PX- See Also:
-
ONE_PX_IMAGE
-
-
Constructor Details
-
PdfVisualTester
public PdfVisualTester()
-
-
Method Details
-
comparePdfDocuments
public static List<PdfVisualTester.PdfCompareResult> comparePdfDocuments(byte[] expected, byte[] actual, String testName, boolean keepSameImages) throws 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.PdfCompareResult
instances describing differences. - Throws:
Exception
IOException
-
isImageDifferent
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
-
getExpectedPixel
-
getActualPixel
-
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)
-