public static ColorValueExtent ColorValueExtent(MetafileReader reader, CommandHeader commandHeader) { // If the model is RGB or CMYK, then 2 parameters: // P1: (direct colour value) minimum colour value // P2: (direct colour value) maximum colour value // If the model is CIELAB, CIELUV, or RGB-related then 3 parameters: // P1: (real) scale and offset pair for first component // P2: (real) scale and offset pair for second component // P3: (real) scale and offset pair for third component ColorValueExtent result; if (reader.Descriptor.ColorModel == ColorModel.RGB) { MetafileColor min = reader.ReadDirectColor(); MetafileColor max = reader.ReadDirectColor(); result = new ColorValueExtent(ColorSpace.RGB, min, max); } else if (reader.Descriptor.ColorModel == ColorModel.CMYK) { MetafileColor min = reader.ReadDirectColor(); MetafileColor max = reader.ReadDirectColor(); result = new ColorValueExtent(ColorSpace.CMYK, min, max); } else if (reader.Descriptor.ColorModel == ColorModel.CIELAB || reader.Descriptor.ColorModel == ColorModel.CIELUV || reader.Descriptor.ColorModel == ColorModel.RGBrelated) { double firstScale = reader.ReadReal(); double firstOffset = reader.ReadReal(); double secondScale = reader.ReadReal(); double secondOffset = reader.ReadReal(); double thirdScale = reader.ReadReal(); double thirdOffset = reader.ReadReal(); result = new ColorValueExtent(ColorSpace.CIE, firstScale, firstOffset, secondScale, secondOffset, thirdScale, thirdOffset); } else { // unsupported, just return a default unknown color space result = new ColorValueExtent(); } return(result); }
public static ColorTable ColorTable(MetafileReader reader, CommandHeader commandHeader) { // P1: (colour index) starting colour table index // P2: (direct colour list) list of direct colour values (>3-tuples or 4-tuples of direct colour components (CCO)) int startIndex = reader.ReadColorIndex(); var colors = new List <MetafileColor>(); while (reader.HasMoreData(3)) // at least 3 color components with at least 1 byte each { colors.Add(reader.ReadDirectColor()); } return(new ColorTable(startIndex, colors.ToArray())); }
private static object ReadValue(MetafileReader reader, DataTypeIndex type) { switch (type) { case DataTypeIndex.StructuredDataRecord: return(ReadStructuredDataRecord(reader)); case DataTypeIndex.ColorIndex: return(reader.ReadIndexedColor()); case DataTypeIndex.ColorDirect: return(reader.ReadDirectColor()); case DataTypeIndex.Name: return(reader.ReadName()); case DataTypeIndex.Enumerated: return(reader.ReadEnum()); case DataTypeIndex.Integer: return(reader.ReadInteger()); case DataTypeIndex.Reserved: // TODO: what exactly does reserved mean in terms of advancing position? return(null); case DataTypeIndex.SignedInteger8bit: return(reader.ReadInteger(1, false)); case DataTypeIndex.SignedInteger16bit: return(reader.ReadInteger(2, false)); case DataTypeIndex.SignedInteger32bit: return(reader.ReadInteger(4, false)); case DataTypeIndex.Index: return(reader.ReadIndex()); case DataTypeIndex.Real: return(reader.ReadReal()); case DataTypeIndex.String: case DataTypeIndex.StringFixed: // TODO: difference between S and SF? charset/escape code handling? return(reader.ReadString()); case DataTypeIndex.ViewportCoordinate: return(reader.ReadViewportCoordinate()); case DataTypeIndex.VDC: return(reader.ReadVdc()); case DataTypeIndex.ColorComponent: return(reader.ReadColorValue()); case DataTypeIndex.UnsignedInteger8bit: return(reader.ReadInteger(1, true)); case DataTypeIndex.UnsignedInteger32Bit: return(reader.ReadInteger(4, true)); case DataTypeIndex.UnsignedInteger16bit: return(reader.ReadInteger(2, true)); case DataTypeIndex.BitStream: case DataTypeIndex.ColorList: default: // FIXME: how are those implemented? return(null); } }
public static BackgroundColor BackgroundColor(MetafileReader reader, CommandHeader header) { // P1: (direct colour) background colour. return(new BackgroundColor(reader.ReadDirectColor())); }