001package net.bramp.ffmpeg.info; 002 003import org.apache.commons.lang3.builder.EqualsBuilder; 004import org.apache.commons.lang3.builder.HashCodeBuilder; 005 006/** Represents an FFmpeg pixel format with its properties and capabilities. */ 007public class PixelFormat { 008 private final String name; 009 private final int numberOfComponents; 010 private final int bitsPerPixel; 011 012 private final boolean canDecode; 013 private final boolean canEncode; 014 private final boolean hardwareAccelerated; 015 private final boolean palettedFormat; 016 private final boolean bitstreamFormat; 017 018 /** Constructs a new PixelFormat with the given properties. */ 019 public PixelFormat(String name, int numberOfComponents, int bitsPerPixel, String flags) { 020 this.name = name; 021 this.numberOfComponents = numberOfComponents; 022 this.bitsPerPixel = bitsPerPixel; 023 024 this.canDecode = flags.charAt(0) == 'I'; 025 this.canEncode = flags.charAt(1) == 'O'; 026 this.hardwareAccelerated = flags.charAt(2) == 'H'; 027 this.palettedFormat = flags.charAt(3) == 'P'; 028 this.bitstreamFormat = flags.charAt(4) == 'B'; 029 } 030 031 @Override 032 public String toString() { 033 return name; 034 } 035 036 @Override 037 public boolean equals(Object obj) { 038 return EqualsBuilder.reflectionEquals(this, obj); 039 } 040 041 @Override 042 public int hashCode() { 043 return HashCodeBuilder.reflectionHashCode(this); 044 } 045 046 public String getName() { 047 return name; 048 } 049 050 public int getBitsPerPixel() { 051 return bitsPerPixel; 052 } 053 054 public int getNumberOfComponents() { 055 return numberOfComponents; 056 } 057 058 /** Returns whether this pixel format supports encoding. */ 059 public boolean canEncode() { 060 return canEncode; 061 } 062 063 /** Returns whether this pixel format supports decoding. */ 064 public boolean canDecode() { 065 return canDecode; 066 } 067 068 public boolean isHardwareAccelerated() { 069 return hardwareAccelerated; 070 } 071 072 public boolean isPalettedFormat() { 073 return palettedFormat; 074 } 075 076 public boolean isBitstreamFormat() { 077 return bitstreamFormat; 078 } 079}