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; 006 007import java.util.Objects; 008 009/** Video mode. */ 010@SuppressWarnings("MemberName") 011public class VideoMode { 012 public enum PixelFormat { 013 kUnknown(0), 014 kMJPEG(1), 015 kYUYV(2), 016 kRGB565(3), 017 kBGR(4), 018 kGray(5), 019 kY16(6), 020 kUYVY(7); 021 022 private final int value; 023 024 PixelFormat(int value) { 025 this.value = value; 026 } 027 028 public int getValue() { 029 return value; 030 } 031 } 032 033 private static final PixelFormat[] m_pixelFormatValues = PixelFormat.values(); 034 035 public static PixelFormat getPixelFormatFromInt(int pixelFormat) { 036 return m_pixelFormatValues[pixelFormat]; 037 } 038 039 /** 040 * Create a new video mode. 041 * 042 * @param pixelFormat The pixel format enum as an integer. 043 * @param width The image width in pixels. 044 * @param height The image height in pixels. 045 * @param fps The camera's frames per second. 046 */ 047 public VideoMode(int pixelFormat, int width, int height, int fps) { 048 this.pixelFormat = getPixelFormatFromInt(pixelFormat); 049 this.width = width; 050 this.height = height; 051 this.fps = fps; 052 } 053 054 /** 055 * Create a new video mode. 056 * 057 * @param pixelFormat The pixel format. 058 * @param width The image width in pixels. 059 * @param height The image height in pixels. 060 * @param fps The camera's frames per second. 061 */ 062 public VideoMode(PixelFormat pixelFormat, int width, int height, int fps) { 063 this.pixelFormat = pixelFormat; 064 this.width = width; 065 this.height = height; 066 this.fps = fps; 067 } 068 069 /** Pixel format. */ 070 public PixelFormat pixelFormat; 071 072 /** Width in pixels. */ 073 public int width; 074 075 /** Height in pixels. */ 076 public int height; 077 078 /** Frames per second. */ 079 public int fps; 080 081 @Override 082 public boolean equals(Object other) { 083 if (this == other) { 084 return true; 085 } 086 if (other == null) { 087 return false; 088 } 089 if (getClass() != other.getClass()) { 090 return false; 091 } 092 VideoMode mode = (VideoMode) other; 093 094 return pixelFormat == mode.pixelFormat 095 && width == mode.width 096 && height == mode.height 097 && fps == mode.fps; 098 } 099 100 @Override 101 public int hashCode() { 102 return Objects.hash(pixelFormat, width, height, fps); 103 } 104}