protected static void TestTiffEncoderCore <TPixel>( TestImageProvider <TPixel> provider, TiffBitsPerPixel?bitsPerPixel, TiffPhotometricInterpretation photometricInterpretation, TiffCompression compression = TiffCompression.None, TiffPredictor predictor = TiffPredictor.None, bool useExactComparer = true, float compareTolerance = 0.001f, IImageDecoder imageDecoder = null) where TPixel : unmanaged, IPixel <TPixel> { using Image <TPixel> image = provider.GetImage(); var encoder = new TiffEncoder { PhotometricInterpretation = photometricInterpretation, BitsPerPixel = bitsPerPixel, Compression = compression, HorizontalPredictor = predictor }; // Does DebugSave & load reference CompareToReferenceInput(): image.VerifyEncoder( provider, "tiff", bitsPerPixel, encoder, useExactComparer ? ImageComparer.Exact : ImageComparer.Tolerant(compareTolerance), referenceDecoder: imageDecoder ?? ReferenceDecoder); }
public static TiffBaseCompressor Create( TiffCompression method, Stream output, MemoryAllocator allocator, int width, int bitsPerPixel, DeflateCompressionLevel compressionLevel, TiffPredictor predictor) { switch (method) { // The following compression types are not implemented in the encoder and will default to no compression instead. case TiffCompression.ItuTRecT43: case TiffCompression.ItuTRecT82: case TiffCompression.OldJpeg: case TiffCompression.OldDeflate: case TiffCompression.None: DebugGuard.IsTrue(compressionLevel == DeflateCompressionLevel.DefaultCompression, "No deflate compression level is expected to be set"); DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new NoCompressor(output, allocator, width, bitsPerPixel)); case TiffCompression.Jpeg: DebugGuard.IsTrue(compressionLevel == DeflateCompressionLevel.DefaultCompression, "No deflate compression level is expected to be set"); DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new TiffJpegCompressor(output, allocator, width, bitsPerPixel)); case TiffCompression.PackBits: DebugGuard.IsTrue(compressionLevel == DeflateCompressionLevel.DefaultCompression, "No deflate compression level is expected to be set"); DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new PackBitsCompressor(output, allocator, width, bitsPerPixel)); case TiffCompression.Deflate: return(new DeflateCompressor(output, allocator, width, bitsPerPixel, predictor, compressionLevel)); case TiffCompression.Lzw: DebugGuard.IsTrue(compressionLevel == DeflateCompressionLevel.DefaultCompression, "No deflate compression level is expected to be set"); return(new LzwCompressor(output, allocator, width, bitsPerPixel, predictor)); case TiffCompression.CcittGroup3Fax: DebugGuard.IsTrue(compressionLevel == DeflateCompressionLevel.DefaultCompression, "No deflate compression level is expected to be set"); DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new T4BitCompressor(output, allocator, width, bitsPerPixel, false)); case TiffCompression.CcittGroup4Fax: DebugGuard.IsTrue(compressionLevel == DeflateCompressionLevel.DefaultCompression, "No deflate compression level is expected to be set"); DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new T6BitCompressor(output, allocator, width, bitsPerPixel)); case TiffCompression.Ccitt1D: DebugGuard.IsTrue(compressionLevel == DeflateCompressionLevel.DefaultCompression, "No deflate compression level is expected to be set"); DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new T4BitCompressor(output, allocator, width, bitsPerPixel, true)); default: throw TiffThrowHelper.NotSupportedCompressor(method.ToString()); } }
public static TiffBaseDecompressor Create( Configuration configuration, TiffDecoderCompressionType method, MemoryAllocator allocator, TiffPhotometricInterpretation photometricInterpretation, int width, int bitsPerPixel, TiffColorType colorType, TiffPredictor predictor, FaxCompressionOptions faxOptions, byte[] jpegTables, TiffFillOrder fillOrder, ByteOrder byteOrder) { switch (method) { case TiffDecoderCompressionType.None: DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); DebugGuard.IsTrue(faxOptions == FaxCompressionOptions.None, "No fax compression options are expected"); return(new NoneTiffCompression(allocator, width, bitsPerPixel)); case TiffDecoderCompressionType.PackBits: DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); DebugGuard.IsTrue(faxOptions == FaxCompressionOptions.None, "No fax compression options are expected"); return(new PackBitsTiffCompression(allocator, width, bitsPerPixel)); case TiffDecoderCompressionType.Deflate: DebugGuard.IsTrue(faxOptions == FaxCompressionOptions.None, "No fax compression options are expected"); return(new DeflateTiffCompression(allocator, width, bitsPerPixel, colorType, predictor, byteOrder == ByteOrder.BigEndian)); case TiffDecoderCompressionType.Lzw: DebugGuard.IsTrue(faxOptions == FaxCompressionOptions.None, "No fax compression options are expected"); return(new LzwTiffCompression(allocator, width, bitsPerPixel, colorType, predictor, byteOrder == ByteOrder.BigEndian)); case TiffDecoderCompressionType.T4: DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new T4TiffCompression(allocator, fillOrder, width, bitsPerPixel, faxOptions, photometricInterpretation)); case TiffDecoderCompressionType.T6: DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new T6TiffCompression(allocator, fillOrder, width, bitsPerPixel, photometricInterpretation)); case TiffDecoderCompressionType.HuffmanRle: DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new ModifiedHuffmanTiffCompression(allocator, fillOrder, width, bitsPerPixel, photometricInterpretation)); case TiffDecoderCompressionType.Jpeg: DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression"); return(new JpegTiffCompression(configuration, allocator, width, bitsPerPixel, jpegTables, photometricInterpretation)); default: throw TiffThrowHelper.NotSupportedDecompressor(nameof(method)); } }
/// <summary> /// Initializes a new instance of the <see cref="TiffBaseCompressor"/> class. /// </summary> /// <param name="output">The output stream to write the compressed image to.</param> /// <param name="allocator">The memory allocator.</param> /// <param name="width">The image width.</param> /// <param name="bitsPerPixel">Bits per pixel.</param> /// <param name="predictor">The predictor to use (should only be used with deflate or lzw compression). Defaults to none.</param> protected TiffBaseCompressor(Stream output, MemoryAllocator allocator, int width, int bitsPerPixel, TiffPredictor predictor = TiffPredictor.None) : base(allocator, width, bitsPerPixel, predictor) => this.Output = output;
/// <summary> /// Initialize the middleware. /// </summary> /// <param name="bytesPerScanlines">Byte count per scanline.</param> /// <param name="bitsPerSample">Bits per sample.</param> /// <param name="predictor">The predictor tag.</param> public TiffReversePredictorMiddleware(TiffValueCollection <int> bytesPerScanlines, TiffValueCollection <ushort> bitsPerSample, TiffPredictor predictor) { _bytesPerScanlines = bytesPerScanlines; _bitsPerSample = bitsPerSample; _predictor = predictor; }
/// <summary> /// Initializes a new instance of the <see cref="DeflateTiffCompression" /> class. /// </summary> /// <param name="memoryAllocator">The memoryAllocator to use for buffer allocations.</param> /// <param name="width">The image width.</param> /// <param name="bitsPerPixel">The bits used per pixel.</param> /// <param name="colorType">The color type of the pixel data.</param> /// <param name="predictor">The tiff predictor used.</param> /// <param name="isBigEndian">if set to <c>true</c> decodes the pixel data as big endian, otherwise as little endian.</param> public DeflateTiffCompression(MemoryAllocator memoryAllocator, int width, int bitsPerPixel, TiffColorType colorType, TiffPredictor predictor, bool isBigEndian) : base(memoryAllocator, width, bitsPerPixel, predictor) { this.colorType = colorType; this.isBigEndian = isBigEndian; }
public DeflateCompressor(Stream output, MemoryAllocator allocator, int width, int bitsPerPixel, TiffPredictor predictor, DeflateCompressionLevel compressionLevel) : base(output, allocator, width, bitsPerPixel, predictor) => this.compressionLevel = compressionLevel;
/// <summary> /// Initializes a new instance of the <see cref="TiffBaseDecompressor"/> class. /// </summary> /// <param name="memoryAllocator">The memory allocator.</param> /// <param name="width">The width of the image.</param> /// <param name="bitsPerPixel">The bits per pixel.</param> /// <param name="predictor">The predictor.</param> protected TiffBaseDecompressor(MemoryAllocator memoryAllocator, int width, int bitsPerPixel, TiffPredictor predictor = TiffPredictor.None) : base(memoryAllocator, width, bitsPerPixel, predictor) { }
public TiffJpegCompressor(Stream output, MemoryAllocator memoryAllocator, int width, int bitsPerPixel, TiffPredictor predictor = TiffPredictor.None) : base(output, memoryAllocator, width, bitsPerPixel, predictor) { }
/// <summary> /// Initialize the middleware with the specified predictor. /// </summary> /// <param name="predictor"></param> public TiffApplyPredictorMiddleware(TiffPredictor predictor) { _predictor = predictor; }
public LzwCompressor(Stream output, MemoryAllocator allocator, int width, int bitsPerPixel, TiffPredictor predictor) : base(output, allocator, width, bitsPerPixel, predictor) { }
protected TiffBaseCompression(MemoryAllocator allocator, int width, int bitsPerPixel, TiffPredictor predictor = TiffPredictor.None) { this.Allocator = allocator; this.Width = width; this.BitsPerPixel = bitsPerPixel; this.Predictor = predictor; this.BytesPerRow = ((width * bitsPerPixel) + 7) / 8; }