Merge pull request #417 from guzba/master

jpeg tests/ stuff
This commit is contained in:
treeform 2022-05-11 20:14:47 -07:00 committed by GitHub
commit 0d3d16efb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 58 additions and 181 deletions

2
.gitignore vendored
View file

@ -15,4 +15,4 @@ bindings/generated
*.dSYM
dump.txt
tests/fileformats/jpeg/generated
tests/fileformats/jpeg/diff
tests/fileformats/jpeg/diffs

View file

@ -1,46 +1,6 @@
import benchy, pixie/fileformats/jpg
import benchy, jpegsuite, pixie/fileformats/jpg
var files = @[
"tests/fileformats/jpeg/master/red.jpg",
"tests/fileformats/jpeg/master/green.jpg",
"tests/fileformats/jpeg/master/blue.jpg",
"tests/fileformats/jpeg/master/white.jpg",
"tests/fileformats/jpeg/master/black.jpg",
"tests/fileformats/jpeg/master/8x8.jpg",
"tests/fileformats/jpeg/master/8x8_progressive.jpg",
"tests/fileformats/jpeg/master/16x16.jpg",
"tests/fileformats/jpeg/master/16x16_progressive.jpg",
"tests/fileformats/jpeg/master/quality_01.jpg",
"tests/fileformats/jpeg/master/quality_10.jpg",
"tests/fileformats/jpeg/master/quality_25.jpg",
"tests/fileformats/jpeg/master/quality_50.jpg",
"tests/fileformats/jpeg/master/quality_100.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_2_2.jpg",
"tests/fileformats/jpeg/master/cat_4_2_0.jpg",
"tests/fileformats/jpeg/master/cat_4_1_1.jpg",
"tests/fileformats/jpeg/master/cat_4_2_0_progressive.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4_progressive.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5_progressive.jpg",
"tests/fileformats/jpeg/master/mandrill.jpg",
"tests/fileformats/jpeg/master/exif_overrun.jpg",
"tests/fileformats/jpeg/master/grayscale_test.jpg",
"tests/fileformats/jpeg/master/progressive.jpg",
"tests/fileformats/jpeg/master/testimg.jpg",
"tests/fileformats/jpeg/master/testimgp.jpg",
"tests/fileformats/jpeg/master/testorig.jpg",
"tests/fileformats/jpeg/master/testprog.jpg",
]
for file in files:
for file in jpegSuiteFiles:
let data = readFile(file)
timeIt "jpeg " & $(len(data) div 1024) & "k decode":
discard decodeJpg(data)

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 626 B

After

Width:  |  Height:  |  Size: 626 B

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

Before

Width:  |  Height:  |  Size: 589 B

After

Width:  |  Height:  |  Size: 589 B

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

Before

Width:  |  Height:  |  Size: 636 B

After

Width:  |  Height:  |  Size: 636 B

View file

Before

Width:  |  Height:  |  Size: 639 B

After

Width:  |  Height:  |  Size: 639 B

View file

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View file

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View file

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

View file

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View file

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View file

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View file

Before

Width:  |  Height:  |  Size: 639 B

After

Width:  |  Height:  |  Size: 639 B

View file

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 75 KiB

View file

Before

Width:  |  Height:  |  Size: 285 KiB

After

Width:  |  Height:  |  Size: 285 KiB

View file

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View file

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View file

Before

Width:  |  Height:  |  Size: 639 B

After

Width:  |  Height:  |  Size: 639 B

View file

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View file

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View file

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

Before

Width:  |  Height:  |  Size: 634 B

After

Width:  |  Height:  |  Size: 634 B

View file

@ -1,57 +1,15 @@
import pixie/common, pixie/fileformats/jpg, random, strformat
import jpegsuite, pixie/common, pixie/fileformats/jpg, random, strformat
randomize()
var files = @[
"tests/fileformats/jpeg/master/red.jpg",
"tests/fileformats/jpeg/master/green.jpg",
"tests/fileformats/jpeg/master/blue.jpg",
"tests/fileformats/jpeg/master/white.jpg",
"tests/fileformats/jpeg/master/black.jpg",
"tests/fileformats/jpeg/master/8x8.jpg",
"tests/fileformats/jpeg/master/8x8_progressive.jpg",
"tests/fileformats/jpeg/master/16x16.jpg",
"tests/fileformats/jpeg/master/16x16_progressive.jpg",
"tests/fileformats/jpeg/master/quality_01.jpg",
"tests/fileformats/jpeg/master/quality_10.jpg",
"tests/fileformats/jpeg/master/quality_25.jpg",
"tests/fileformats/jpeg/master/quality_50.jpg",
"tests/fileformats/jpeg/master/quality_100.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_2_2.jpg",
"tests/fileformats/jpeg/master/cat_4_2_0.jpg",
"tests/fileformats/jpeg/master/cat_4_1_1.jpg",
"tests/fileformats/jpeg/master/cat_4_2_0_progressive.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4_progressive.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5_progressive.jpg",
"tests/fileformats/jpeg/master/mandrill.jpg",
"tests/fileformats/jpeg/master/exif_overrun.jpg",
"tests/fileformats/jpeg/master/grayscale_test.jpg",
"tests/fileformats/jpeg/master/progressive.jpg",
"tests/fileformats/jpeg/master/testimg.jpg",
"tests/fileformats/jpeg/master/testimgp.jpg",
"tests/fileformats/jpeg/master/testorig.jpg",
"tests/fileformats/jpeg/master/testprog.jpg",
]
for i in 0 ..< 10_000:
let original = readFile(sample(files))
var data = original
let file = sample(jpegSuiteFiles)
var data = readFile(file)
let
pos = rand(0 ..< data.len)
value = rand(255).uint8
data[pos] = value.char
echo &"{i} {pos} {value}"
echo &"{i} {file} {pos} {value}"
try:
let img = decodeJpg(data)

39
tests/jpegsuite.nim Normal file
View file

@ -0,0 +1,39 @@
const jpegSuiteFiles* = [
"tests/fileformats/jpeg/masters/red.jpg",
"tests/fileformats/jpeg/masters/green.jpg",
"tests/fileformats/jpeg/masters/blue.jpg",
"tests/fileformats/jpeg/masters/white.jpg",
"tests/fileformats/jpeg/masters/black.jpg",
"tests/fileformats/jpeg/masters/8x8.jpg",
"tests/fileformats/jpeg/masters/8x8_progressive.jpg",
"tests/fileformats/jpeg/masters/16x16.jpg",
"tests/fileformats/jpeg/masters/16x16_progressive.jpg",
"tests/fileformats/jpeg/masters/quality_01.jpg",
"tests/fileformats/jpeg/masters/quality_10.jpg",
"tests/fileformats/jpeg/masters/quality_25.jpg",
"tests/fileformats/jpeg/masters/quality_50.jpg",
"tests/fileformats/jpeg/masters/quality_100.jpg",
"tests/fileformats/jpeg/masters/cat_4_4_4.jpg",
"tests/fileformats/jpeg/masters/cat_4_4_4.jpg",
"tests/fileformats/jpeg/masters/cat_4_2_2.jpg",
"tests/fileformats/jpeg/masters/cat_4_2_0.jpg",
"tests/fileformats/jpeg/masters/cat_4_1_1.jpg",
"tests/fileformats/jpeg/masters/cat_4_2_0_progressive.jpg",
"tests/fileformats/jpeg/masters/cat_4_4_4_progressive.jpg",
"tests/fileformats/jpeg/masters/cat_restart_markers_5.jpg",
"tests/fileformats/jpeg/masters/cat_restart_markers_5_progressive.jpg",
"tests/fileformats/jpeg/masters/mandrill.jpg",
"tests/fileformats/jpeg/masters/exif_overrun.jpg",
"tests/fileformats/jpeg/masters/grayscale_test.jpg",
"tests/fileformats/jpeg/masters/progressive.jpg",
"tests/fileformats/jpeg/masters/testimg.jpg",
"tests/fileformats/jpeg/masters/testimgp.jpg",
"tests/fileformats/jpeg/masters/testorig.jpg",
"tests/fileformats/jpeg/masters/testprog.jpg",
]

View file

@ -1,47 +1,4 @@
import pixie, strutils
import jpegsuite, pixie
import pixie/fileformats/jpg
var files = @[
"tests/fileformats/jpeg/master/red.jpg",
"tests/fileformats/jpeg/master/green.jpg",
"tests/fileformats/jpeg/master/blue.jpg",
"tests/fileformats/jpeg/master/white.jpg",
"tests/fileformats/jpeg/master/black.jpg",
"tests/fileformats/jpeg/master/8x8.jpg",
"tests/fileformats/jpeg/master/8x8_progressive.jpg",
"tests/fileformats/jpeg/master/16x16.jpg",
"tests/fileformats/jpeg/master/16x16_progressive.jpg",
"tests/fileformats/jpeg/master/quality_01.jpg",
"tests/fileformats/jpeg/master/quality_10.jpg",
"tests/fileformats/jpeg/master/quality_25.jpg",
"tests/fileformats/jpeg/master/quality_50.jpg",
"tests/fileformats/jpeg/master/quality_100.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_2_2.jpg",
"tests/fileformats/jpeg/master/cat_4_2_0.jpg",
"tests/fileformats/jpeg/master/cat_4_1_1.jpg",
"tests/fileformats/jpeg/master/cat_4_2_0_progressive.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4_progressive.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5_progressive.jpg",
"tests/fileformats/jpeg/master/mandrill.jpg",
"tests/fileformats/jpeg/master/exif_overrun.jpg",
"tests/fileformats/jpeg/master/grayscale_test.jpg",
"tests/fileformats/jpeg/master/progressive.jpg",
"tests/fileformats/jpeg/master/testimg.jpg",
"tests/fileformats/jpeg/master/testimgp.jpg",
"tests/fileformats/jpeg/master/testorig.jpg",
"tests/fileformats/jpeg/master/testprog.jpg",
]
for file in files:
var img = decodeJpg(readFile(file))
# img.writeFile(file.replace("master", "generated").replace(".jpg", ".jpeg.png"))
for file in jpegSuiteFiles:
let img = readImage(file)

View file

@ -1,58 +1,21 @@
import pixie, strutils, os, strformat
import jpegsuite, os, pixie, strformat, strutils
import pixie/fileformats/jpg
createDir("tests/fileformats/jpeg/generated")
createDir("tests/fileformats/jpeg/diffs")
var files = @[
"tests/fileformats/jpeg/master/red.jpg",
"tests/fileformats/jpeg/master/green.jpg",
"tests/fileformats/jpeg/master/blue.jpg",
"tests/fileformats/jpeg/master/white.jpg",
"tests/fileformats/jpeg/master/black.jpg",
for file in jpegSuiteFiles:
let img = readImage(file)
"tests/fileformats/jpeg/master/8x8.jpg",
"tests/fileformats/jpeg/master/8x8_progressive.jpg",
"tests/fileformats/jpeg/master/16x16.jpg",
"tests/fileformats/jpeg/master/16x16_progressive.jpg",
"tests/fileformats/jpeg/master/quality_01.jpg",
"tests/fileformats/jpeg/master/quality_10.jpg",
"tests/fileformats/jpeg/master/quality_25.jpg",
"tests/fileformats/jpeg/master/quality_50.jpg",
"tests/fileformats/jpeg/master/quality_100.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_2_2.jpg",
"tests/fileformats/jpeg/master/cat_4_2_0.jpg",
"tests/fileformats/jpeg/master/cat_4_1_1.jpg",
"tests/fileformats/jpeg/master/cat_4_2_0_progressive.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4_progressive.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5_progressive.jpg",
"tests/fileformats/jpeg/master/mandrill.jpg",
"tests/fileformats/jpeg/master/exif_overrun.jpg",
"tests/fileformats/jpeg/master/grayscale_test.jpg",
"tests/fileformats/jpeg/master/progressive.jpg",
"tests/fileformats/jpeg/master/testimg.jpg",
"tests/fileformats/jpeg/master/testimgp.jpg",
"tests/fileformats/jpeg/master/testorig.jpg",
"tests/fileformats/jpeg/master/testprog.jpg",
]
for file in files:
var img = decodeJpg(readFile(file))
let genFile = file.replace("master", "generated").replace(".jpg", ".png")
let diffFile = file.replace("master", "diff").replace(".jpg", ".png")
let genFile = file.replace("masters", "generated").replace(".jpg", ".png")
img.writeFile(genFile)
if execShellCmd(&"convert {file} {genFile}") != 0:
echo "fail"
var img2 = readImage(genFile)
let (score, diff) = img2.diff(img)
let diffFile = file.replace("master", "diff").replace(".jpg", ".png")
diff.writeFile(diffFile)
if score > 1: