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.wpilibj.util; 006 007import edu.wpi.first.math.MathUtil; 008import java.util.Objects; 009 010/** Represents colors with 8 bits of precision. */ 011@SuppressWarnings("MemberName") 012public class Color8Bit { 013 public final int red; 014 public final int green; 015 public final int blue; 016 017 /** 018 * Constructs a Color8Bit. 019 * 020 * @param red Red value (0-255) 021 * @param green Green value (0-255) 022 * @param blue Blue value (0-255) 023 */ 024 public Color8Bit(int red, int green, int blue) { 025 this.red = MathUtil.clamp(red, 0, 255); 026 this.green = MathUtil.clamp(green, 0, 255); 027 this.blue = MathUtil.clamp(blue, 0, 255); 028 } 029 030 /** 031 * Constructs a Color8Bit from a Color. 032 * 033 * @param color The color 034 */ 035 public Color8Bit(Color color) { 036 this((int) (color.red * 255), (int) (color.green * 255), (int) (color.blue * 255)); 037 } 038 039 @Override 040 public boolean equals(Object other) { 041 if (this == other) { 042 return true; 043 } 044 if (other == null || getClass() != other.getClass()) { 045 return false; 046 } 047 048 Color8Bit color8Bit = (Color8Bit) other; 049 return red == color8Bit.red && green == color8Bit.green && blue == color8Bit.blue; 050 } 051 052 @Override 053 public int hashCode() { 054 return Objects.hash(red, green, blue); 055 } 056}