Exemplo n.º 1
0
        /// <summary>
        /// Copy the 2-dimensional pixel data into <paramref name="destination"/>, after skipping some rows and columns specified in <paramref name="offset"/>.
        /// </summary>
        /// <param name="offset">The number rows and columns to skip. X represents the number of columns to skip; Y represents the number of rows to skip.</param>
        /// <param name="destination">The destination writer. It also limits the number of rows and columns to copy.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> that fires if the user want to stop the current task.</param>
        /// <returns>A <see cref="ValueTask"/> that completes when all the requested pixels are copied.</returns>
        public ValueTask ReadAsync(TiffPoint offset, TiffPixelBufferWriter <TPixel> destination, CancellationToken cancellationToken)
        {
            offset = new TiffPoint(offset.X + _offset.X, offset.Y + _offset.Y);
            var readSize = new TiffSize(Math.Min(_size.Width, destination.Width), Math.Min(_size.Height, destination.Height));

            if (readSize.IsAreaEmpty)
            {
                return(default);
Exemplo n.º 2
0
 /// <summary>
 /// Initialize <see cref="TiffPixelBufferWriter{TPixel}"/> to wrap <paramref name="writer"/> and represents the same region as <paramref name="writer"/>.
 /// </summary>
 /// <param name="writer">The pixel buffer writer. If <paramref name="writer"/> is null, <see cref="TiffPixelBufferWriter{TPixel}"/> will be empty and represents an emtry 2-dimensional region.</param>
 public TiffPixelBufferWriter(ITiffPixelBufferWriter <TPixel> writer)
 {
     _writer = writer ?? TiffEmptyPixelBufferWriter <TPixel> .Default;
     if (_writer is TiffPixelBufferWriter <TPixel> structWriter)
     {
         _writer = structWriter._writer;
         _offset = structWriter._offset;
         _size   = structWriter._size;
     }
     else
     {
         _offset = default;
         _size   = new TiffSize(_writer.Width, _writer.Height);
     }
 }
Exemplo n.º 3
0
 internal TiffPixelBufferReader(ITiffPixelBufferReader <TPixel> reader, TiffPoint offset, TiffSize size)
 {
     _reader = reader;
     if (_reader is TiffPixelBufferReader <TPixel> structReader)
     {
         _reader = structReader._reader;
         _offset = structReader._offset;
         _size   = structReader._size;
     }
     else
     {
         _offset = offset;
         _size   = size;
     }
 }
Exemplo n.º 4
0
 internal TiffPixelBufferWriter(ITiffPixelBufferWriter <TPixel> writer, TiffPoint offset, TiffSize size)
 {
     _writer = writer;
     _offset = offset;
     _size   = size;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initialize <see cref="TiffPixelBuffer{TPixel}"/> to wrap <paramref name="buffer"/> and represents the same region as <paramref name="buffer"/>.
 /// </summary>
 /// <param name="buffer">The pixel buffer. If <paramref name="buffer"/> is null, <see cref="TiffPixelBuffer{TPixel}"/> will be empty and represents an emtry 2-dimensional region.</param>
 public TiffPixelBuffer(ITiffPixelBuffer <TPixel> buffer)
 {
     _buffer = buffer ?? TiffEmptyPixelBuffer <TPixel> .Default;
     _offset = default;
     _size   = new TiffSize(_buffer.Width, _buffer.Height);
 }
Exemplo n.º 6
0
 internal TiffPixelBuffer(ITiffPixelBuffer <TPixel> buffer, TiffPoint offset, TiffSize size)
 {
     _buffer = buffer;
     _offset = offset;
     _size   = size;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Crop a sub region from <paramref name="writer"/>.
        /// </summary>
        /// <typeparam name="TPixel">The pixel type.</typeparam>
        /// <param name="writer">The original pixel buffer.</param>
        /// <param name="offset">The number of columns and rows to skip.</param>
        /// <param name="size">The number of columns and rows to take.</param>
        /// <returns>A <see cref="TiffPixelBuffer{TPixel}"/> representing the cropped region.</returns>
        public static TiffPixelBufferWriter <TPixel> Crop <TPixel>(this TiffPixelBufferWriter <TPixel> writer, TiffPoint offset, TiffSize size) where TPixel : unmanaged
        {
            if ((uint)offset.X > (uint)writer._size.Width)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            if ((uint)offset.Y > (uint)writer._size.Height)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            int offsetX = writer._offset.X + offset.X;
            int offsetY = writer._offset.Y + offset.Y;

            if ((uint)offsetX > (uint)writer._size.Width)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            if ((uint)offsetY > (uint)writer._size.Height)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            int sizeWidth  = writer._size.Width - offset.X;
            int sizeHeight = writer._size.Height - offset.Y;

            if ((uint)size.Width > (uint)sizeWidth)
            {
                throw new ArgumentOutOfRangeException(nameof(size));
            }
            if ((uint)size.Height > (uint)sizeHeight)
            {
                throw new ArgumentOutOfRangeException(nameof(size));
            }
            return(new TiffPixelBufferWriter <TPixel>(writer._writer, new TiffPoint(offsetX, offsetY), size));
        }
Exemplo n.º 8
0
 /// <summary>
 /// Crop a sub region from <paramref name="writer"/>.
 /// </summary>
 /// <typeparam name="TPixel">The pixel type.</typeparam>
 /// <param name="writer">The original pixel buffer.</param>
 /// <param name="offset">The number of columns and rows to skip.</param>
 /// <param name="size">The number of columns and rows to take.</param>
 /// <returns>A <see cref="TiffPixelBuffer{TPixel}"/> representing the cropped region.</returns>
 public static TiffPixelBufferWriter <TPixel> Crop <TPixel>(this ITiffPixelBufferWriter <TPixel> writer, TiffPoint offset, TiffSize size) where TPixel : unmanaged
 {
     if (writer is TiffPixelBufferWriter <TPixel> structWriter)
     {
         return(structWriter.Crop(offset, size));
     }
     return(writer.AsPixelBufferWriter().Crop(offset, size));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Crop a sub region from <paramref name="buffer"/>.
 /// </summary>
 /// <typeparam name="TPixel">The pixel type.</typeparam>
 /// <param name="buffer">The original pixel buffer.</param>
 /// <param name="offset">The number of columns and rows to skip.</param>
 /// <param name="size">The number of columns and rows to take.</param>
 /// <returns>A <see cref="TiffPixelBuffer{TPixel}"/> representing the cropped region.</returns>
 public static TiffPixelBuffer <TPixel> Crop <TPixel>(this ITiffPixelBuffer <TPixel> buffer, TiffPoint offset, TiffSize size) where TPixel : unmanaged
 {
     return(buffer.AsPixelBuffer().Crop(offset, size));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Encode an image as well as associated tag fields into TIFF stream.
 /// </summary>
 /// <param name="writer">The <see cref="TiffImageFileDirectoryWriter"/> object to write encoded image data and fields to.</param>
 /// <param name="offset">The number of columns and rows to skip in <paramref name="reader"/>.</param>
 /// <param name="size">The number of columns and rows to encode in <paramref name="reader"/>.</param>
 /// <param name="reader">The pixel buffer reader.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> that fires if the user has requested to abort the encoding pipeline.</param>
 /// <returns>A <see cref="Task"/> that completes when the image and fields have been encoded.</returns>
 public abstract Task EncodeAsync(TiffImageFileDirectoryWriter writer, TiffPoint offset, TiffSize size, ITiffPixelBufferReader <TPixel> reader, CancellationToken cancellationToken = default);
Exemplo n.º 11
0
 /// <summary>
 /// Encode a single image without writing any IFD tag fields.
 /// </summary>
 /// <param name="writer">The <see cref="TiffFileWriter"/> object to write encoded image data to.</param>
 /// <param name="offset">The number of columns and rows to skip in <paramref name="reader"/>.</param>
 /// <param name="size">The number of columns and rows to encode in <paramref name="reader"/>.</param>
 /// <param name="reader">The pixel buffer reader object.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> that fires if the user has requested to abort the encoding pipeline.</param>
 /// <returns>A <see cref="Task{TiffStreamRegion}"/> that completes and return the position and length written into the stream when the image has been encoded.</returns>
 public abstract Task <TiffStreamRegion> EncodeAsync(TiffFileWriter writer, TiffPoint offset, TiffSize size, ITiffPixelBufferReader <TPixel> reader, CancellationToken cancellationToken = default);
Exemplo n.º 12
0
 /// <summary>
 /// Initialize <see cref="TiffPixelBufferReader{TPixel}"/> to wrap <paramref name="reader"/>.
 /// </summary>
 /// <param name="reader">The reader to wrap.</param>
 public TiffPixelBufferReader(ITiffPixelBufferReader <TPixel> reader)
 {
     _reader = reader ?? TiffEmptyPixelBufferReader <TPixel> .Default;
     _offset = default;
     _size   = new TiffSize(_reader.Width, _reader.Height);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Decode the image into the specified pixel buffer writer.
 /// </summary>
 /// <typeparam name="TPixel">The pixel type.</typeparam>
 /// <param name="offset">Number of columns and rows to skip in the source image.</param>
 /// <param name="readSize">Number of columns and rows to read from the source image.</param>
 /// <param name="destinationOffset">Number of columns and rows to skip in the destination writer.</param>
 /// <param name="writer">The pixel buffer writer to write pixels into.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> that fires if the user has requested to abort the decoding pipeline.</param>
 /// <returns>A <see cref="Task"/> that completes when the image has been decoded.</returns>
 public abstract Task DecodeAsync <TPixel>(TiffPoint offset, TiffSize readSize, TiffPoint destinationOffset, ITiffPixelBufferWriter <TPixel> writer, CancellationToken cancellationToken = default) where TPixel : unmanaged;
Exemplo n.º 14
0
 /// <summary>
 /// Decode the image into the specified pixel buffer writer.
 /// </summary>
 /// <typeparam name="TPixel">The pixel type.</typeparam>
 /// <param name="offset">Number of columns and rows to skip in the source image.</param>
 /// <param name="readSize">Number of columns and rows to read from the source image.</param>
 /// <param name="destinationOffset">Number of columns and rows to skip in the destination writer.</param>
 /// <param name="writer">The pixel buffer writer to write pixels into.</param>
 public abstract void Decode <TPixel>(TiffPoint offset, TiffSize readSize, TiffPoint destinationOffset, ITiffPixelBufferWriter <TPixel> writer) where TPixel : unmanaged;