Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comparison when layout differs #111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Diff.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module MakeDiff (IO1 : ImageIO.ImageIO) (IO2 : ImageIO.ImageIO) = struct
if alpha <> Int32.zero then countDifference !x !y)
else
let compColor =
if layoutDifference then IO1.readRawPixel ~x:!x ~y:!y base
if layoutDifference then IO2.readRawPixel ~x:!x ~y:!y comp
else IO2.readRawPixelAtOffset offset comp
in

Expand Down
19 changes: 17 additions & 2 deletions test/Test_Core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ let test_different_sized_aa_images () =
let _, diffPixels, diffPercentage, _ =
PNG_Diff.compare img1 img2 ~outputDiffMask:true ~antialiasing:true ()
in
check int "diffPixels" 399 diffPixels;
check (float 0.01) "diffPercentage" 0.99 diffPercentage
check int "diffPixels" 417 diffPixels;
check (float 0.01) "diffPercentage" 1.0425 diffPercentage

let test_threshold () =
let img1 = Png.IO.loadImage "test-images/png/orange.png" in
Expand Down Expand Up @@ -73,6 +73,16 @@ let test_blend_semi_transparent_color () =
test_blend 0. 128. 255. 51. 204. 229.6 255. 0.2;
test_blend 0. 128. 255. 128. 127. 191.25 255. 0.5

let test_different_layouts () =
Sys.getcwd () |> print_endline;
let img1 = Png.IO.loadImage "test-images/png/white4x4.png" in
let img2 = Png.IO.loadImage "test-images/png/purple8x8.png" in
let _, diffPixels, diffPercentage, _ =
PNG_Diff.compare img1 img2 ~outputDiffMask:false ~antialiasing:false ()
in
check int "diffPixels" 16 diffPixels;
check (float 0.001) "diffPercentage" 100.0 diffPercentage

let () =
run "CORE"
[
Expand All @@ -98,4 +108,9 @@ let () =
test_case "blend semi-transparent colors" `Quick
test_blend_semi_transparent_color;
] );
( "layoutDifference",
[
test_case "diff images with different layouts" `Quick
test_different_layouts;
] );
]
Binary file added test/test-images/png/purple8x8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/test-images/png/white4x4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading