/// **************************************************************************
///
/// $Id: ComponentMappingBox.java,v 1.1 2002/07/25 14:50:46 grosbois Exp $
///
/// Copyright Eastman Kodak Company, 343 State Street, Rochester, NY 14650
/// $Date $
/// ***************************************************************************
///
using System;
using ColorSpaceException = CSJ2K.Color.ColorSpaceException;
using ICCProfile = CSJ2K.Icc.ICCProfile;
using ParameterList = CSJ2K.j2k.util.ParameterList;
using RandomAccessIO = CSJ2K.j2k.io.RandomAccessIO;
namespace CSJ2K.Color.Boxes
{
/// This class maps the components in the codestream
/// to channels in the image. It models the Component
/// Mapping box in the JP2 header.
///
///
/// 1.0
///
/// Bruce A. Kern
///
public sealed class ComponentMappingBox:JP2Box
{
public int NChannels
{
/* Return the number of mapped channels. */
get
{
return nChannels;
}
}
private int nChannels;
private System.Collections.ArrayList map = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
/// Construct a ComponentMappingBox from an input image.
/// RandomAccessIO jp2 image
///
/// offset to the start of the box in the image
///
/// ColorSpaceException
///
public ComponentMappingBox(RandomAccessIO in_Renamed, int boxStart):base(in_Renamed, boxStart)
{
readBox();
}
/// Analyze the box content.
internal void readBox()
{
nChannels = (boxEnd - dataStart) / 4;
in_Renamed.seek(dataStart);
for (int offset = dataStart; offset < boxEnd; offset += 4)
{
byte[] mapping = new byte[4];
in_Renamed.readFully(mapping, 0, 4);
map.Add(mapping);
}
}
/* Return the component mapped to the channel. */
public int getCMP(int channel)
{
byte[] mapping = (byte[]) map[channel];
return ICCProfile.getShort(mapping, 0) & 0x0000ffff;
}
/// Return the channel type.
public short getMTYP(int channel)
{
byte[] mapping = (byte[]) map[channel];
return (short) (mapping[2] & 0x00ff);
}
/// Return the palette index for the channel.
public short getPCOL(int channel)
{
byte[] mapping = (byte[]) map[channel];
return (short) (mapping[3] & 0x000ff);
}
/// Return a suitable String representation of the class instance.
public override System.String ToString()
{
System.Text.StringBuilder rep = new System.Text.StringBuilder("[ComponentMappingBox ").Append(" ");
rep.Append("nChannels= ").Append(System.Convert.ToString(nChannels));
System.Collections.IEnumerator Enum = map.GetEnumerator();
//UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
while (Enum.MoveNext())
{
//UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
byte[] bfr = (byte[]) Enum.Current;
rep.Append(eol).Append(" ").Append("CMP= ").Append(System.Convert.ToString(getCMP(bfr))).Append(", ");
rep.Append("MTYP= ").Append(System.Convert.ToString(getMTYP(bfr))).Append(", ");
rep.Append("PCOL= ").Append(System.Convert.ToString(getPCOL(bfr)));
}
rep.Append("]");
return rep.ToString();
}
private int getCMP(byte[] mapping)
{
return ICCProfile.getShort(mapping, 0) & 0x0000ffff;
}
private short getMTYP(byte[] mapping)
{
return (short) (mapping[2] & 0x00ff);
}
private short getPCOL(byte[] mapping)
{
return (short) (mapping[3] & 0x000ff);
}
/* end class ComponentMappingBox */
static ComponentMappingBox()
{
{
type = 0x636d6170;
}
}
}
}