Test a GIF with an out of range transparent index

Bug: skia:8461

According to skbug.com/7069, we should allow GIFs to use a transparent
index outside of the range of the color table. Add a test to verify
support for this.

The GIF is 2x2 with the following pixels:
-------------------------------------------------
|   black            |          white           |
-------------------------------------------------
|   transparent      |      transparent         |
-------------------------------------------------

The color table only has 2 entries (black and white), and the
transparent index is 2.

Change-Id: I16574a61e2982b6628c3eca96cb7b3e1f57d3b2a
Reviewed-on: https://skia-review.googlesource.com/c/161561
Reviewed-by: Nigel Tao <nigeltao@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Auto-Submit: Leon Scroggins <scroggo@google.com>
diff --git a/resources/images/out-of-palette.gif b/resources/images/out-of-palette.gif
new file mode 100644
index 0000000..20f71cd
--- /dev/null
+++ b/resources/images/out-of-palette.gif
Binary files differ
diff --git a/tests/GifTest.cpp b/tests/GifTest.cpp
index 0de5fc5..fc61ffc 100644
--- a/tests/GifTest.cpp
+++ b/tests/GifTest.cpp
@@ -281,3 +281,45 @@
     // too early.
     REPORTER_ASSERT(r, codec->getFrameCount() == 0);
 }
+
+DEF_TEST(Codec_gif_out_of_palette, r) {
+    if (GetResourcePath().isEmpty()) {
+        return;
+    }
+
+    const char* path = "images/out-of-palette.gif";
+    auto data = GetResourceAsData(path);
+    if (!data) {
+        ERRORF(r, "failed to find %s", path);
+        return;
+    }
+
+    auto codec = SkCodec::MakeFromData(std::move(data));
+    if (!codec) {
+        ERRORF(r, "Could not create codec from %s", path);
+        return;
+    }
+
+    SkBitmap bm;
+    bm.allocPixels(codec->getInfo());
+    auto result = codec->getPixels(bm.pixmap());
+    REPORTER_ASSERT(r, result == SkCodec::kSuccess, "Failed to decode %s with error %s",
+                    path, SkCodec::ResultToString(result));
+
+    struct {
+        int     x;
+        int     y;
+        SkColor expected;
+    } pixels[] = {
+        { 0, 0, SK_ColorBLACK },
+        { 1, 0, SK_ColorWHITE },
+        { 0, 1, SK_ColorTRANSPARENT },
+        { 1, 1, SK_ColorTRANSPARENT },
+    };
+    for (auto& pixel : pixels) {
+        auto actual = bm.getColor(pixel.x, pixel.y);
+        REPORTER_ASSERT(r, actual == pixel.expected,
+                        "pixel (%i,%i) mismatch! expected: %x actual: %x",
+                        pixel.x, pixel.y, pixel.expected, actual);
+    }
+}