-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathResizeVisualTests.swift
More file actions
73 lines (51 loc) · 2.84 KB
/
ResizeVisualTests.swift
File metadata and controls
73 lines (51 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import XCTest
import Swim
class ResizeVisualTests: XCTestCase {
}
#if canImport(AppKit)
import AppKit
extension ResizeVisualTests {
func testResize() {
let image = Image<RGB, Double>(width: 4,
height: 4,
data: (0..<4*4*3).map { _ in Double.random(in: 0..<1) })
let resizedNN = image.resize(width: 128, height: 192, method: .nearestNeighbor)
let resizedBL = image.resize(width: 128, height: 192, method: .bilinear)
let resizedBC = image.resize(width: 128, height: 192, method: .bicubic)
let resizedAA = image.resize(width: 128, height: 192, method: .areaAverage)
let concat = Image.concatH([resizedNN, resizedBL, resizedBC, resizedAA])
let nsImage = doubleToNSImage(concat)
XCTAssertTrue(nsImage.isValid, "Break and check nsImage in debugger.")
}
func testResizeUpscale_lena() {
let path = testResoruceRoot().appendingPathComponent("lena_128.png")
let lena = try! Image<RGB, Double>(contentsOf: path)
var images = [Image<RGB, Double>]()
let size = 300
images.append(lena.resize(width: size, height: size, method: .nearestNeighbor))
images.append(lena.resize(width: size, height: size, method: .bilinear))
images.append(lena.resize(width: size, height: size, method: .bicubic))
images.append(lena.resize(width: size, height: size, method: .lanczos2))
images.append(lena.resize(width: size, height: size, method: .lanczos3))
images.append(lena.resize(width: size, height: size, method: .areaAverage))
let image = Image.concatH(images)
let nsImage = doubleToNSImage(image.toRGBA(with: 1))
XCTAssertTrue(nsImage.isValid, "Break and check nsImage in debugger.")
}
func testResizeDownscale_lena() {
let path = testResoruceRoot().appendingPathComponent("lena_512.png")
let lena = try! Image<RGB, Double>(contentsOf: path)
var images = [Image<RGB, Double>]()
let size = 100
images.append(lena.resize(width: size, height: size, method: .nearestNeighbor))
images.append(lena.resize(width: size, height: size, method: .bilinear))
images.append(lena.resize(width: size, height: size, method: .bicubic))
images.append(lena.resize(width: size, height: size, method: .lanczos2))
images.append(lena.resize(width: size, height: size, method: .lanczos3))
images.append(lena.resize(width: size, height: size, method: .areaAverage))
let image = Image.concatH(images)
let nsImage = doubleToNSImage(image.toRGBA(with: 1))
XCTAssertTrue(nsImage.isValid, "Break and check nsImage in debugger.")
}
}
#endif