Skip to content

Commit

Permalink
pixels: clamp functions optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
disintegration committed Apr 1, 2017
1 parent d3ddfc5 commit 70f330c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pixels.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func convertPalette(p []color.Color) []pixel {
}

func getPaletteIndex(pal []pixel, px pixel) int {
var k int = 0
var k int
var dmin float32 = 4
for i, palpx := range pal {
d := px.R - palpx.R
Expand Down Expand Up @@ -287,21 +287,25 @@ func (p *pixelGetter) getPixelColumn(x int, buf *[]pixel) {
}

func f32u8(val float32) uint8 {
if val > 255.0 {
val = 255.0
} else if val < 0.0 {
val = 0.0
x := int64(val + 0.5)
if x > 255 {
return 255
}
return uint8(val + 0.5)
if x > 0 {
return uint8(x)
}
return 0
}

func f32u16(val float32) uint16 {
if val > 65535.0 {
val = 65535.0
} else if val < 0.0 {
val = 0.0
x := int64(val + 0.5)
if x > 65535 {
return 65535
}
if x > 0 {
return uint16(x)
}
return uint16(val + 0.5)
return 0
}

type pixelSetter struct {
Expand Down

0 comments on commit 70f330c

Please sign in to comment.