Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. private void uncompress(QTNode node, int size, Coordinate start) {
  2. // TODO
  3. int dim = (int)Math.sqrt(size);
  4. int endRow = dim+start.getRow();
  5. int endCol = dim+start.getCol();
  6. if(node.getVal() != QUAD_SPLIT) {
  7. for(int row = start.getRow(); row < endRow; row++) {
  8. for(int col = start.getCol(); col < endCol; col++) {
  9. image[row][col] = node.getVal();
  10. }
  11. }
  12. } else {
  13. uncompress(node.getUpperLeft(), size/4, start);
  14. uncompress(node.getUpperRight(), size/4, new Coordinate(start.getRow(), endCol-(dim/2)));
  15. uncompress(node.getLowerLeft(), size/4, new Coordinate(endRow-(dim/2), start.getCol()));
  16. uncompress(node.getLowerRight(), size/4, new Coordinate(endRow-(dim/2), endCol-(dim/2)));
  17. }
  18.  
  19. }
  20.  
  21. /**
  22. * Uncompress a RIT compressed file. This is the public facing routine
  23. * meant to be used by a client to uncompress an image for displaying.
  24. *
  25. * The file is expected to be 2^n x 2^n pixels. The first line in
  26. * the file is its size (number of values). The remaining lines are
  27. * the values in the compressed image, one per line, of "size" lines.
  28. *
  29. * Once this routine completes, the raw image of grayscale values (0-255)
  30. * is stored internally and can be retrieved by the client using getImage().
  31. *
  32. * @param filename the name of the compressed file
  33. * @throws IOException if there are issues working with the compressed file
  34. * @throws QTException if there are issues parsing the data in the file
  35. */
  36. public void uncompress(String filename) throws IOException, QTException {
  37.  
  38. File file = new File(filename);
  39. BufferedReader in = new BufferedReader(new FileReader(file));
  40. List<Integer> fileLines = new ArrayList<>();
  41. String line = in.readLine();
  42. while(line != null) {
  43. fileLines.add(Integer.parseInt(line));
  44. line = in.readLine();
  45. }
  46. rawSize = fileLines.remove(0);
  47. root = parse(fileLines);
  48. DIM = (int)Math.sqrt(rawSize);
  49. image = new int[DIM][DIM];
  50.  
  51. uncompress(root, rawSize, new Coordinate(0, 0));
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement