Exemple #1
0
        /// <summary>
        /// Reads an individual gif frame.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="image">The image to decode the information to.</param>
        /// <param name="previousFrame">The previous frame.</param>
        private void ReadFrame <TPixel>(ref Image <TPixel> image, ref ImageFrame <TPixel> previousFrame)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            this.ReadImageDescriptor();

            IManagedByteBuffer localColorTable = null;
            Buffer2D <byte>    indices         = null;

            try
            {
                // Determine the color table for this frame. If there is a local one, use it otherwise use the global color table.
                if (this.imageDescriptor.LocalColorTableFlag)
                {
                    int length = this.imageDescriptor.LocalColorTableSize * 3;
                    localColorTable = this.configuration.MemoryAllocator.AllocateManagedByteBuffer(length, AllocationOptions.Clean);
                    this.stream.Read(localColorTable.Array, 0, length);
                }

                indices = this.configuration.MemoryAllocator.Allocate2D <byte>(this.imageDescriptor.Width, this.imageDescriptor.Height, AllocationOptions.Clean);

                this.ReadFrameIndices(indices);
                ReadOnlySpan <Rgb24> colorTable = MemoryMarshal.Cast <byte, Rgb24>((localColorTable ?? this.globalColorTable).GetSpan());
                this.ReadFrameColors(ref image, ref previousFrame, indices, colorTable, this.imageDescriptor);

                // Skip any remaining blocks
                this.SkipBlock();
            }
            finally
            {
                localColorTable?.Dispose();
                indices?.Dispose();
            }
        }
Exemple #2
0
 public void Dispose()
 {
     Unlock();
     if (buffer2D != null)
     {
         buffer2D.Dispose();
     }
     buffer.Dispose();
 }