Test that fit=cover serves a source whose centre is under a pixel wide (part of #282)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
An 8192x1 source at 1x8192, or the same turned on its side, has a centre with the requested proportions 1/8192 of a pixel wide. The crop must keep at least one pixel of it, or the request fails. The test's cases are now named by source and requested size. Model: opus-5-5
This commit is contained in:
@@ -9,20 +9,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// TestImageProcessor_FitCoverServesThinSource verifies that FitCover serves
|
// TestImageProcessor_FitCoverServesThinSource verifies that FitCover serves
|
||||||
// a source of 8192x64 or 8192x1, or one of those turned on its side, at
|
// a thin source at the requested size. A source of 8192x64 or 8192x1 scaled
|
||||||
// 8192x8192. Scaling such a source to cover that size makes it 128 or 8192
|
// to cover 8192x8192 is 128 or 8192 times as long as the output on its long
|
||||||
// times as long as the output on its long side.
|
// side. The centre of an 8192x1 source with the proportions of 1x8192 is
|
||||||
|
// 1/8192 of a pixel wide. Each case is also turned on its side.
|
||||||
func TestImageProcessor_FitCoverServesThinSource(t *testing.T) {
|
func TestImageProcessor_FitCoverServesThinSource(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
inputWidth, inputHeight int
|
inputWidth, inputHeight int
|
||||||
|
size Size
|
||||||
}{
|
}{
|
||||||
{"8192x64", 8192, 64},
|
{"8192x64 at 8192x8192", 8192, 64, Size{Width: 8192, Height: 8192}},
|
||||||
{"8192x1", 8192, 1},
|
{"8192x1 at 8192x8192", 8192, 1, Size{Width: 8192, Height: 8192}},
|
||||||
{"64x8192", 64, 8192},
|
{"8192x1 at 1x8192", 8192, 1, Size{Width: 1, Height: 8192}},
|
||||||
{"1x8192", 1, 8192},
|
{"64x8192 at 8192x8192", 64, 8192, Size{Width: 8192, Height: 8192}},
|
||||||
|
{"1x8192 at 8192x8192", 1, 8192, Size{Width: 8192, Height: 8192}},
|
||||||
|
{"1x8192 at 8192x1", 1, 8192, Size{Width: 8192, Height: 1}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@@ -33,14 +37,7 @@ func TestImageProcessor_FitCoverServesThinSource(t *testing.T) {
|
|||||||
|
|
||||||
result, err := New(Params{}).Process(t.Context(),
|
result, err := New(Params{}).Process(t.Context(),
|
||||||
bytes.NewReader(input),
|
bytes.NewReader(input),
|
||||||
&Request{
|
&Request{Size: tt.size, Format: FormatJPEG, FitMode: FitCover})
|
||||||
Size: Size{
|
|
||||||
Width: MaxOutputDimension,
|
|
||||||
Height: MaxOutputDimension,
|
|
||||||
},
|
|
||||||
Format: FormatJPEG,
|
|
||||||
FitMode: FitCover,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Process() error = %v", err)
|
t.Fatalf("Process() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -49,11 +46,9 @@ func TestImageProcessor_FitCoverServesThinSource(t *testing.T) {
|
|||||||
|
|
||||||
t.Logf("Process() made %dx%d", result.Width, result.Height)
|
t.Logf("Process() made %dx%d", result.Width, result.Height)
|
||||||
|
|
||||||
if result.Width != MaxOutputDimension ||
|
if result.Width != tt.size.Width || result.Height != tt.size.Height {
|
||||||
result.Height != MaxOutputDimension {
|
|
||||||
t.Errorf("Process() made %dx%d, want %dx%d",
|
t.Errorf("Process() made %dx%d, want %dx%d",
|
||||||
result.Width, result.Height,
|
result.Width, result.Height, tt.size.Width, tt.size.Height)
|
||||||
MaxOutputDimension, MaxOutputDimension)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user