docs: public static void main(final String[] pArgs) throws IOException {
          int subsampleFactor = 1;
          Rectangle sourceRegion = null;
          boolean readLayers = false;
          boolean readThumbnails = false;
  
          int idx = 0;
          while (pArgs[idx].charAt(0) == '-') {
              if (pArgs[idx].equals("-s") || pArgs[idx].equals("--subsampling")) {
                  subsampleFactor = Integer.parseInt(pArgs[++idx]);
              }
              else if (pArgs[idx].equals("-r") || pArgs[idx].equals("--sourceregion")) {
                  int xw = Integer.parseInt(pArgs[++idx]);
                  int yh = Integer.parseInt(pArgs[++idx]);
  
                  try {
                      int w = Integer.parseInt(pArgs[idx + 1]);
                      int h = Integer.parseInt(pArgs[idx + 2]);
  
                      idx += 2;
  
                      // x y w h
                      sourceRegion = new Rectangle(xw, yh, w, h);
                  }
                  catch (NumberFormatException e) {
                      // w h
                      sourceRegion = new Rectangle(xw, yh);
                  }
  
                  System.out.println("sourceRegion: " + sourceRegion);
              }
              else if (pArgs[idx].equals("-l") || pArgs[idx].equals("--layers")) {
                  readLayers = true;
              }
              else if (pArgs[idx].equals("-t") || pArgs[idx].equals("--thumbnails")) {
                  readThumbnails = true;
              }
              else {
                  System.err.println("Usage: java PSDImageReader [-s <subsample factor>] [-r [<x y>] <w h>] <image file>");
                  System.exit(1);
              }
  
              idx++;
          }
  
          PSDImageReader imageReader = new PSDImageReader(null);
  
          for (; idx < pArgs.length; idx++) {
              File file = new File(pArgs[idx]);
              System.out.println();
              System.out.println("file: " + file.getAbsolutePath());
  
              ImageInputStream stream = ImageIO.createImageInputStream(file);
              imageReader.setInput(stream);
              imageReader.readHeader();
              System.out.println("imageReader.header: " + imageReader.header);
  
              imageReader.readImageResources(true);
              System.out.println("imageReader.imageResources: " + imageReader.metadata.imageResources);
              System.out.println();
  
              imageReader.readLayerAndMaskInfo(true);
              System.out.println("imageReader.layerInfo: " + imageReader.metadata.layerInfo);
  /*
      //        System.out.println("imageReader.globalLayerMask: " + imageReader.globalLayerMask);
              System.out.println();
  
              IIOMetadata metadata = imageReader.getImageMetadata(0);
              Node node;
              XMLSerializer serializer;
  
              node = metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
              serializer = new XMLSerializer(System.out, System.getProperty("file.encoding"));
              serializer.serialize(node, true);
              System.out.println();
  
              node = metadata.getAsTree(PSDMetadata.NATIVE_METADATA_FORMAT_NAME);
      //        serializer = new XMLSerializer(System.out, System.getProperty("file.encoding"));
              serializer.serialize(node, true);
  */
              if (readThumbnails && imageReader.hasThumbnails(0)) {
                  int thumbnails = imageReader.getNumThumbnails(0);
                  for (int i = 0; i < thumbnails; i++) {
                      showIt(imageReader.readThumbnail(0, i), String.format("Thumbnail %d", i));
                  }
              }
  
              long start = System.currentTimeMillis();
  
              ImageReadParam param = imageReader.getDefaultReadParam();
  
              if (sourceRegion != null) {
                  param.setSourceRegion(sourceRegion);
              }
  
              if (subsampleFactor > 1) {
                  param.setSourceSubsampling(subsampleFactor, subsampleFactor, 0, 0);
              }
  
              //        param.setDestinationType(imageReader.getRawImageType(0));
  
              BufferedImage image = imageReader.read(0, param);
              System.out.println("read time: " + (System.currentTimeMillis() - start));
              System.out.println("image: " + image);
  
              if (image.getType() == BufferedImage.TYPE_CUSTOM) {
                  try {
                      ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_sRGB), null);
                      GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
                      image = op.filter(image, gc.createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency()));
                  }
                  catch (Exception e) {
                      e.printStackTrace();
                      image = ImageUtil.accelerate(image);
                  }
                  System.out.println("conversion time: " + (System.currentTimeMillis() - start));
                  System.out.println("image: " + image);
              }
  
              showIt(image, file.getName());
  
              if (readLayers) {
                  int images = imageReader.getNumImages(true);
                  for (int i = 1; i < images; i++) {
                      start = System.currentTimeMillis();
                      BufferedImage layer = imageReader.read(i);
  
                      System.out.println("layer read time: " + (System.currentTimeMillis() - start));
                      System.err.println("layer: " + layer);
  
                      if (layer != null && layer.getType() == BufferedImage.TYPE_CUSTOM) {
                          try {
                              ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_sRGB), null);
                              GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
                              layer = op.filter(layer, gc.createCompatibleImage(layer.getWidth(), layer.getHeight(), layer.getTransparency()));
                          }
                          catch (Exception e) {
                              e.printStackTrace();
                              layer = ImageUtil.accelerate(layer);
                          }
                          System.out.println("layer conversion time: " + (System.currentTimeMillis() - start));
                          System.out.println("layer: " + layer);
                      }
  
                      showIt(layer, "layer " + i);
                  }
              }
          }
      }