Example #1
0
 @Override
 public Format setInputFormat(Format format) {
   final VideoFormat videoFormat = (VideoFormat) format;
   if (videoFormat.getSize() == null) return null; // must set a size.
   // TODO: check VideoFormat and compatibility
   return super.setInputFormat(format);
 }
Example #2
0
  @Override
  public Format[] getSupportedOutputFormats(Format input) {
    if (input == null) return supportedOutputFormats;

    final VideoFormat inputCast = (VideoFormat) input;
    final Format[] result =
        new Format[] {
          new RGBFormat(
              inputCast.getSize(), -1, Format.byteArray, inputCast.getFrameRate(), -1, -1, -1, -1)
        };
    // TODO: we don't know the details of the output format (pixel masks,
    // etc) until we actually parse one!

    return result;
  }
Example #3
0
 @Override
 protected void copy(Format f) {
   super.copy(f);
   final GIFFormat oCast = (GIFFormat) f; // it has to be a GIFFormat, or
   // ClassCastException will be
   // thrown.
 }
Example #4
0
  /**
   * Read screen.
   *
   * @param output output buffer for screen bytes
   * @param dim dimension of the screen
   * @return raw bytes, it could be equal to output or not. Take care in the caller to check if
   *     output is the returned value.
   */
  public byte[] readScreen(byte[] output, Dimension dim) {
    VideoFormat format = (VideoFormat) getFormat();
    Dimension formatSize = format.getSize();
    int width = formatSize.width;
    int height = formatSize.height;
    BufferedImage scaledScreen = null;
    BufferedImage screen = null;
    byte data[] = null;
    int size = width * height * 4;

    // If output is not large enough, enlarge it.
    if ((output == null) || (output.length < size)) output = new byte[size];

    /* get desktop screen via native grabber if available */
    if (desktopInteract.captureScreen(displayIndex, x, y, dim.width, dim.height, output)) {
      return output;
    }

    System.out.println("failed to grab with native! " + output.length);

    /* OK native grabber failed or is not available,
     * try with AWT Robot and convert it to the right format
     *
     * Note that it is very memory consuming since memory are allocated
     * to capture screen (via Robot) and then for converting to raw bytes
     * Moreover support for multiple display has not yet been investigated
     *
     * Normally not of our supported platform (Windows (x86, x64),
     * Linux (x86, x86-64), Mac OS X (i386, x86-64, ppc) and
     * FreeBSD (x86, x86-64) should go here.
     */
    screen = desktopInteract.captureScreen();

    if (screen != null) {
      /* convert to ARGB BufferedImage */
      scaledScreen =
          ImgStreamingUtils.getScaledImage(screen, width, height, BufferedImage.TYPE_INT_ARGB);
      /* get raw bytes */
      data = ImgStreamingUtils.getImageBytes(scaledScreen, output);
    }

    screen = null;
    scaledScreen = null;
    return data;
  }