| 1 | package png2svgscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/ |
| 2 | |
| 3 | import ( |
| 4 | "image/colorscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.25.1 testing/" |
| 6 | ) |
| 7 | |
| 8 | func TestRainforestPixelColorMatchscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/TestRainforestPixelColorMatch().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 9 | const filename = "img/rainforest.png" |
| 10 | const targetX, targetY = 10, 1 |
| 11 | |
| 12 | // Read the image |
| 13 | img, err := ReadPNGscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/ReadPNG().(filename, false) |
| 14 | if err != nil { |
| 15 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("Failed to read PNG file: %v", err) |
| 16 | } |
| 17 | |
| 18 | // Initialize PixelImage |
| 19 | pixelImage := NewPixelImagescip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/NewPixelImage().(img, false) |
| 20 | |
| 21 | // Get the original pixel color directly from the image |
| 22 | originalColor := colorscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/.NRGBAModelscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/NRGBAModel..Convertscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/Model#Convert().(img.Atscip-go gomod github.com/golang/go/src go1.25.1 image/Image#At().(targetX, targetY)).(colorscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/.NRGBAscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/NRGBA#) |
| 23 | |
| 24 | // Get the pixel at (10, 1) from PixelImage |
| 25 | pixel := pixelImage.pixelsscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/PixelImage#pixels.[targetY*pixelImage.wscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/PixelImage#w.+targetX] |
| 26 | |
| 27 | // Check if the color of the pixel matches the original image's pixel color |
| 28 | if pixel.rscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#r. != int(originalColor.Rscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/NRGBA#R.) || pixel.gscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#g. != int(originalColor.Gscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/NRGBA#G.) || pixel.bscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#b. != int(originalColor.Bscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/NRGBA#B.) { |
| 29 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Pixel at (%d,%d) has incorrect color: got (R: %d, G: %d, B: %d), want (R: %d, G: %d, B: %d)", |
| 30 | targetX, targetY, pixel.rscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#r., pixel.gscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#g., pixel.bscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#b., originalColor.Rscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/NRGBA#R., originalColor.Gscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/NRGBA#G., originalColor.Bscip-go gomod github.com/golang/go/src go1.25.1 `image/color`/NRGBA#B.) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestRainforestPixelColorSpecificscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/TestRainforestPixelColorSpecific().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 35 | const filename = "img/rainforest.png" |
| 36 | const targetX, targetY = 10, 1 |
| 37 | const expectedRed, expectedGreen, expectedBlue = 0x0c, 0, 0 // Assuming the pixel should be #0c0000 |
| 38 | |
| 39 | // Read the image |
| 40 | img, err := ReadPNGscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/ReadPNG().(filename, false) |
| 41 | if err != nil { |
| 42 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("Failed to read PNG file: %v", err) |
| 43 | } |
| 44 | |
| 45 | // Initialize PixelImage |
| 46 | pixelImage := NewPixelImagescip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/NewPixelImage().(img, false) |
| 47 | |
| 48 | // Get the pixel at (10, 1) |
| 49 | pixel := pixelImage.pixelsscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/PixelImage#pixels.[targetY*pixelImage.wscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/PixelImage#w.+targetX] |
| 50 | |
| 51 | // Check if the color of the pixel matches the expected values |
| 52 | if pixel.rscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#r. != expectedRed || pixel.gscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#g. != expectedGreen || pixel.bscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#b. != expectedBlue { |
| 53 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Pixel at (%d,%d) has incorrect color: got (R: %d, G: %d, B: %d), want (R: %d, G: %d, B: %d)", |
| 54 | targetX, targetY, pixel.rscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#r., pixel.gscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#g., pixel.bscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/Pixel#b., expectedRed, expectedGreen, expectedBlue) |
| 55 | } |
| 56 | } |