| 1 | package png2svg |
| 2 | |
| 3 | import ( |
| 4 | "image/color" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestRainforestPixelColorMatch(t *testing.T) { |
| 9 | const filename = "img/rainforest.png" |
| 10 | const targetX, targetY = 10, 1 |
| 11 | |
| 12 | // Read the image |
| 13 | img, err := ReadPNG(filename, false) |
| 14 | if err != nil { |
| 15 | t.Fatalf("Failed to read PNG file: %v", err) |
| 16 | } |
| 17 | |
| 18 | // Initialize PixelImage |
| 19 | pixelImage := NewPixelImage(img, false) |
| 20 | |
| 21 | // Get the original pixel color directly from the image |
| 22 | originalColor := color.NRGBAModel.Convert(img.At(targetX, targetY)).(color.NRGBA) |
| 23 | |
| 24 | // Get the pixel at (10, 1) from PixelImage |
| 25 | pixel := pixelImage.pixels[targetY*pixelImage.w+targetX] |
| 26 | |
| 27 | // Check if the color of the pixel matches the original image's pixel color |
| 28 | if pixel.r != int(originalColor.R) || pixel.g != int(originalColor.G) || pixel.b != int(originalColor.B) { |
| 29 | t.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.r, pixel.g, pixel.b, originalColor.R, originalColor.G, originalColor.B) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestRainforestPixelColorSpecific(t *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 := ReadPNG(filename, false) |
| 41 | if err != nil { |
| 42 | t.Fatalf("Failed to read PNG file: %v", err) |
| 43 | } |
| 44 | |
| 45 | // Initialize PixelImage |
| 46 | pixelImage := NewPixelImage(img, false) |
| 47 | |
| 48 | // Get the pixel at (10, 1) |
| 49 | pixel := pixelImage.pixels[targetY*pixelImage.w+targetX] |
| 50 | |
| 51 | // Check if the color of the pixel matches the expected values |
| 52 | if pixel.r != expectedRed || pixel.g != expectedGreen || pixel.b != expectedBlue { |
| 53 | t.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.r, pixel.g, pixel.b, expectedRed, expectedGreen, expectedBlue) |
| 55 | } |
| 56 | } |