Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void uncompress(QTNode node, int size, Coordinate start) {
- // TODO
- int dim = (int)Math.sqrt(size);
- int endRow = dim+start.getRow();
- int endCol = dim+start.getCol();
- if(node.getVal() != QUAD_SPLIT) {
- for(int row = start.getRow(); row < endRow; row++) {
- for(int col = start.getCol(); col < endCol; col++) {
- image[row][col] = node.getVal();
- }
- }
- } else {
- uncompress(node.getUpperLeft(), size/4, start);
- uncompress(node.getUpperRight(), size/4, new Coordinate(start.getRow(), endCol-(dim/2)));
- uncompress(node.getLowerLeft(), size/4, new Coordinate(endRow-(dim/2), start.getCol()));
- uncompress(node.getLowerRight(), size/4, new Coordinate(endRow-(dim/2), endCol-(dim/2)));
- }
- }
- /**
- * Uncompress a RIT compressed file. This is the public facing routine
- * meant to be used by a client to uncompress an image for displaying.
- *
- * The file is expected to be 2^n x 2^n pixels. The first line in
- * the file is its size (number of values). The remaining lines are
- * the values in the compressed image, one per line, of "size" lines.
- *
- * Once this routine completes, the raw image of grayscale values (0-255)
- * is stored internally and can be retrieved by the client using getImage().
- *
- * @param filename the name of the compressed file
- * @throws IOException if there are issues working with the compressed file
- * @throws QTException if there are issues parsing the data in the file
- */
- public void uncompress(String filename) throws IOException, QTException {
- File file = new File(filename);
- BufferedReader in = new BufferedReader(new FileReader(file));
- List<Integer> fileLines = new ArrayList<>();
- String line = in.readLine();
- while(line != null) {
- fileLines.add(Integer.parseInt(line));
- line = in.readLine();
- }
- rawSize = fileLines.remove(0);
- root = parse(fileLines);
- DIM = (int)Math.sqrt(rawSize);
- image = new int[DIM][DIM];
- uncompress(root, rawSize, new Coordinate(0, 0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement