Debian Codegraph @

planar_yuv_luminance_source.go

raw symbols SCIP
1 package gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/
2
3 import (
4 errorsscip-go gomod golang.org/x/xerrors 5ec99f83aff1 `golang.org/x/xerrors`/ "golang.org/x/xerrorsscip-go gomod golang.org/x/xerrors 5ec99f83aff1 `golang.org/x/xerrors`/"
5 )
6
7 const thumbnailScaleFactorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/thumbnailScaleFactor. = 2
8
9 type PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource# struct {
10 LuminanceSourceBasescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#LuminanceSourceBase.
11 yuvDatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#yuvData. []byte
12 dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth. int
13 dataHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataHeight. int
14 leftscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#left. int
15 topscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#top. int
16 }
17
18 func NewPlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewPlanarYUVLuminanceSource().(yuvData []byte,
19 dataWidth, dataHeight, left, top, width, height int,
20 reverseHorizontal bool) (LuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSource#, error) {
21
22 if left+width > dataWidth || top+height > dataHeight {
23 return nil, errorsscip-go gomod golang.org/x/xerrors 5ec99f83aff1 `golang.org/x/xerrors`/.Newscip-go gomod golang.org/x/xerrors 5ec99f83aff1 `golang.org/x/xerrors`/New().("IllegalArgumentException: Crop rectangle does not fit within image data")
24 }
25
26 yuvsrc := &PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#{
27 LuminanceSourceBasescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSourceBase#{width, height},
28 yuvData,
29 dataWidth,
30 dataHeight,
31 left,
32 top,
33 }
34 if reverseHorizontal {
35 yuvsrc.reverseHorizontalscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#reverseHorizontal().(width, height)
36 }
37 return yuvsrc, nil
38 }
39
40 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) Invertscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#Invert().() LuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSource# {
41 return LuminanceSourceInvertscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSourceInvert().(this)
42 }
43
44 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) Stringscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#String().() string {
45 return LuminanceSourceStringscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSourceString().(this)
46 }
47
48 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) GetRowscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#GetRow().(y int, row []byte) ([]byte, error) {
49 if y < 0 || y >= this.GetHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSourceBase#GetHeight().() {
50 return nil, errorsscip-go gomod golang.org/x/xerrors 5ec99f83aff1 `golang.org/x/xerrors`/.Errorfscip-go gomod golang.org/x/xerrors 5ec99f83aff1 `golang.org/x/xerrors`/Errorf().("IllegalArgumentException: Requested row is outside the image: %v", y)
51 }
52 width := this.GetWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSourceBase#GetWidth().()
53 if row == nil || len(row) < width {
54 row = make([]byte, width)
55 }
56 offset := (y+this.topscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#top.)*this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth. + this.leftscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#left.
57 copy(row, this.yuvDatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#yuvData.[offset:offset+width])
58 return row, nil
59 }
60
61 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) GetMatrixscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#GetMatrix().() []byte {
62 width := this.GetWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSourceBase#GetWidth().()
63 height := this.GetHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSourceBase#GetHeight().()
64
65 // If the caller asks for the entire underlying image, save the copy and give them the
66 // original data. The docs specifically warn that result.length must be ignored.
67 if width == this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth. && height == this.dataHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataHeight. {
68 return this.yuvDatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#yuvData.
69 }
70
71 area := width * height
72 matrix := make([]byte, area)
73 inputOffset := this.topscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#top.*this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth. + this.leftscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#left.
74
75 // If the width matches the full width of the underlying data, perform a single copy.
76 if width == this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth. {
77 copy(matrix, this.yuvDatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#yuvData.[inputOffset:inputOffset+area])
78 return matrix
79 }
80
81 // Otherwise copy one cropped row at a time.
82 for y := 0; y < height; y++ {
83 outputOffset := y * width
84 copy(matrix[outputOffset:], this.yuvDatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#yuvData.[inputOffset:inputOffset+width])
85 inputOffset += this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth.
86 }
87 return matrix
88 }
89
90 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) IsCropSupportedscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#IsCropSupported().() bool {
91 return true
92 }
93
94 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) Cropscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#Crop().(left, top, width, height int) (LuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSource#, error) {
95 return NewPlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewPlanarYUVLuminanceSource().(
96 this.yuvDatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#yuvData.,
97 this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth.,
98 this.dataHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataHeight.,
99 this.leftscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#left.+left,
100 this.topscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#top.+top,
101 width,
102 height,
103 false)
104 }
105
106 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) RenderThumbnailscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#RenderThumbnail().() []uint {
107 width := this.GetThumbnailWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#GetThumbnailWidth().()
108 height := this.GetThumbnailHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#GetThumbnailHeight().()
109 pixels := make([]uint, width*height)
110 yuv := this.yuvDatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#yuvData.
111 inputOffset := this.topscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#top.*this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth. + this.leftscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#left.
112
113 for y := 0; y < height; y++ {
114 outputOffset := y * width
115 for x := 0; x < width; x++ {
116 grey := uint(yuv[inputOffset+x*thumbnailScaleFactorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/thumbnailScaleFactor.]) & 0xff
117 pixels[outputOffset+x] = 0xFF000000 | (grey * 0x00010101)
118 }
119 inputOffset += this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth. * thumbnailScaleFactorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/thumbnailScaleFactor.
120 }
121 return pixels
122 }
123
124 // GetThumbnailWidth return width of image from {@link #renderThumbnail()}
125 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) GetThumbnailWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#GetThumbnailWidth().() int {
126 return this.GetWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSourceBase#GetWidth().() / thumbnailScaleFactorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/thumbnailScaleFactor.
127 }
128
129 // GetThumbnailHeight return height of image from {@link #renderThumbnail()}
130 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) GetThumbnailHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#GetThumbnailHeight().() int {
131 return this.GetHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/LuminanceSourceBase#GetHeight().() / thumbnailScaleFactorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/thumbnailScaleFactor.
132 }
133
134 func (this *PlanarYUVLuminanceSourcescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#) reverseHorizontalscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#reverseHorizontal().(width, height int) {
135 yuvData := this.yuvDatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#yuvData.
136 for y, rowStart := 0, this.topscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#top.*this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth.+this.leftscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#left.; y < height; y, rowStart = y+1, rowStart+this.dataWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/PlanarYUVLuminanceSource#dataWidth. {
137 middle := rowStart + width/2
138 for x1, x2 := rowStart, rowStart+width-1; x1 < middle; x1, x2 = x1+1, x2-1 {
139 yuvData[x1], yuvData[x2] = yuvData[x2], yuvData[x1]
140 }
141 }
142 }