Created
October 10, 2016 20:28
-
-
Save lite1979/cdda9842248413bd690189a8461a543e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void appendStarSlices(ByteArrayBuilder builder) { | |
/* Loop through and convert format */ | |
int widthBytes = (int)((getWidth() + 7) / 8); | |
int heightBytes = (int)((getHeight() + 7) / 8); | |
int x = 0; | |
int y = 0; | |
int bit = 0; | |
int byteVal = 0; | |
boolean[] imgData = getImageAsBooleanArray(); | |
StringBuilder b = new StringBuilder(); | |
for (int i = 0; i < widthBytes * getHeight(); i++) | |
b.append(new char[0]); | |
while(true) { | |
byteVal |= (imgData[y * getWidth() + x] ? 1 : 0) << 7 - bit; | |
x++; | |
bit++; | |
if (x >= getWidth()) { | |
x = 0; | |
y++; | |
bit = 8; | |
if (y > getHeight()) { | |
builder.append(new byte[] { (byte)byteVal } ); | |
break; | |
} | |
} | |
if (bit >= 8) { | |
builder.append(new byte[] { (byte)byteVal } ); | |
byteVal = 0; | |
bit = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment