~shabbyrobe/grugdct

98379b08f4df88d5db84e3af79d5a519f3da4654 — Blake Williams 1 year, 7 months ago 2eb1519
Faster clamp
5 files changed, 10 insertions(+), 35 deletions(-)

M basic_8x8.go
M basic_std.go
M cachedcos_8x8.go
M cachedcos_8x8_faster.go
M cachedcos_std.go
M basic_8x8.go => basic_8x8.go +2 -7
@@ 87,17 87,12 @@ func (bas Basic8x8) IDCT8x8Into(mat *Matrix8x8F32, xpos int, ypos int, into Imag
			}

			z /= scale
			if z > 255.0 {
				z = 255.0
			}
			if z < 0 {
				z = 0.0
			}

			xp, yp := xpos+x, ypos+y
			if xp < into.W && yp < into.H {
				// Round, then convert to int and clamp to [0, ff]
				// It's inaccurate without the round. 255.5 will truncate to 255, not wrap.
				into.Pix[yp*into.W+xp] = uint8(z + 0.5)
				into.Pix[yp*into.W+xp] = uint8((int(z+0.5) & 0xff))
			}
		}
	}

M basic_std.go => basic_std.go +2 -7
@@ 99,17 99,12 @@ func (bas Basic) IDCTInto(mat MatrixF64, xpos int, ypos int, into Image) {
			}

			z /= bas.idctScale
			if z > 255.0 {
				z = 255.0
			}
			if z < 0 {
				z = 0.0
			}

			xp, yp := xpos+x, ypos+y
			if xp < into.W && yp < into.H {
				// Round, then convert to int and clamp to [0, ff]
				// It's inaccurate without the round. 255.5 will truncate to 255, not wrap.
				into.Pix[yp*into.W+xp] = uint8(z + 0.5)
				into.Pix[yp*into.W+xp] = uint8((int(z+0.5) & 0xff))
			}
		}
	}

M cachedcos_8x8.go => cachedcos_8x8.go +2 -7
@@ 85,17 85,12 @@ func (cos CachedCosines8x8) IDCT8x8Into(mat *Matrix8x8F32, xpos int, ypos int, i
			}

			z /= scale
			if z > 255.0 {
				z = 255.0
			}
			if z < 0 {
				z = 0.0
			}

			xp, yp := xpos+x, ypos+y
			if xp < into.W && yp < into.H {
				// Round, then convert to int and clamp to [0, ff]
				// It's inaccurate without the round. 255.5 will truncate to 255, not wrap.
				into.Pix[yp*into.W+xp] = uint8(z + 0.5)
				into.Pix[yp*into.W+xp] = uint8((int(z+0.5) & 0xff))
			}
		}
	}

M cachedcos_8x8_faster.go => cachedcos_8x8_faster.go +2 -7
@@ 86,17 86,12 @@ func (cos CachedCosines8x8Faster) IDCT8x8Into(mat *Matrix8x8F32, xpos int, ypos 
		}

		z /= scale
		if z > 255.0 {
			z = 255.0
		}
		if z < 0 {
			z = 0.0
		}

		xp, yp := xpos+x, ypos+y
		if xp < into.W && yp < into.H {
			// Round, then convert to int and clamp to [0, ff]
			// It's inaccurate without the round. 255.5 will truncate to 255, not wrap.
			into.Pix[yp*into.W+xp] = uint8(z + 0.5)
			into.Pix[yp*into.W+xp] = uint8((int(z+0.5) & 0xff))
		}
	}
}

M cachedcos_std.go => cachedcos_std.go +2 -7
@@ 125,17 125,12 @@ func (dct CachedCosines) IDCTInto(mat MatrixF64, xpos int, ypos int, into Image)
			}

			z /= dct.idctScale
			if z > 255.0 {
				z = 255.0
			}
			if z < 0 {
				z = 0.0
			}

			xp, yp := xpos+x, ypos+y
			if xp < into.W && yp < into.H {
				// Round, then convert to int and clamp to [0, ff]
				// It's inaccurate without the round. 255.5 will truncate to 255, not wrap.
				into.Pix[yp*into.W+xp] = uint8(z + 0.5)
				into.Pix[yp*into.W+xp] = uint8((int(z+0.5) & 0xff))
			}
		}
	}