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; 010 011/** 012 * A source for user code to provide video frames as raw bytes. 013 * 014 * <p>This is a complex API, most cases should use CvSource. 015 */ 016public class RawSource extends ImageSource { 017 /** 018 * Create a raw frame source. 019 * 020 * @param name Source name (arbitrary unique identifier) 021 * @param mode Video mode being generated 022 */ 023 public RawSource(String name, VideoMode mode) { 024 super( 025 CameraServerJNI.createRawSource( 026 name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps)); 027 } 028 029 /** 030 * Create a raw frame source. 031 * 032 * @param name Source name (arbitrary unique identifier) 033 * @param pixelFormat Pixel format 034 * @param width width 035 * @param height height 036 * @param fps fps 037 */ 038 public RawSource(String name, VideoMode.PixelFormat pixelFormat, int width, int height, int fps) { 039 super(CameraServerJNI.createRawSource(name, pixelFormat.getValue(), width, height, fps)); 040 } 041 042 /** 043 * Put a raw image and notify sinks. 044 * 045 * @param image raw frame image 046 */ 047 protected void putFrame(RawFrame image) { 048 CameraServerJNI.putRawSourceFrame(m_handle, image); 049 } 050 051 /** 052 * Put a raw image and notify sinks. 053 * 054 * @param data raw frame data pointer 055 * @param width frame width 056 * @param height frame height 057 * @param pixelFormat pixel format 058 * @param totalData length of data in total 059 */ 060 protected void putFrame(long data, int width, int height, int pixelFormat, int totalData) { 061 CameraServerJNI.putRawSourceFrame(m_handle, data, width, height, pixelFormat, totalData); 062 } 063 064 /** 065 * Put a raw image and notify sinks. 066 * 067 * @param data raw frame data pointer 068 * @param width frame width 069 * @param height frame height 070 * @param pixelFormat pixel format 071 * @param totalData length of data in total 072 */ 073 protected void putFrame( 074 long data, int width, int height, VideoMode.PixelFormat pixelFormat, int totalData) { 075 CameraServerJNI.putRawSourceFrame( 076 m_handle, data, width, height, pixelFormat.getValue(), totalData); 077 } 078}