Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1630)

Delta Between Two Patch Sets: draw/scale.go

Issue 101670045: code review 101670045: go.image/draw: new package, a superset of the standard ...
Left Patch Set: diff -r e492ffa4cad4 https://code.google.com/p/go.image Created 9 years, 8 months ago
Right Patch Set: diff -r e492ffa4cad4 https://code.google.com/p/go.image Created 9 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « draw/draw.go ('k') | draw/scale_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2014 The Go Authors. All rights reserved. 1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package draw 5 package draw
6 6
7 import ( 7 import (
8 "image" 8 "image"
9 "image/color" 9 "image/color"
10 "math" 10 "math"
11 ) 11 )
12 12
13 // Quality is a desired resampling quality, ranging from the fastest 13 // Quality is a desired resampling quality, ranging from the fastest
14 // computation (lowest quality) to the slowest computation (highest quality). 14 // computation (lowest quality) to the slowest computation (highest quality).
15 type Quality int 15 type Quality int
16 16
17 const ( 17 const (
18 FastestQuality Quality = -1 18 FastestQuality Quality = -1
19 DefaultQuality Quality = 0 19 DefaultQuality Quality = 0
20 NicestQuality Quality = +1 20 NicestQuality Quality = +1
r 2014/07/08 19:44:54 not sure i like these names. they don't convey rea
21 ) 21 )
22 22
23 // Scale scales the part of the source image defined by src and sr and writes 23 // Scale scales the part of the source image defined by src and sr and writes
24 // to the part of the destination image defined by dst and dr. 24 // to the part of the destination image defined by dst and dr.
25 func Scale(dst Image, dr image.Rectangle, src image.Image, sr image.Rectangle, q Quality) { 25 func Scale(dst Image, dr image.Rectangle, src image.Image, sr image.Rectangle, q Quality) {
26 NewScaler(dr.Size(), sr.Size(), q).Scale(dst, dr.Min, src, sr.Min) 26 NewScaler(dr.Size(), sr.Size(), q).Scale(dst, dr.Min, src, sr.Min)
27 } 27 }
28 28
29 // Scaler scales part of a source image, starting from sp, and writes to a 29 // Scaler scales part of a source image, starting from sp, and writes to a
30 // destination image, starting from dp. The destination and source width and 30 // destination image, starting from dp. The destination and source width and
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 183 }
184 184
185 func (z *nicestScaler) Scale(dst Image, dp image.Point, src image.Image, sp imag e.Point) { 185 func (z *nicestScaler) Scale(dst Image, dp image.Point, src image.Image, sp imag e.Point) {
186 // TODO: is it worth having a sync.Pool for this temporary buffer? 186 // TODO: is it worth having a sync.Pool for this temporary buffer?
187 tmp := make([][4]float64, z.dw*z.sh) 187 tmp := make([][4]float64, z.dw*z.sh)
188 z.scaleX(tmp, src, sp) 188 z.scaleX(tmp, src, sp)
189 z.scaleY(dst, dp, tmp) 189 z.scaleY(dst, dp, tmp)
190 } 190 }
191 191
192 // source is a range of contribs, their inverse total weight, and that ITW 192 // source is a range of contribs, their inverse total weight, and that ITW
193 // multiplied by 0xffff. 193 // divided by 0xffff.
194 type source struct { 194 type source struct {
195 i, j int32 195 i, j int32
196 invTotalWeight float64 196 invTotalWeight float64
197 invTotalWeightFFFF float64 197 invTotalWeightFFFF float64
198 } 198 }
199 199
200 // contrib is the weight of a column or row. 200 // contrib is the weight of a column or row.
201 type contrib struct { 201 type contrib struct {
202 coord int32 202 coord int32
203 weight float64 203 weight float64
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 342
343 func ftou(f float64) uint16 { 343 func ftou(f float64) uint16 {
344 i := int32(0xffff*f + 0.5) 344 i := int32(0xffff*f + 0.5)
345 if i > 0xffff { 345 if i > 0xffff {
346 return 0xffff 346 return 0xffff
347 } else if i > 0 { 347 } else if i > 0 {
348 return uint16(i) 348 return uint16(i)
349 } 349 }
350 return 0 350 return 0
351 } 351 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b