예제 #1
0
        private int GetBlockLength(AseColorEntryData block)
        {
            int blockLength;

            blockLength = this.GetBlockLength((_BlockData)block);

            blockLength += 6; // 4 bytes for the color space and 2 bytes for the color type

            // TODO: Include support for other color spaces

            blockLength += 12; // length of RGB data (3 * 4 bytes)

            return(blockLength);
        }
예제 #2
0
        private void WriteBlock(Stream stream, AseColorEntryData block)
        {
            int blockLength;

            blockLength = this.GetBlockLength(block);

            stream.WriteBigEndian((ushort)AseBlockType.Color);
            stream.WriteBigEndian(blockLength);

            this.WriteNullTerminatedString(stream, block.Name);

            stream.Write("RGB ");

            stream.WriteBigEndian((float)(block.R / 255.0));
            stream.WriteBigEndian((float)(block.G / 255.0));
            stream.WriteBigEndian((float)(block.B / 255.0));

            stream.WriteBigEndian((ushort)block.Type);

            this.WriteExtraData(stream, block.ExtraData);
        }
예제 #3
0
        private _BlockData ReadColorBlock(Stream stream, Stack <AseColorEntryCollection> colorStack)
        {
            AseColorEntryData block;
            string            colorMode;
            byte                    r;
            byte                    g;
            byte                    b;
            AseColorType            colorType;
            string                  name;
            AseColorEntryCollection colors;

            // get the name of the color
            // this is stored as a null terminated string
            // with the length of the byte data stored before
            // the string data in a 16bit int
            name = stream.ReadStringBigEndian();

            // get the mode of the color, which is stored
            // as four ASCII characters
            colorMode = stream.ReadString(4);

            // read the color data
            // how much data we need to read depends on the
            // color mode we previously read
            switch (colorMode)
            {
            case "RGB ":
                // RGB is comprised of three floating point values ranging from 0-1.0
                float value1;
                float value2;
                float value3;
                value1 = stream.ReadSingleBigEndian();
                value2 = stream.ReadSingleBigEndian();
                value3 = stream.ReadSingleBigEndian();
                r      = (byte)Convert.ToInt32(value1 * 255);
                g      = (byte)Convert.ToInt32(value2 * 255);
                b      = (byte)Convert.ToInt32(value3 * 255);
                break;

            case "CMYK":
                // CMYK is comprised of four floating point values
                throw new InvalidDataException(string.Format("Unsupported color mode '{0}'.", colorMode));

            case "LAB ":
                // LAB is comprised of three floating point values
                throw new InvalidDataException(string.Format("Unsupported color mode '{0}'.", colorMode));

            case "Gray":
                // Grayscale is comprised of a single floating point value
                throw new InvalidDataException(string.Format("Unsupported color mode '{0}'.", colorMode));

            default:
                throw new InvalidDataException(string.Format("Unsupported color mode '{0}'.", colorMode));
            }

            // the final "official" piece of data is a color type
            colorType = (AseColorType)stream.ReadUInt16BigEndian();

            block = new AseColorEntryData
            {
                R    = r,
                G    = g,
                B    = b,
                Name = name,
                Type = colorType
            };

            colors = colorStack.Peek();
            colors.Add(block);

            return(block);
        }