using System;
using System.Collections.Generic;
using System.Text;
namespace BitMiracle.LibJpeg
{
using ImageProcessor.Formats;
///
/// Represents a "sample" (you can understand it as a "pixel") of image.
///
/// It's impossible to create an instance of this class directly,
/// but you can use existing samples through collection.
/// Usual scenario is to get row of samples from the method.
///
#if EXPOSE_LIBJPEG
public
#endif
class Sample
{
private short[] m_components;
private byte m_bitsPerComponent;
internal Sample(BitStream bitStream, byte bitsPerComponent, byte componentCount)
{
if (bitStream == null)
throw new ArgumentNullException("bitStream");
if (bitsPerComponent <= 0 || bitsPerComponent > 16)
throw new ArgumentOutOfRangeException("bitsPerComponent");
if (componentCount <= 0 || componentCount > 5)
throw new ArgumentOutOfRangeException("componentCount");
m_bitsPerComponent = bitsPerComponent;
m_components = new short[componentCount];
for (short i = 0; i < componentCount; ++i)
m_components[i] = (short)bitStream.Read(bitsPerComponent);
}
internal Sample(short[] components, byte bitsPerComponent)
{
if (components == null)
throw new ArgumentNullException("components");
if (components.Length == 0 || components.Length > 5)
throw new ArgumentException("components must be not empty and contain less than 5 elements");
if (bitsPerComponent <= 0 || bitsPerComponent > 16)
throw new ArgumentOutOfRangeException("bitsPerComponent");
m_bitsPerComponent = bitsPerComponent;
m_components = new short[components.Length];
Buffer.BlockCopy(components, 0, m_components, 0, components.Length * sizeof(short));
}
///
/// Gets the number of bits per color component.
///
/// The number of bits per color component.
public byte BitsPerComponent
{
get
{
return m_bitsPerComponent;
}
}
///
/// Gets the number of color components.
///
/// The number of color components.
public byte ComponentCount
{
get
{
return (byte)m_components.Length;
}
}
///
/// Gets the color component at the specified index.
///
/// The number of color component.
/// Value of color component.
public short this[int componentNumber]
{
get
{
return m_components[componentNumber];
}
}
///
/// Gets the required color component.
///
/// The number of color component.
/// Value of color component.
public short GetComponent(int componentNumber)
{
return m_components[componentNumber];
}
}
}