Exemplo n.º 1
0
            public TgaHeader(Stream input)
            {
                int byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.idLength = (byte)byteRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.cmapType = (byte)byteRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.imageType = (TgaType)byteRead;
                }

                int shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.cmapIndex = (ushort)shortRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.cmapLength = (ushort)shortRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.cmapEntrySize = (byte)byteRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.xOrigin = (ushort)shortRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.yOrigin = (ushort)shortRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.imageWidth = (ushort)shortRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.imageHeight = (ushort)shortRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.pixelDepth = (byte)byteRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.imageDesc = (byte)byteRead;
                }                
            }
Exemplo n.º 2
0
            public TgaHeader(Stream input)
            {
                int byteRead = input.ReadByte();

                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.idLength = (byte)byteRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.cmapType = (byte)byteRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.imageType = (TgaType)byteRead;
                }

                int shortRead = Utility.ReadUInt16(input);

                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.cmapIndex = (ushort)shortRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.cmapLength = (ushort)shortRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.cmapEntrySize = (byte)byteRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.xOrigin = (ushort)shortRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.yOrigin = (ushort)shortRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.imageWidth = (ushort)shortRead;
                }

                shortRead = Utility.ReadUInt16(input);
                if (shortRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.imageHeight = (ushort)shortRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.pixelDepth = (byte)byteRead;
                }

                byteRead = input.ReadByte();
                if (byteRead == -1)
                {
                    throw new EndOfStreamException();
                }
                else
                {
                    this.imageDesc = (byte)byteRead;
                }
            }
Exemplo n.º 3
0
        public static void Save(Image image, TgaType type, Stream stream)
        {
            BinaryWriter bw = new BinaryWriter(stream);

            byte[] header = new byte[18];
            header[2] = (byte)type;
            BinaryHelper.WriteLittleEndianUInt16(header, 12, (ushort)image.Width);
            BinaryHelper.WriteLittleEndianUInt16(header, 14, (ushort)image.Height);
            header[16] = (byte)(image.BytesPerPixel * 8);

            bw.Write(header);
        }