public void Load(Stream stream, TargaImage tga)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (tga == null)
            {
                throw new ArgumentNullException(nameof(tga));
            }

#if DEBUG
            if (stream.GetType() == typeof(FileStream))
            {
                var field = typeof(FileStream).GetField("_bufferSize", BindingFlags.Instance | BindingFlags.NonPublic);
                Debug.Assert(field != null);
                var value = (int)field.GetValue((FileStream)stream);
                Debug.Assert(value <= HeaderSize);
            }
#endif

            stream.SafeRead(_header, 0, _header.Length);
            tga.ChangeResolution(_header[12] << 0 | _header[13] << 8, _header[14] << 0 | _header[15] << 8);
            stream.SafeRead(tga.RawData, 0, tga.RawData.Length);
        }
        public void Add(TargaImage tga)
        {
            if (tga == null)
            {
                throw new ArgumentNullException(nameof(tga));
            }
            if (tga.RawData.Length != _tgaSize)
            {
                throw new ArgumentException("Invalid Image dimensions.", nameof(tga));
            }

            if (_state == null || _state.Length != _tgaSize)
            {
                _state        = new double[_tgaSize];
                _stateDivisor = 0.0;
            }

            _tgaImage = tga.RawData;
            Parallel.For(0, _height, AddLineToState);
            _tgaImage = null;

            _stateDivisor++;
        }
        public void Convert(TargaImage tga, BitmapImage bmp)
        {
            if (tga == null)
            {
                throw new ArgumentNullException(nameof(tga));
            }
            if (bmp == null)
            {
                throw new ArgumentNullException(nameof(bmp));
            }
            if (tga.RawData.Length != _tgaSize)
            {
                throw new ArgumentException("Invalid TGA Image dimensions.", nameof(tga));
            }
            if (bmp.RawData.Length != _bmpSize)
            {
                throw new ArgumentException("Invalid BMP Image dimensions.", nameof(bmp));
            }

            _tgaImage = tga.RawData;
            _bmpImage = bmp.RawData;
            Parallel.For(0, _height, FlipLineY);
        }