Ignore layout bound markers during patch calculation

Change-Id: I0ae90c2867e2599a71ddf11f83352db4868deca2
diff --git a/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java b/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java
index 8b92655..9efcdda 100644
--- a/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java
+++ b/draw9patch/src/main/java/com/android/draw9patch/ui/PatchInfo.java
@@ -172,15 +172,20 @@
 
     private static P getPatches(int[] pixels) {
         int lastIndex = 1;
-        int lastPixel = pixels[1];
+        int lastPixel;
         boolean first = true;
         boolean startWithPatch = false;
 
         List<Pair<Integer>> fixed = new ArrayList<Pair<Integer>>();
         List<Pair<Integer>> patches = new ArrayList<Pair<Integer>>();
 
+        // ignore layout bound markers for the purpose of patch calculation
+        lastPixel = pixels[1] != PatchInfo.RED_TICK ? pixels[1] : 0;
+
         for (int i = 1; i < pixels.length - 1; i++) {
-            int pixel = pixels[i];
+            // ignore layout bound markers for the purpose of patch calculation
+            int pixel = pixels[i] != PatchInfo.RED_TICK ? pixels[i] : 0;
+
             if (pixel != lastPixel) {
                 if (lastPixel == BLACK_TICK) {
                     if (first) startWithPatch = true;
diff --git a/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java b/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java
index 7ca4fdd..7350b82 100644
--- a/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java
+++ b/draw9patch/src/test/java/com/android/draw9patch/ui/PatchInfoTest.java
@@ -32,7 +32,13 @@
         for (int row = 0; row < h; row++) {
             for (int col = 0; col < w; col++) {
                 char c = data[row].charAt(col);
-                image.setRGB(col, row, c == '*' ? PatchInfo.BLACK_TICK : 0);
+                int color = 0;
+                if (c == '*') {
+                    color = PatchInfo.BLACK_TICK;
+                } else if (c == 'R') {
+                    color = PatchInfo.RED_TICK;
+                }
+                image.setRGB(col, row, color);
             }
         }
         return image;
@@ -101,4 +107,23 @@
         assertEquals(2, pi.verticalPadding.first.intValue());
         assertEquals(0, pi.verticalPadding.second.intValue());
     }
+
+    // make sure that the presence of layout bound markers doesn't affect patch/padding info
+    public void testIgnoreLayoutBoundMarkers() {
+        BufferedImage image = createImage(new String[] {
+                "0RR3**6789",
+                "R........R",
+                "*.........",
+                "*........*",
+                "4........*",
+                "5***456R89",
+        });
+        PatchInfo pi = new PatchInfo(image);
+
+        assertFalse(pi.horizontalStartWithPatch);
+
+        assertEquals(1, pi.patches.size());
+        assertEquals(2, pi.verticalPatches.size());
+        assertEquals(2, pi.horizontalPatches.size());
+    }
 }