diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java index f59b45a0..f1f12fd0 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java @@ -32,15 +32,14 @@ /** * Webcam class. It wraps webcam device obtained from webcam driver. - * + * * @author Bartosz Firyn (bfiryn) */ public class Webcam { /** - * Class used to asynchronously notify all webcam listeners about new image - * available. - * + * Class used to asynchronously notify all webcam listeners about new image available. + * * @author Bartosz Firyn (sarxos) */ private static final class ImageNotification implements Runnable { @@ -57,7 +56,7 @@ private static final class ImageNotification implements Runnable { /** * Create new notification. - * + * * @param webcam the webcam from which image has been acquired * @param image the acquired image */ @@ -183,8 +182,8 @@ public Thread newThread(Runnable r) { private volatile WebcamImageTransformer transformer = null; /** - * Lock which denies access to the given webcam when it's already in use by - * other webcam capture API process or thread. + * Lock which denies access to the given webcam when it's already in use by other webcam capture + * API process or thread. */ private WebcamLock lock = null; @@ -195,7 +194,7 @@ public Thread newThread(Runnable r) { /** * Webcam class. - * + * * @param device - device to be used as webcam * @throws IllegalArgumentException when device argument is null */ @@ -208,8 +207,8 @@ protected Webcam(WebcamDevice device) { } /** - * Asynchronously start new thread which will notify all webcam listeners - * about the new image available. + * Asynchronously start new thread which will notify all webcam listeners about the new image + * available. */ protected void notifyWebcamImageAcquired(BufferedImage image) { @@ -224,34 +223,34 @@ protected void notifyWebcamImageAcquired(BufferedImage image) { /** * Open the webcam in blocking (synchronous) mode. - * + * + * @return True if webcam has been open, false otherwise * @see #open(boolean) + * @throws WebcamException when something went wrong */ public boolean open() { return open(false); } /** - * Open the webcam in either blocking (synchronous) or non-blocking - * (asynchronous) mode.The difference between those two modes lies in the - * image acquisition mechanism.
+ * Open the webcam in either blocking (synchronous) or non-blocking (asynchronous) mode.The + * difference between those two modes lies in the image acquisition mechanism.
*
- * In blocking mode, when user calls {@link #getImage()} method, device is - * being queried for new image buffer and user have to wait for it to be - * available.
+ * In blocking mode, when user calls {@link #getImage()} method, device is being queried for new + * image buffer and user have to wait for it to be available.
*
- * In non-blocking mode, there is a special thread running in the background - * which constantly fetch new images and cache them internally for further - * use. This cached instance is returned every time when user request new - * image. Because of that it can be used when timeing is very important, - * because all users calls for new image do not have to wait on device - * response. By using this mode user should be aware of the fact that in - * some cases, when two consecutive calls to get new image are executed more - * often than webcam device can serve them, the same image instance will be - * returned. User should use {@link #isImageNew()} method to distinguish if - * returned image is not the same as the previous one. - * + * In non-blocking mode, there is a special thread running in the background which constantly + * fetch new images and cache them internally for further use. This cached instance is returned + * every time when user request new image. Because of that it can be used when timeing is very + * important, because all users calls for new image do not have to wait on device response. By + * using this mode user should be aware of the fact that in some cases, when two consecutive + * calls to get new image are executed more often than webcam device can serve them, the same + * image instance will be returned. User should use {@link #isImageNew()} method to distinguish + * if returned image is not the same as the previous one. + * * @param async true for non-blocking mode, false for blocking + * @return True if webcam has been open + * @throws WebcamException when something went wrong */ public boolean open(boolean async) { @@ -321,6 +320,8 @@ public boolean open(boolean async) { /** * Close the webcam. + * + * @return True if webcam has been open, false otherwise */ public boolean close() { @@ -389,10 +390,10 @@ public boolean close() { } /** - * Return underlying webcam device. Depending on the driver used to discover - * devices, this method can return instances of different class. By default - * {@link WebcamDefaultDevice} is returned when no external driver is used. - * + * Return underlying webcam device. Depending on the driver used to discover devices, this + * method can return instances of different class. By default {@link WebcamDefaultDevice} is + * returned when no external driver is used. + * * @return Underlying webcam device instance */ public WebcamDevice getDevice() { @@ -401,8 +402,8 @@ public WebcamDevice getDevice() { } /** - * Completely dispose capture device. After this operation webcam cannot be - * used any more and full reinstantiation is required. + * Completely dispose capture device. After this operation webcam cannot be used any more and + * full reinstantiation is required. */ protected void dispose() { @@ -462,10 +463,9 @@ private void removeShutdownHook() { } /** - * TRansform image using image transformer. If image transformer has not - * been set, this method return instance passed in the argument, without any - * modifications. - * + * TRansform image using image transformer. If image transformer has not been set, this method + * return instance passed in the argument, without any modifications. + * * @param image the image to be transformed * @return Transformed image (if transformer is set) */ @@ -481,7 +481,7 @@ protected BufferedImage transform(BufferedImage image) { /** * Is webcam open? - * + * * @return true if open, false otherwise */ public boolean isOpen() { @@ -490,7 +490,7 @@ public boolean isOpen() { /** * Get current webcam resolution in pixels. - * + * * @return Webcam resolution (picture size) in pixels. */ public Dimension getViewSize() { @@ -498,9 +498,8 @@ public Dimension getViewSize() { } /** - * Return list of supported view sizes. It can differ between vary webcam - * data sources. - * + * Return list of supported view sizes. It can differ between vary webcam data sources. + * * @return Array of supported dimensions */ public Dimension[] getViewSizes() { @@ -508,9 +507,9 @@ public Dimension[] getViewSizes() { } /** - * Set custom resolution. If you are using this method you have to make sure - * that your webcam device can support this specific resolution. - * + * Set custom resolution. If you are using this method you have to make sure that your webcam + * device can support this specific resolution. + * * @param sizes the array of custom resolutions to be supported by webcam */ public void setCustomViewSizes(Dimension[] sizes) { @@ -528,9 +527,9 @@ public Dimension[] getCustomViewSizes() { } /** - * Set new view size. New size has to exactly the same as one of the default - * sized or exactly the same as one of the custom ones. - * + * Set new view size. New size has to exactly the same as one of the default sized or exactly + * the same as one of the custom ones. + * * @param size the new view size to be set * @see Webcam#setCustomViewSizes(Dimension[]) * @see Webcam#getViewSizes() @@ -595,20 +594,18 @@ public void setViewSize(Dimension size) { } /** - * Capture image from webcam and return it. Will return image object or null - * if webcam is closed or has been already disposed by JVM.
+ * Capture image from webcam and return it. Will return image object or null if webcam is closed + * or has been already disposed by JVM.
*
* IMPORTANT NOTE!!!
*
- * There are two possible behaviors of what webcam should do when you try to - * get image and webcam is actually closed. Normally it will return null, - * but there is a special flag which can be statically set to switch all - * webcams to auto open mode. In this mode, webcam will be automatically - * open, when you try to get image from closed webcam. Please be aware of - * some side effects! In case of multi-threaded applications, there is no - * guarantee that one thread will not try to open webcam even if it was - * manually closed in different thread. - * + * There are two possible behaviors of what webcam should do when you try to get image and + * webcam is actually closed. Normally it will return null, but there is a special flag which + * can be statically set to switch all webcams to auto open mode. In this mode, webcam will be + * automatically open, when you try to get image from closed webcam. Please be aware of some + * side effects! In case of multi-threaded applications, there is no guarantee that one thread + * will not try to open webcam even if it was manually closed in different thread. + * * @return Captured image or null if webcam is closed or disposed by JVM */ public BufferedImage getImage() { @@ -667,17 +664,14 @@ public double getFPS() { } /** - * Get RAW image ByteBuffer. It will always return buffer with 3 x 1 bytes - * per each pixel, where RGB components are on (0, 1, 2) and color space is - * sRGB.
+ * Get RAW image ByteBuffer. It will always return buffer with 3 x 1 bytes per each pixel, where + * RGB components are on (0, 1, 2) and color space is sRGB.
*
- * * IMPORTANT!
- * Some drivers can return direct ByteBuffer, so there is no guarantee that - * underlying bytes will not be released in next read image operation. - * Therefore, to avoid potential bugs you should convert this ByteBuffer to - * bytes array before you fetch next image. - * + * Some drivers can return direct ByteBuffer, so there is no guarantee that underlying bytes + * will not be released in next read image operation. Therefore, to avoid potential bugs you + * should convert this ByteBuffer to bytes array before you fetch next image. + * * @return Byte buffer */ public ByteBuffer getImageBytes() { @@ -701,18 +695,15 @@ public ByteBuffer getImageBytes() { } /** - * Get RAW image ByteBuffer. It will always return buffer with 3 x 1 bytes - * per each pixel, where RGB components are on (0, 1, 2) and color space is - * sRGB.
+ * Get RAW image ByteBuffer. It will always return buffer with 3 x 1 bytes per each pixel, where + * RGB components are on (0, 1, 2) and color space is sRGB.
*
- * * IMPORTANT!
- * Some drivers can return direct ByteBuffer, so there is no guarantee that - * underlying bytes will not be released in next read image operation. - * Therefore, to avoid potential bugs you should convert this ByteBuffer to - * bytes array before you fetch next image. - * - * @return Byte buffer + * Some drivers can return direct ByteBuffer, so there is no guarantee that underlying bytes + * will not be released in next read image operation. Therefore, to avoid potential bugs you + * should convert this ByteBuffer to bytes array before you fetch next image. + * + * @param target the target {@link ByteBuffer} object to copy data into */ public void getImageBytes(ByteBuffer target) { @@ -736,7 +727,7 @@ public void getImageBytes(ByteBuffer target) { /** * Is webcam ready to be read. - * + * * @return True if ready, false otherwise */ private boolean isReady() { @@ -761,10 +752,9 @@ private boolean isReady() { } /** - * Get list of webcams to use. This method will wait predefined time - * interval for webcam devices to be discovered. By default this time is set - * to 1 minute. - * + * Get list of webcams to use. This method will wait predefined time interval for webcam devices + * to be discovered. By default this time is set to 1 minute. + * * @return List of webcams existing in the system * @throws WebcamException when something is wrong * @see Webcam#getWebcams(long, TimeUnit) @@ -782,11 +772,12 @@ public static List getWebcams() throws WebcamException { } /** - * Get list of webcams to use. This method will wait given time interval for - * webcam devices to be discovered. Time argument is given in milliseconds. - * + * Get list of webcams to use. This method will wait given time interval for webcam devices to + * be discovered. Time argument is given in milliseconds. + * * @param timeout the time to wait for webcam devices to be discovered * @return List of webcams existing in the ssytem + * @throws TimeoutException when timeout occurs * @throws WebcamException when something is wrong * @throws IllegalArgumentException when timeout is negative * @see Webcam#getWebcams(long, TimeUnit) @@ -799,9 +790,9 @@ public static List getWebcams(long timeout) throws TimeoutException, Web } /** - * Get list of webcams to use. This method will wait given time interval for - * webcam devices to be discovered. - * + * Get list of webcams to use. This method will wait given time interval for webcam devices to + * be discovered. + * * @param timeout the devices discovery timeout * @param tunit the time unit * @return List of webcams @@ -832,7 +823,7 @@ public static synchronized List getWebcams(long timeout, TimeUnit tunit) /** * Will discover and return first webcam available in the system. - * + * * @return Default webcam (first from the list) * @throws WebcamException if something is really wrong * @see Webcam#getWebcams() @@ -850,7 +841,7 @@ public static Webcam getDefault() throws WebcamException { /** * Will discover and return first webcam available in the system. - * + * * @param timeout the webcam discovery timeout (1 minute by default) * @return Default webcam (first from the list) * @throws TimeoutException when discovery timeout has been exceeded @@ -867,7 +858,7 @@ public static Webcam getDefault(long timeout) throws TimeoutException, WebcamExc /** * Will discover and return first webcam available in the system. - * + * * @param timeout the webcam discovery timeout (1 minute by default) * @param tunit the time unit * @return Default webcam (first from the list) @@ -899,10 +890,10 @@ public static Webcam getDefault(long timeout, TimeUnit tunit) throws TimeoutExce } /** - * Get webcam name (device name). The name of device depends on the value - * returned by the underlying data source, so in some cases it can be - * human-readable value and sometimes it can be some strange number. - * + * Get webcam name (device name). The name of device depends on the value returned by the + * underlying data source, so in some cases it can be human-readable value and sometimes it can + * be some strange number. + * * @return Name */ public String getName() { @@ -917,8 +908,9 @@ public String toString() { /** * Add webcam listener. - * + * * @param l the listener to be added + * @return True if listener has been added, false if it was already there * @throws IllegalArgumentException when argument is null */ public boolean addWebcamListener(WebcamListener l) { @@ -947,7 +939,7 @@ public int getWebcamListenersCount() { /** * Removes webcam listener. - * + * * @param l the listener to be removed * @return True if listener has been removed, false otherwise */ @@ -960,7 +952,7 @@ public boolean removeWebcamListener(WebcamListener l) { * Return webcam driver. Perform search if necessary.
*
* This method is not thread-safe! - * + * * @return Webcam driver */ public static synchronized WebcamDriver getDriver() { @@ -985,7 +977,7 @@ public static synchronized WebcamDriver getDriver() { * Set new video driver to be used by webcam.
*
* This method is not thread-safe! - * + * * @param wd new webcam driver to be used (e.g. LtiCivil, JFM, FMJ, QTJ) * @throws IllegalArgumentException when argument is null */ @@ -1003,12 +995,12 @@ public static void setDriver(WebcamDriver wd) { } /** - * Set new video driver class to be used by webcam. Class given in the - * argument shall extend {@link WebcamDriver} interface and should have - * public default constructor, so instance can be created by reflection.
+ * Set new video driver class to be used by webcam. Class given in the argument shall extend + * {@link WebcamDriver} interface and should have public default constructor, so instance can be + * created by reflection.
*
* This method is not thread-safe! - * + * * @param driverClass new video driver class to use * @throws IllegalArgumentException when argument is null */ @@ -1050,7 +1042,7 @@ public static void resetDriver() { /** * Register new webcam video driver. - * + * * @param clazz webcam video driver class * @throws IllegalArgumentException when argument is null */ @@ -1064,7 +1056,7 @@ public static void registerDriver(Class clazz) { /** * Register new webcam video driver. - * + * * @param clazzName webcam video driver class name * @throws IllegalArgumentException when argument is null */ @@ -1078,12 +1070,11 @@ public static void registerDriver(String clazzName) { /** * CAUTION!!!
*
- * This is experimental feature to be used mostly in in development phase. - * After you set handle term signal to true, and fetch capture devices, - * Webcam Capture API will listen for TERM signal and try to close all - * devices after it has been received. This feature can be unstable on - * some systems! - * + * This is experimental feature to be used mostly in in development phase. After you set handle + * term signal to true, and fetch capture devices, Webcam Capture API will listen for TERM + * signal and try to close all devices after it has been received. This feature can be + * unstable on some systems! + * * @param on signal handling will be enabled if true, disabled otherwise */ public static void setHandleTermSignal(boolean on) { @@ -1095,7 +1086,7 @@ public static void setHandleTermSignal(boolean on) { /** * Is TERM signal handler enabled. - * + * * @return True if enabled, false otherwise */ public static boolean isHandleTermSignal() { @@ -1103,13 +1094,12 @@ public static boolean isHandleTermSignal() { } /** - * Switch all webcams to auto open mode. In this mode, each webcam will be - * automatically open whenever user will try to get image from instance - * which has not yet been open. Please be aware of some side effects! In - * case of multi-threaded applications, there is no guarantee that one - * thread will not try to open webcam even if it was manually closed in - * different thread. - * + * Switch all webcams to auto open mode. In this mode, each webcam will be automatically open + * whenever user will try to get image from instance which has not yet been open. Please be + * aware of some side effects! In case of multi-threaded applications, there is no guarantee + * that one thread will not try to open webcam even if it was manually closed in different + * thread. + * * @param on true to enable, false to disable */ public static void setAutoOpenMode(boolean on) { @@ -1117,13 +1107,11 @@ public static void setAutoOpenMode(boolean on) { } /** - * Is auto open mode enabled. Auto open mode will will automatically open - * webcam whenever user will try to get image from instance which has not - * yet been open. Please be aware of some side effects! In case of - * multi-threaded applications, there is no guarantee that one thread will - * not try to open webcam even if it was manually closed in different - * thread. - * + * Is auto open mode enabled. Auto open mode will will automatically open webcam whenever user + * will try to get image from instance which has not yet been open. Please be aware of some side + * effects! In case of multi-threaded applications, there is no guarantee that one thread will + * not try to open webcam even if it was manually closed in different thread. + * * @return True if mode is enabled, false otherwise */ public static boolean isAutoOpenMode() { @@ -1132,7 +1120,7 @@ public static boolean isAutoOpenMode() { /** * Add new webcam discovery listener. - * + * * @param l the listener to be added * @return True, if listeners list size has been changed, false otherwise * @throws IllegalArgumentException when argument is null @@ -1150,7 +1138,7 @@ public static WebcamDiscoveryListener[] getDiscoveryListeners() { /** * Remove discovery listener - * + * * @param l the listener to be removed * @return True if listeners list contained the specified element */ @@ -1160,7 +1148,7 @@ public static boolean removeDiscoveryListener(WebcamDiscoveryListener l) { /** * Return discovery service. - * + * * @return Discovery service */ public static synchronized WebcamDiscoveryService getDiscoveryService() { @@ -1172,7 +1160,7 @@ public static synchronized WebcamDiscoveryService getDiscoveryService() { /** * Return discovery service without creating it if not exists. - * + * * @return Discovery service or null if not yet created */ public static synchronized WebcamDiscoveryService getDiscoveryServiceRef() { @@ -1181,7 +1169,7 @@ public static synchronized WebcamDiscoveryService getDiscoveryServiceRef() { /** * Return image transformer. - * + * * @return Transformer instance */ public WebcamImageTransformer getImageTransformer() { @@ -1190,7 +1178,7 @@ public WebcamImageTransformer getImageTransformer() { /** * Set image transformer. - * + * * @param transformer the transformer to be set */ public void setImageTransformer(WebcamImageTransformer transformer) { @@ -1199,7 +1187,7 @@ public void setImageTransformer(WebcamImageTransformer transformer) { /** * Return webcam lock. - * + * * @return Webcam lock */ public WebcamLock getLock() { diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamMotionDetector.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamMotionDetector.java index f8367458..71473a18 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamMotionDetector.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamMotionDetector.java @@ -19,7 +19,7 @@ /** * Webcam motion detector. - * + * * @author Bartosz Firyn (SarXos) */ public class WebcamMotionDetector { @@ -56,7 +56,7 @@ public class WebcamMotionDetector { /** * Create new threads for detector internals. - * + * * @author Bartosz Firyn (SarXos) */ private static final class DetectorThreadFactory implements ThreadFactory { @@ -72,7 +72,7 @@ public Thread newThread(Runnable runnable) { /** * Run motion detector. - * + * * @author Bartosz Firyn (SarXos) */ private class Runner implements Runnable { @@ -99,7 +99,7 @@ public void run() { /** * Change motion to false after specified number of seconds. - * + * * @author Bartosz Firyn (SarXos) */ private class Inverter implements Runnable { @@ -203,11 +203,10 @@ public void run() { /** * Create motion detector. Will open webcam if it is closed. - * + * * @param webcam web camera instance * @param pixelThreshold intensity threshold (0 - 255) * @param areaThreshold percentage threshold of image covered by motion - * @param inertia for how long motion is valid (seconds) * @param interval the check interval */ public WebcamMotionDetector(Webcam webcam, int pixelThreshold, double areaThreshold, int interval) { @@ -226,10 +225,10 @@ public WebcamMotionDetector(Webcam webcam, int pixelThreshold, double areaThresh /** * Create motion detector with default parameter inertia = 0. - * + * * @param webcam web camera instance * @param pixelThreshold intensity threshold (0 - 255) - * @param areaThreshol percentage threshold of image covered by motion + * @param areaThreshold percentage threshold of image covered by motion (0 - 100) */ public WebcamMotionDetector(Webcam webcam, int pixelThreshold, double areaThreshold) { this(webcam, pixelThreshold, areaThreshold, DEFAULT_INTERVAL); @@ -237,7 +236,7 @@ public WebcamMotionDetector(Webcam webcam, int pixelThreshold, double areaThresh /** * Create motion detector with default parameter inertia = 0. - * + * * @param webcam web camera instance * @param pixelThreshold intensity threshold (0 - 255) */ @@ -246,9 +245,8 @@ public WebcamMotionDetector(Webcam webcam, int pixelThreshold) { } /** - * Create motion detector with default parameters - threshold = 25, inertia - * = 0. - * + * Create motion detector with default parameters - threshold = 25, inertia = 0. + * * @param webcam web camera instance */ public WebcamMotionDetector(Webcam webcam) { @@ -346,7 +344,7 @@ private void notifyMotionListeners() { /** * Add motion listener. - * + * * @param l listener to add * @return true if listeners list has been changed, false otherwise */ @@ -363,7 +361,7 @@ public WebcamMotionListener[] getMotionListeners() { /** * Removes motion listener. - * + * * @param l motion listener to remove * @return true if listener was available on the list, false otherwise */ @@ -379,9 +377,9 @@ public int getInterval() { } /** - * Motion check interval in milliseconds. After motion is detected, it's - * valid for time which is equal to value of 2 * interval. - * + * Motion check interval in milliseconds. After motion is detected, it's valid for time which is + * equal to value of 2 * interval. + * * @param interval the new motion check interval (ms) * @see #DEFAULT_INTERVAL */ @@ -395,10 +393,10 @@ public void setInterval(int interval) { } /** - * Set pixel intensity difference threshold above which pixel is classified - * as "moved". Minimum value is 0 and maximum is 255. Default value is 10. - * This value is equal for all RGB components difference. - * + * Set pixel intensity difference threshold above which pixel is classified as "moved". Minimum + * value is 0 and maximum is 255. Default value is 10. This value is equal for all RGB + * components difference. + * * @param threshold the pixel intensity difference threshold * @see #DEFAULT_PIXEL_THREASHOLD */ @@ -413,10 +411,10 @@ public void setPixelThreshold(int threshold) { } /** - * Set percentage fraction of detected motion area threshold above which it - * is classified as "moved". Minimum value for this is 0 and maximum is 100, - * which corresponds to full image covered by spontaneous motion. - * + * Set percentage fraction of detected motion area threshold above which it is classified as + * "moved". Minimum value for this is 0 and maximum is 100, which corresponds to full image + * covered by spontaneous motion. + * * @param threshold the percentage fraction of image area * @see #DEFAULT_AREA_THREASHOLD */ @@ -431,10 +429,9 @@ public void setAreaThreshold(double threshold) { } /** - * Set motion inertia (time when motion is valid). If no value specified - * this is set to 2 * interval. To reset to default value, - * {@link #clearInertia()} method must be used. - * + * Set motion inertia (time when motion is valid). If no value specified this is set to 2 * + * interval. To reset to default value, {@link #clearInertia()} method must be used. + * * @param inertia the motion inertia time in milliseconds * @see #clearInertia() */ @@ -446,8 +443,8 @@ public void setInertia(int inertia) { } /** - * Reset inertia time to value calculated automatically on the base of - * interval. This value will be set to 2 * interval. + * Reset inertia time to value calculated automatically on the base of interval. This value will + * be set to 2 * interval. */ public void clearInertia() { this.inertia = -1; @@ -455,7 +452,7 @@ public void clearInertia() { /** * Get attached webcam object. - * + * * @return Attached webcam */ public Webcam getWebcam() { @@ -470,9 +467,9 @@ public boolean isMotion() { } /** - * Get percentage fraction of image covered by motion. 0 means no motion on - * image and 100 means full image covered by spontaneous motion. - * + * Get percentage fraction of image covered by motion. 0 means no motion on image and 100 means + * full image covered by spontaneous motion. + * * @return Return percentage image fraction covered by motion */ public double getMotionArea() { @@ -480,9 +477,9 @@ public double getMotionArea() { } /** - * Get motion center of gravity. When no motion is detected this value - * points to the image center. - * + * Get motion center of gravity. When no motion is detected this value points to the image + * center. + * * @return Center of gravity point */ public Point getMotionCog() { diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamMotionEvent.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamMotionEvent.java index 3e41e085..1701e075 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamMotionEvent.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamMotionEvent.java @@ -6,7 +6,7 @@ /** * Webcam detected motion event. - * + * * @author Bartosz Firyn (SarXos) */ public class WebcamMotionEvent extends EventObject { @@ -18,9 +18,10 @@ public class WebcamMotionEvent extends EventObject { /** * Create detected motion event. - * + * * @param detector * @param strength + * @param cog center of motion gravity */ public WebcamMotionEvent(WebcamMotionDetector detector, double strength, Point cog) { @@ -31,9 +32,9 @@ public WebcamMotionEvent(WebcamMotionDetector detector, double strength, Point c } /** - * Get percentage fraction of image covered by motion. 0 is no motion on - * image, and 100 is full image covered by motion. - * + * Get percentage fraction of image covered by motion. 0 is no motion on image, and 100 is full + * image covered by motion. + * * @return Motion area */ public double getArea() { diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamPanel.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamPanel.java index a53cd9b4..1358284d 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamPanel.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamPanel.java @@ -41,56 +41,58 @@ /** - * Simply implementation of JPanel allowing users to render pictures taken with - * webcam. - * + * Simply implementation of JPanel allowing users to render pictures taken with webcam. + * * @author Bartosz Firyn (SarXos) */ public class WebcamPanel extends JPanel implements WebcamListener, PropertyChangeListener { /** * This enum is to control of how image will be drawn in the panel bounds. - * + * * @author Sylwia Kauczor */ public static enum DrawMode { /** - * Do not resize image - paint it as it is. This will make the image to - * go off out the bounds if panel is smaller than image size. + * Do not resize image - paint it as it is. This will make the image to go off out the + * bounds if panel is smaller than image size. */ NONE, /** - * Will resize image to the panel bounds. This mode does not care of the - * image scale, so the final image may be disrupted. + * Will resize image to the panel bounds. This mode does not care of the image scale, so the + * final image may be disrupted. */ FILL, /** - * Will fir image into the panel bounds. This will resize the image and - * keep both x and y scale factor. + * Will fir image into the panel bounds. This will resize the image and keep both x and y + * scale factor. */ FIT, } /** * Interface of the painter used to draw image in panel. - * + * * @author Bartosz Firyn (SarXos) */ public static interface Painter { /** - * Paints panel without image. - * + * Paint panel without image. + * + * @param panel the webcam panel to paint on * @param g2 the graphics 2D object used for drawing */ void paintPanel(WebcamPanel panel, Graphics2D g2); /** - * Paints webcam image in panel. - * + * Paint webcam image in panel. + * + * @param panel the webcam panel to paint on + * @param image the image from webcam * @param g2 the graphics 2D object used for drawing */ void paintImage(WebcamPanel panel, BufferedImage image, Graphics2D g2); @@ -98,7 +100,7 @@ public static interface Painter { /** * Default painter used to draw image in panel. - * + * * @author Bartosz Firyn (SarXos) * @author Sylwia Kauczor */ @@ -426,14 +428,14 @@ public void run() { /** * Image updater reads images from camera and force panel to be repainted. - * + * * @author Bartosz Firyn (SarXos) */ private class ImageUpdater implements Runnable { /** * Repaint scheduler schedule panel updates. - * + * * @author Bartosz Firyn (sarxos) */ private class RepaintScheduler extends Thread { @@ -513,8 +515,7 @@ public void run() { private AtomicBoolean running = new AtomicBoolean(false); /** - * Start repainter. Can be invoked many times, but only first call will - * take effect. + * Start repainter. Can be invoked many times, but only first call will take effect. */ public void start() { if (running.compareAndSet(false, true)) { @@ -525,9 +526,8 @@ public void start() { } /** - * Stop repainter. Can be invoked many times, but only first call will - * take effect. - * + * Stop repainter. Can be invoked many times, but only first call will take effect. + * * @throws InterruptedException */ public void stop() throws InterruptedException { @@ -588,9 +588,9 @@ private void update() { private ResourceBundle rb = null; /** - * The mode of how the image will be resized to fit into panel bounds. - * Default is {@link DrawMode#FIT} - * + * The mode of how the image will be resized to fit into panel bounds. Default is + * {@link DrawMode#FIT} + * * @see DrawMode */ private DrawMode drawMode = DrawMode.FIT; @@ -601,9 +601,8 @@ private void update() { private double frequency = 5; // FPS /** - * Is frames requesting frequency limited? If true, images will be fetched - * in configured time intervals. If false, images will be fetched as fast as - * camera can serve them. + * Is frames requesting frequency limited? If true, images will be fetched in configured time + * intervals. If false, images will be fetched as fast as camera can serve them. */ private boolean frequencyLimit = false; @@ -628,8 +627,7 @@ private void update() { private final Webcam webcam; /** - * Repainter is used to fetch images from camera and force panel repaint - * when image is ready. + * Repainter is used to fetch images from camera and force panel repaint when image is ready. */ private final ImageUpdater updater; @@ -665,7 +663,7 @@ private void update() { /** * Painter used to draw image in panel. - * + * * @see #setPainter(Painter) * @see #getPainter() */ @@ -688,7 +686,7 @@ private void update() { /** * Creates webcam panel and automatically start webcam. - * + * * @param webcam the webcam to be used to fetch images */ public WebcamPanel(Webcam webcam) { @@ -696,9 +694,8 @@ public WebcamPanel(Webcam webcam) { } /** - * Creates new webcam panel which display image from camera in you your - * Swing application. - * + * Creates new webcam panel which display image from camera in you your Swing application. + * * @param webcam the webcam to be used to fetch images * @param start true if webcam shall be automatically started */ @@ -707,12 +704,11 @@ public WebcamPanel(Webcam webcam, boolean start) { } /** - * Creates new webcam panel which display image from camera in you your - * Swing application. If panel size argument is null, then image size will - * be used. If you would like to fill panel area with image even if its size - * is different, then you can use {@link WebcamPanel#setFillArea(boolean)} - * method to configure this. - * + * Creates new webcam panel which display image from camera in you your Swing application. If + * panel size argument is null, then image size will be used. If you would like to fill panel + * area with image even if its size is different, then you can use + * {@link WebcamPanel#setFillArea(boolean)} method to configure this. + * * @param webcam the webcam to be used to fetch images * @param size the size of panel * @param start true if webcam shall be automatically started @@ -750,7 +746,7 @@ public WebcamPanel(Webcam webcam, Dimension size, boolean start) { /** * Set new painter. Painter is a class which pains image visible when - * + * * @param painter the painter object to be set */ public void setPainter(Painter painter) { @@ -759,7 +755,7 @@ public void setPainter(Painter painter) { /** * Get painter used to draw image in webcam panel. - * + * * @return Painter object */ public Painter getPainter() { @@ -877,7 +873,7 @@ public void resume() { /** * Is frequency limit enabled? - * + * * @return True or false */ public boolean isFPSLimited() { @@ -885,11 +881,11 @@ public boolean isFPSLimited() { } /** - * Enable or disable frequency limit. Frequency limit should be used for - * all IP cameras working in pull mode (to save number of HTTP - * requests). If true, images will be fetched in configured time intervals. - * If false, images will be fetched as fast as camera can serve them. - * + * Enable or disable frequency limit. Frequency limit should be used for all IP cameras + * working in pull mode (to save number of HTTP requests). If true, images will be fetched + * in configured time intervals. If false, images will be fetched as fast as camera can serve + * them. + * * @param frequencyLimit */ public void setFPSLimited(boolean frequencyLimit) { @@ -898,7 +894,7 @@ public void setFPSLimited(boolean frequencyLimit) { /** * Get rendering frequency in FPS (equivalent to Hz). - * + * * @return Rendering frequency */ public double getFPSLimit() { @@ -906,9 +902,9 @@ public double getFPSLimit() { } /** - * Set rendering frequency (in Hz or FPS). Minimum frequency is 0.016 (1 - * frame per minute) and maximum is 25 (25 frames per second). - * + * Set rendering frequency (in Hz or FPS). Minimum frequency is 0.016 (1 frame per minute) and + * maximum is 25 (25 frames per second). + * * @param fps the frequency */ public void setFPSLimit(double fps) { @@ -923,7 +919,7 @@ public void setFPSLimit(double fps) { /** * Is displaying of some debug information enabled. - * + * * @return True if debug information are enabled, false otherwise */ public boolean isDisplayDebugInfo() { @@ -932,7 +928,7 @@ public boolean isDisplayDebugInfo() { /** * Display some debug information on image surface. - * + * * @param displayDebugInfo the value to control debug information */ public void setDisplayDebugInfo(boolean displayDebugInfo) { @@ -940,9 +936,9 @@ public void setDisplayDebugInfo(boolean displayDebugInfo) { } /** - * This method return true in case if camera FPS is set to be displayed on - * panel surface. Default value returned is false. - * + * This method return true in case if camera FPS is set to be displayed on panel surface. + * Default value returned is false. + * * @return True if camera FPS is set to be displayed on panel surface * @see #setFPSDisplayed(boolean) */ @@ -951,9 +947,8 @@ public boolean isFPSDisplayed() { } /** - * This method is to control if camera FPS should be displayed on the webcam - * panel surface. - * + * This method is to control if camera FPS should be displayed on the webcam panel surface. + * * @param displayed the value to control if camera FPS should be displayed */ public void setFPSDisplayed(boolean displayed) { @@ -961,10 +956,9 @@ public void setFPSDisplayed(boolean displayed) { } /** - * This method will return true in case when panel is configured to display - * image size. The string will be printed in the right bottom corner of the - * panel surface. - * + * This method will return true in case when panel is configured to display image size. The + * string will be printed in the right bottom corner of the panel surface. + * * @return True in case if panel is configured to display image size */ public boolean isImageSizeDisplayed() { @@ -973,7 +967,7 @@ public boolean isImageSizeDisplayed() { /** * Configure panel to display camera image size to be displayed. - * + * * @param imageSizeDisplayed */ public void setImageSizeDisplayed(boolean imageSizeDisplayed) { @@ -982,7 +976,7 @@ public void setImageSizeDisplayed(boolean imageSizeDisplayed) { /** * Turn on/off antialiasing. - * + * * @param antialiasing the true to enable, false to disable antialiasing */ public void setAntialiasingEnabled(boolean antialiasing) { @@ -998,7 +992,7 @@ public boolean isAntialiasingEnabled() { /** * Is webcam panel repainting starting. - * + * * @return True if panel is starting */ public boolean isStarting() { @@ -1007,7 +1001,7 @@ public boolean isStarting() { /** * Is webcam panel repainting started. - * + * * @return True if panel repainting has been started */ public boolean isStarted() { @@ -1019,11 +1013,10 @@ public boolean isFitArea() { } /** - * This method will change the mode of panel area painting so the image will - * be resized and will keep scale factor to fit into drawable panel bounds. - * When set to false, the mode will be reset to {@link DrawMode#NONE} so - * image will be drawn as it is. - * + * This method will change the mode of panel area painting so the image will be resized and will + * keep scale factor to fit into drawable panel bounds. When set to false, the mode will be + * reset to {@link DrawMode#NONE} so image will be drawn as it is. + * * @param fitArea the fit area mode enabled or disabled */ public void setFitArea(boolean fitArea) { @@ -1031,9 +1024,9 @@ public void setFitArea(boolean fitArea) { } /** - * Image will be resized to fill panel area if true. If false then image - * will be rendered as it was obtained from webcam instance. - * + * Image will be resized to fill panel area if true. If false then image will be rendered as it + * was obtained from webcam instance. + * * @param fillArea shall image be resided to fill panel area */ public void setFillArea(boolean fillArea) { @@ -1041,10 +1034,9 @@ public void setFillArea(boolean fillArea) { } /** - * Get value of fill area setting. Image will be resized to fill panel area - * if true. If false then image will be rendered as it was obtained from - * webcam instance. - * + * Get value of fill area setting. Image will be resized to fill panel area if true. If false + * then image will be rendered as it was obtained from webcam instance. + * * @return True if image is being resized, false otherwise */ public boolean isFillArea() { @@ -1053,7 +1045,7 @@ public boolean isFillArea() { /** * Get default painter used to draw panel. - * + * * @return Default painter */ public Painter getDefaultPainter() { @@ -1095,9 +1087,8 @@ public void webcamImageObtained(WebcamEvent we) { } /** - * This method returns true if image mirroring is enabled. The default value - * is false. - * + * This method returns true if image mirroring is enabled. The default value is false. + * * @return True if image is mirrored, false otherwise */ public boolean isMirrored() { @@ -1105,9 +1096,9 @@ public boolean isMirrored() { } /** - * Decide whether or not the image from webcam painted on panel surface will - * be mirrored. The image from camera itself is not modified. - * + * Decide whether or not the image from webcam painted on panel surface will be mirrored. The + * image from camera itself is not modified. + * * @param mirrored the parameter to control if image should be mirrored */ public void setMirrored(boolean mirrored) { diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamProcessor.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamProcessor.java index 65d66d09..98946e82 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamProcessor.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamProcessor.java @@ -19,7 +19,7 @@ public class WebcamProcessor { /** * Thread doing supersync processing. - * + * * @author sarxos */ public static final class ProcessorThread extends Thread { @@ -33,7 +33,7 @@ public ProcessorThread(Runnable r) { /** * Thread factory for processor. - * + * * @author Bartosz Firyn (SarXos) */ private static final class ProcessorThreadFactory implements ThreadFactory { @@ -48,10 +48,9 @@ public Thread newThread(Runnable r) { } /** - * Heart of overall processing system. This class process all native calls - * wrapped in tasks, by doing this all tasks executions are - * super-synchronized. - * + * Heart of overall processing system. This class process all native calls wrapped in tasks, by + * doing this all tasks executions are super-synchronized. + * * @author Bartosz Firyn (SarXos) */ private static final class AtomicProcessor implements Runnable { @@ -61,9 +60,8 @@ private static final class AtomicProcessor implements Runnable { /** * Process task. - * + * * @param task the task to be processed - * @return Processed task * @throws InterruptedException when thread has been interrupted */ public void process(WebcamTask task) throws InterruptedException { @@ -127,7 +125,7 @@ private WebcamProcessor() { /** * Process single webcam task. - * + * * @param task the task to be processed * @throws InterruptedException when thread has been interrupted */ diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamUtils.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamUtils.java index 6300e54c..b7a4ad88 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamUtils.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamUtils.java @@ -57,7 +57,7 @@ public static final byte[] getImageBytes(Webcam webcam, String format) { /** * Capture image as BYteBuffer. - * + * * @param webcam the webcam from which image should be obtained * @param format the file format * @return Byte buffer @@ -68,8 +68,9 @@ public static final ByteBuffer getImageByteBuffer(Webcam webcam, String format) /** * Get resource bundle for specific class. - * + * * @param clazz the class for which resource bundle should be found + * @param locale the {@link Locale} object * @return Resource bundle */ public static final ResourceBundle loadRB(Class clazz, Locale locale) { diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/util/jh/JHBlurFilter.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/util/jh/JHBlurFilter.java index 8c1b6a21..8bc11d0c 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/util/jh/JHBlurFilter.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/util/jh/JHBlurFilter.java @@ -20,9 +20,9 @@ /** - * A filter which performs a box blur on an image. The horizontal and vertical - * blurs can be specified separately and a number of iterations can be given - * which allows an approximation to Gaussian blur. + * A filter which performs a box blur on an image. The horizontal and vertical blurs can be + * specified separately and a number of iterations can be given which allows an approximation to + * Gaussian blur. */ public class JHBlurFilter extends JHFilter { @@ -39,7 +39,7 @@ public JHBlurFilter() { /** * Construct a BoxBlurFilter. - * + * * @param hRadius the horizontal radius of blur * @param vRadius the vertical radius of blur * @param iterations the number of time to iterate the blur @@ -52,7 +52,7 @@ public JHBlurFilter(float hRadius, float vRadius, int iterations) { /** * Set whether to premultiply the alpha channel. - * + * * @param premultiplyAlpha true to premultiply the alpha * @see #getPremultiplyAlpha */ @@ -62,7 +62,7 @@ public void setPremultiplyAlpha(boolean premultiplyAlpha) { /** * Get whether to premultiply the alpha channel. - * + * * @return true to premultiply the alpha * @see #setPremultiplyAlpha */ @@ -75,23 +75,26 @@ public BufferedImage filter(BufferedImage src, BufferedImage dst) { int width = src.getWidth(); int height = src.getHeight(); - if (dst == null) + if (dst == null) { dst = createCompatibleDestImage(src, null); + } int[] inPixels = new int[width * height]; int[] outPixels = new int[width * height]; getRGB(src, 0, 0, width, height, inPixels); - if (premultiplyAlpha) + if (premultiplyAlpha) { premultiply(inPixels, 0, inPixels.length); + } for (int i = 0; i < iterations; i++) { blur(inPixels, outPixels, width, height, hRadius); blur(outPixels, inPixels, height, width, vRadius); } blurFractional(inPixels, outPixels, width, height, hRadius); blurFractional(outPixels, inPixels, height, width, vRadius); - if (premultiplyAlpha) + if (premultiplyAlpha) { unpremultiply(inPixels, 0, inPixels.length); + } setRGB(dst, 0, 0, width, height, inPixels); return dst; @@ -99,7 +102,7 @@ public BufferedImage filter(BufferedImage src, BufferedImage dst) { /** * Blur and transpose a block of ARGB pixels. - * + * * @param in the input pixels * @param out the output pixels * @param width the width of the pixel array @@ -112,8 +115,9 @@ public static void blur(int[] in, int[] out, int width, int height, float radius int tableSize = 2 * r + 1; int divide[] = new int[256 * tableSize]; - for (int i = 0; i < 256 * tableSize; i++) + for (int i = 0; i < 256 * tableSize; i++) { divide[i] = i / tableSize; + } int inIndex = 0; @@ -133,11 +137,13 @@ public static void blur(int[] in, int[] out, int width, int height, float radius out[outIndex] = (divide[ta] << 24) | (divide[tr] << 16) | (divide[tg] << 8) | divide[tb]; int i1 = x + r + 1; - if (i1 > widthMinus1) + if (i1 > widthMinus1) { i1 = widthMinus1; + } int i2 = x - r; - if (i2 < 0) + if (i2 < 0) { i2 = 0; + } int rgb1 = in[inIndex + i1]; int rgb2 = in[inIndex + i2]; @@ -197,7 +203,7 @@ public static void blurFractional(int[] in, int[] out, int width, int height, fl /** * Set the horizontal size of the blur. Minimum hRadius value is 0. - * + * * @param hRadius the radius of the blur in the horizontal direction * @see #getHRadius */ @@ -207,7 +213,7 @@ public void setHRadius(float hRadius) { /** * Get the horizontal size of the blur. - * + * * @return the radius of the blur in the horizontal direction * @see #setHRadius */ @@ -217,7 +223,7 @@ public float getHRadius() { /** * Set the vertical size of the blur. Minimal vRadius value is 0. - * + * * @param vRadius the radius of the blur in the vertical direction * @see #getVRadius */ @@ -227,7 +233,7 @@ public void setVRadius(float vRadius) { /** * Get the vertical size of the blur. - * + * * @return the radius of the blur in the vertical direction * @see #setVRadius */ @@ -236,9 +242,8 @@ public float getVRadius() { } /** - * Set both the horizontal and vertical sizes of the blur. Minimum value is - * 0. - * + * Set both the horizontal and vertical sizes of the blur. Minimum value is 0. + * * @param radius the radius of the blur in both directions * @see #getRadius */ @@ -248,7 +253,7 @@ public void setRadius(float radius) { /** * Get the size of the blur. - * + * * @return the radius of the blur in the horizontal direction * @see #setRadius */ @@ -258,7 +263,7 @@ public float getRadius() { /** * Set the number of iterations the blur is performed. Minimum value is 0. - * + * * @param iterations the number of iterations * @see #getIterations */ @@ -268,7 +273,7 @@ public void setIterations(int iterations) { /** * Get the number of iterations the blur is performed. - * + * * @return the number of iterations * @see #setIterations */ @@ -283,6 +288,10 @@ public String toString() { /** * Premultiply a block of pixels + * + * @param p pixels + * @param offset the offset + * @param length the length */ public static void premultiply(int[] p, int offset, int length) { length += offset; @@ -302,6 +311,10 @@ public static void premultiply(int[] p, int offset, int length) { /** * Premultiply a block of pixels + * + * @param p the pixels + * @param offset the offset + * @param length the length */ public static void unpremultiply(int[] p, int offset, int length) { length += offset; @@ -316,12 +329,15 @@ public static void unpremultiply(int[] p, int offset, int length) { r *= f; g *= f; b *= f; - if (r > 255) + if (r > 255) { r = 255; - if (g > 255) + } + if (g > 255) { g = 255; - if (b > 255) + } + if (b > 255) { b = 255; + } p[i] = (a << 24) | (r << 16) | (g << 8) | b; } } @@ -329,7 +345,7 @@ public static void unpremultiply(int[] p, int offset, int length) { /** * Clamp a value to an interval. - * + * * @param a the lower clamp threshold * @param b the upper clamp threshold * @param x the input parameter