Skip to content

Commit

Permalink
Merge branch 'phhusson-fix-grayalpha-9patch'
Browse files Browse the repository at this point in the history
  • Loading branch information
iBotPeaches committed May 25, 2017
2 parents 6597da9 + a00da34 commit 6e47d36
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Expand Up @@ -20,6 +20,8 @@
import brut.androlib.err.CantFind9PatchChunk;
import brut.util.ExtDataInput;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.*;
import javax.imageio.ImageIO;
import javax.imageio.ImageTypeSpecifier;
Expand All @@ -39,8 +41,24 @@ public void decode(InputStream in, OutputStream out)
BufferedImage im = ImageIO.read(new ByteArrayInputStream(data));
int w = im.getWidth(), h = im.getHeight();

BufferedImage im2 = new BufferedImage(w+2, h+2, BufferedImage.TYPE_INT_ARGB);
im2.createGraphics().drawImage(im, 1, 1, w, h, null);
BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB);
if (im.getType() == BufferedImage.TYPE_CUSTOM) {
//TODO: Ensure this is gray + alpha case?
Raster srcRaster = im.getRaster();
WritableRaster dstRaster = im2.getRaster();
int[] gray = null, alpha = null;
for (int y = 0; y < im.getHeight(); y++) {
gray = srcRaster.getSamples(0, y, w, 1, 0, gray);
alpha = srcRaster.getSamples(0, y, w, 1, 1, alpha);

dstRaster.setSamples(1, y + 1, w, 1, 0, gray);
dstRaster.setSamples(1, y + 1, w, 1, 1, gray);
dstRaster.setSamples(1, y + 1, w, 1, 2, gray);
dstRaster.setSamples(1, y + 1, w, 1, 3, alpha);
}
} else {
im2.createGraphics().drawImage(im, 1, 1, w, h, null);
}

NinePatch np = getNinePatch(data);
drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight);
Expand Down
Expand Up @@ -350,6 +350,27 @@ public void ninePatchImageColorTest() throws BrutException, IOException {
assertEquals(controlImage.getRGB(30, 30), testImage.getRGB(30, 30));
}

@Test
public void issue1508Test() throws BrutException, IOException {
char slash = File.separatorChar;
String location = slash + "res" + slash + "drawable-xhdpi" + slash;

File control = new File((sTestOrigDir + location), "btn_zoom_up_normal.9.png");
File test = new File((sTestNewDir + location), "btn_zoom_up_normal.9.png");

BufferedImage controlImage = ImageIO.read(control);
BufferedImage testImage = ImageIO.read(test);

// 0, 0 = clear
assertEquals(controlImage.getRGB(0, 0), testImage.getRGB(0, 0));

// 30, 0 = black line
assertEquals(controlImage.getRGB(0, 30), testImage.getRGB(0, 30));

// 30, 30 = greyish button
assertEquals(controlImage.getRGB(30, 30), testImage.getRGB(30, 30));
}

@Test
public void drawableXxhdpiTest() throws BrutException, IOException {
compareResFolder("drawable-xxhdpi");
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6e47d36

Please sign in to comment.