OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [image/] [ycbcr_test.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package image_test
6
 
7
import (
8
        . "image"
9
        "image/color"
10
        "testing"
11
)
12
 
13
func TestYCbCr(t *testing.T) {
14
        rects := []Rectangle{
15
                Rect(0, 0, 16, 16),
16
                Rect(1, 0, 16, 16),
17
                Rect(0, 1, 16, 16),
18
                Rect(1, 1, 16, 16),
19
                Rect(1, 1, 15, 16),
20
                Rect(1, 1, 16, 15),
21
                Rect(1, 1, 15, 15),
22
                Rect(2, 3, 14, 15),
23
                Rect(7, 0, 7, 16),
24
                Rect(0, 8, 16, 8),
25
                Rect(0, 0, 10, 11),
26
                Rect(5, 6, 16, 16),
27
                Rect(7, 7, 8, 8),
28
                Rect(7, 8, 8, 9),
29
                Rect(8, 7, 9, 8),
30
                Rect(8, 8, 9, 9),
31
                Rect(7, 7, 17, 17),
32
                Rect(8, 8, 17, 17),
33
                Rect(9, 9, 17, 17),
34
                Rect(10, 10, 17, 17),
35
        }
36
        subsampleRatios := []YCbCrSubsampleRatio{
37
                YCbCrSubsampleRatio444,
38
                YCbCrSubsampleRatio422,
39
                YCbCrSubsampleRatio420,
40
        }
41
        deltas := []Point{
42
                Pt(0, 0),
43
                Pt(1000, 1001),
44
                Pt(5001, -400),
45
                Pt(-701, -801),
46
        }
47
        for _, r := range rects {
48
                for _, subsampleRatio := range subsampleRatios {
49
                        for _, delta := range deltas {
50
                                testYCbCr(t, r, subsampleRatio, delta)
51
                        }
52
                }
53
        }
54
}
55
 
56
func testYCbCr(t *testing.T, r Rectangle, subsampleRatio YCbCrSubsampleRatio, delta Point) {
57
        // Create a YCbCr image m, whose bounds are r translated by (delta.X, delta.Y).
58
        r1 := r.Add(delta)
59
        m := NewYCbCr(r1, subsampleRatio)
60
 
61
        // Test that the image buffer is reasonably small even if (delta.X, delta.Y) is far from the origin.
62
        if len(m.Y) > 100*100 {
63
                t.Errorf("r=%v, subsampleRatio=%v, delta=%v: image buffer is too large",
64
                        r, subsampleRatio, delta)
65
                return
66
        }
67
 
68
        // Initialize m's pixels. For 422 and 420 subsampling, some of the Cb and Cr elements
69
        // will be set multiple times. That's OK. We just want to avoid a uniform image.
70
        for y := r1.Min.Y; y < r1.Max.Y; y++ {
71
                for x := r1.Min.X; x < r1.Max.X; x++ {
72
                        yi := m.YOffset(x, y)
73
                        ci := m.COffset(x, y)
74
                        m.Y[yi] = uint8(16*y + x)
75
                        m.Cb[ci] = uint8(y + 16*x)
76
                        m.Cr[ci] = uint8(y + 16*x)
77
                }
78
        }
79
 
80
        // Make various sub-images of m.
81
        for y0 := delta.Y + 3; y0 < delta.Y+7; y0++ {
82
                for y1 := delta.Y + 8; y1 < delta.Y+13; y1++ {
83
                        for x0 := delta.X + 3; x0 < delta.X+7; x0++ {
84
                                for x1 := delta.X + 8; x1 < delta.X+13; x1++ {
85
                                        subRect := Rect(x0, y0, x1, y1)
86
                                        sub := m.SubImage(subRect).(*YCbCr)
87
 
88
                                        // For each point in the sub-image's bounds, check that m.At(x, y) equals sub.At(x, y).
89
                                        for y := sub.Rect.Min.Y; y < sub.Rect.Max.Y; y++ {
90
                                                for x := sub.Rect.Min.X; x < sub.Rect.Max.X; x++ {
91
                                                        color0 := m.At(x, y).(color.YCbCr)
92
                                                        color1 := sub.At(x, y).(color.YCbCr)
93
                                                        if color0 != color1 {
94
                                                                t.Errorf("r=%v, subsampleRatio=%v, delta=%v, x=%d, y=%d, color0=%v, color1=%v",
95
                                                                        r, subsampleRatio, delta, x, y, color0, color1)
96
                                                                return
97
                                                        }
98
                                                }
99
                                        }
100
                                }
101
                        }
102
                }
103
        }
104
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.