001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.cscore.raw; 006 007import edu.wpi.first.cscore.CameraServerJNI; 008import edu.wpi.first.cscore.ImageSource; 009import edu.wpi.first.cscore.VideoMode; 010import edu.wpi.first.util.RawFrame; 011 012/** 013 * A source for user code to provide video frames as raw bytes. 014 * 015 * <p>This is a complex API, most cases should use CvSource. 016 */ 017public class RawSource extends ImageSource { 018 /** 019 * Create a raw frame source. 020 * 021 * @param name Source name (arbitrary unique identifier) 022 * @param mode Video mode being generated 023 */ 024 public RawSource(String name, VideoMode mode) { 025 super( 026 CameraServerJNI.createRawSource( 027 name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps)); 028 } 029 030 /** 031 * Create a raw frame source. 032 * 033 * @param name Source name (arbitrary unique identifier) 034 * @param pixelFormat Pixel format 035 * @param width width 036 * @param height height 037 * @param fps fps 038 */ 039 public RawSource(String name, VideoMode.PixelFormat pixelFormat, int width, int height, int fps) { 040 super(CameraServerJNI.createRawSource(name, pixelFormat.getValue(), width, height, fps)); 041 } 042 043 /** 044 * Put a raw image and notify sinks. 045 * 046 * @param image raw frame image 047 */ 048 protected void putFrame(RawFrame image) { 049 CameraServerJNI.putRawSourceFrame(m_handle, image); 050 } 051 052 /** 053 * Put a raw image and notify sinks. 054 * 055 * @param data raw frame data pointer 056 * @param width frame width 057 * @param height frame height 058 * @param pixelFormat pixel format 059 * @param totalData length of data in total 060 */ 061 protected void putFrame(long data, int width, int height, int pixelFormat, int totalData) { 062 CameraServerJNI.putRawSourceFrame(m_handle, data, width, height, pixelFormat, totalData); 063 } 064 065 /** 066 * Put a raw image and notify sinks. 067 * 068 * @param data raw frame data pointer 069 * @param width frame width 070 * @param height frame height 071 * @param pixelFormat pixel format 072 * @param totalData length of data in total 073 */ 074 protected void putFrame( 075 long data, int width, int height, VideoMode.PixelFormat pixelFormat, int totalData) { 076 CameraServerJNI.putRawSourceFrame( 077 m_handle, data, width, height, pixelFormat.getValue(), totalData); 078 } 079}