groovy.com.robotics.api.FastScreenshot.java Source code

Java tutorial

Introduction

Here is the source code for groovy.com.robotics.api.FastScreenshot.java

Source

/*
 * MIT License
 *
 * Copyright (c) [2017] [Jasmin Patel]
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package groovy.com.robotics.api;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;

/**
 * @author vVv.AA
 *         <p>
 *         Created on 17/5/17.
 */
@Deprecated
public class FastScreenshot {

    /**
     * Take screenshots and store them a directory.
     * Directory path should NOT be a multi level path.
     * @param directory Directory to store screenshots in.
     * @param n_shots Number of screenshots to take.
     * @param n_threads Number of threads to use.
     * @param delay_us Delay before first screenshot is taken.
     * @param interval_us Delay between screenshots.
     */
    public static void takeScreenshots(String directory, int n_shots, int n_threads, int delay_us,
            int interval_us) {
        _takeScreenshots(StringUtils.stripEnd(StringUtils.stripStart(directory, "/"), "/"), n_shots,
                Math.min(n_threads, n_shots), delay_us, interval_us);
    }

    /**
     * Take screenshots and store them a directory.
     * Uses default directory.
     * @param n_shots Number of screenshots to take.
     * @param n_threads Number of threads to use.
     * @param delay_us Delay before first screenshot is taken.
     * @param interval_us Delay between screenshots.
     */
    public static void takeScreenshots(int n_shots, int n_threads, int delay_us, int interval_us) {
        takeScreenshots(getDefaultDirectoryPath(), n_shots, n_threads, delay_us, interval_us);
    }

    private static native void _takeScreenshots(String directory, int n_shots, int n_threads, int delay_us,
            int interval_us);

    static {
        if (SystemUtils.IS_OS_LINUX) {
            // Dynamically linked. Need to change to static link.
            System.loadLibrary("boost_system");
            System.loadLibrary("boost_thread");
            System.load(System.getenv("PWD") + "/lib/libFastScreenshot.so");
        } else if (SystemUtils.IS_OS_MAC) {
            System.load(System.getenv("PWD") + "/lib/libFastScreenshot.dylib");
        } else
            System.load(System.getenv("PWD") + "/lib/libFastScreenshot.dll");
    }

    public static String getDefaultDirectoryPath() {
        return "testScreenshots";
    }

}