001/*
002 * Copyright (C) Photon Vision.
003 *
004 * This program is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package org.photonvision.jni;
019
020import edu.wpi.first.util.RawFrame;
021import edu.wpi.first.util.TimestampSource;
022
023public class CscoreExtras {
024    /**
025     * Fill {@param framePtr} with the latest image from the source this sink is connected to.
026     *
027     * <p>If lastFrameTime is provided and non-zero, the sink will fill image with the first frame
028     * from the source that is not equal to lastFrameTime. If lastFrameTime is zero, the time of the
029     * current frame owned by the CvSource is used, and this function will block until the connected
030     * CvSource provides a new frame.
031     *
032     * @param sink Sink handle.
033     * @param framePtr Pointer to a wpi::RawFrame.
034     * @param timeout Timeout in seconds.
035     * @param lastFrameTime Timestamp of the last frame - used to compare new frames against.
036     * @return Frame time, in uS, of the incoming frame.
037     */
038    public static native long grabRawSinkFrameTimeoutLastTime(
039            int sink, long framePtr, double timeout, long lastFrameTime);
040
041    /**
042     * Wrap the data owned by a RawFrame in a cv::Mat
043     *
044     * @param rawFramePtr
045     * @return pointer to a cv::Mat
046     */
047    public static native long wrapRawFrame(long rawFramePtr);
048
049    private static native int getTimestampSourceNative(long rawFramePtr);
050
051    public static TimestampSource getTimestampSource(RawFrame frame) {
052        return TimestampSource.getFromInt(getTimestampSourceNative(frame.getNativeObj()));
053    }
054}