Last active
April 15, 2021 09:03
-
-
Save johantiden/a9ec7bc4dfeb9ebc23260d6c0a159317 to your computer and use it in GitHub Desktop.
Showcase of reading a Photoshop liquify .msh file
This file contains 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
public static void main(String[] args) throws IOException { | |
byte[] bytes = Files.readAllBytes(new File("distortedmesh.msh").toPath()); | |
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); | |
byteBuffer.position(64); | |
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); | |
int HEIGHT = 8; | |
int WIDTH = 8; | |
for (int row = 0; row < HEIGHT; row++) { | |
System.out.println("row " + row); | |
boolean nextIsEmpties = true; | |
int sumRead = 0; | |
while (sumRead < WIDTH) { | |
if (nextIsEmpties) { | |
int numEmpties = byteBuffer.getInt(); | |
System.out.println(numEmpties + " empties"); | |
sumRead += numEmpties; | |
} else { | |
int nums = byteBuffer.getInt(); | |
System.out.println(nums + " non empty"); | |
for (int i = 0; i < nums; i++) { | |
int x = sumRead + i; | |
float dx = byteBuffer.getFloat(); | |
float dy = byteBuffer.getFloat(); | |
System.out.println("* x:" + x + " dx:" + dx +", dy:"+ dy); | |
} | |
sumRead += nums; | |
} | |
nextIsEmpties = !nextIsEmpties; | |
} | |
System.out.println("end of row"); | |
System.out.println(""); | |
System.out.println(""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: