1 Star 0 Fork 1

铜豌豆 Linux/png2svg

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pixelimage_test.go 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
atzlinux 提交于 2024-06-12 22:18 +08:00 . New upstream version 1.6.0
package png2svg
import (
"image/color"
"testing"
)
func TestRainforestPixelColorMatch(t *testing.T) {
const filename = "img/rainforest.png"
const targetX, targetY = 10, 1
// Read the image
img, err := ReadPNG(filename, false)
if err != nil {
t.Fatalf("Failed to read PNG file: %v", err)
}
// Initialize PixelImage
pixelImage := NewPixelImage(img, false)
// Get the original pixel color directly from the image
originalColor := color.NRGBAModel.Convert(img.At(targetX, targetY)).(color.NRGBA)
// Get the pixel at (10, 1) from PixelImage
pixel := pixelImage.pixels[targetY*pixelImage.w+targetX]
// Check if the color of the pixel matches the original image's pixel color
if pixel.r != int(originalColor.R) || pixel.g != int(originalColor.G) || pixel.b != int(originalColor.B) {
t.Errorf("Pixel at (%d,%d) has incorrect color: got (R: %d, G: %d, B: %d), want (R: %d, G: %d, B: %d)",
targetX, targetY, pixel.r, pixel.g, pixel.b, originalColor.R, originalColor.G, originalColor.B)
}
}
func TestRainforestPixelColorSpecific(t *testing.T) {
const filename = "img/rainforest.png"
const targetX, targetY = 10, 1
const expectedRed, expectedGreen, expectedBlue = 0x0c, 0, 0 // Assuming the pixel should be #0c0000
// Read the image
img, err := ReadPNG(filename, false)
if err != nil {
t.Fatalf("Failed to read PNG file: %v", err)
}
// Initialize PixelImage
pixelImage := NewPixelImage(img, false)
// Get the pixel at (10, 1)
pixel := pixelImage.pixels[targetY*pixelImage.w+targetX]
// Check if the color of the pixel matches the expected values
if pixel.r != expectedRed || pixel.g != expectedGreen || pixel.b != expectedBlue {
t.Errorf("Pixel at (%d,%d) has incorrect color: got (R: %d, G: %d, B: %d), want (R: %d, G: %d, B: %d)",
targetX, targetY, pixel.r, pixel.g, pixel.b, expectedRed, expectedGreen, expectedBlue)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/atzlinux/png2svg.git
git@gitee.com:atzlinux/png2svg.git
atzlinux
png2svg
png2svg
debian/latest

搜索帮助