/// <inheritdoc/> public void Encode <TPixel>(Image <TPixel> image, Stream stream) where TPixel : unmanaged, IPixel <TPixel> { var encode = new TiffEncoderCore(this, image.GetMemoryAllocator()); encode.Encode(image, stream); }
/// <inheritdoc/> public Task EncodeAsync <TPixel>(Image <TPixel> image, Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel <TPixel> { var encoder = new TiffEncoderCore(this, image.GetMemoryAllocator()); return(encoder.EncodeAsync(image, stream, cancellationToken)); }
private static ushort GetCompressionType(TiffEncoderCore encoder) { switch (encoder.CompressionType) { case TiffCompression.Deflate: // Deflate is allowed for all modes. return((ushort)TiffCompression.Deflate); case TiffCompression.PackBits: // PackBits is allowed for all modes. return((ushort)TiffCompression.PackBits); case TiffCompression.Lzw: if (encoder.PhotometricInterpretation == TiffPhotometricInterpretation.Rgb || encoder.PhotometricInterpretation == TiffPhotometricInterpretation.PaletteColor || encoder.PhotometricInterpretation == TiffPhotometricInterpretation.BlackIsZero) { return((ushort)TiffCompression.Lzw); } break; case TiffCompression.CcittGroup3Fax: return((ushort)TiffCompression.CcittGroup3Fax); case TiffCompression.Ccitt1D: return((ushort)TiffCompression.Ccitt1D); case TiffCompression.Jpeg: return((ushort)TiffCompression.Jpeg); } return((ushort)TiffCompression.None); }
private static uint GetSamplesPerPixel(TiffEncoderCore encoder) { switch (encoder.PhotometricInterpretation) { case TiffPhotometricInterpretation.PaletteColor: case TiffPhotometricInterpretation.BlackIsZero: case TiffPhotometricInterpretation.WhiteIsZero: return(1); case TiffPhotometricInterpretation.Rgb: default: return(3); } }
public void Process(TiffEncoderCore encoder) { var planarConfig = new ExifShort(ExifTagValue.PlanarConfiguration) { Value = (ushort)TiffPlanarConfiguration.Chunky }; var samplesPerPixel = new ExifLong(ExifTagValue.SamplesPerPixel) { Value = GetSamplesPerPixel(encoder) }; ushort[] bitsPerSampleValue = GetBitsPerSampleValue(encoder); var bitPerSample = new ExifShortArray(ExifTagValue.BitsPerSample) { Value = bitsPerSampleValue }; ushort compressionType = GetCompressionType(encoder); var compression = new ExifShort(ExifTagValue.Compression) { Value = compressionType }; var photometricInterpretation = new ExifShort(ExifTagValue.PhotometricInterpretation) { Value = (ushort)encoder.PhotometricInterpretation }; this.Collector.AddOrReplace(planarConfig); this.Collector.AddOrReplace(samplesPerPixel); this.Collector.AddOrReplace(bitPerSample); this.Collector.AddOrReplace(compression); this.Collector.AddOrReplace(photometricInterpretation); if (encoder.HorizontalPredictor == TiffPredictor.Horizontal) { if (encoder.PhotometricInterpretation == TiffPhotometricInterpretation.Rgb || encoder.PhotometricInterpretation == TiffPhotometricInterpretation.PaletteColor || encoder.PhotometricInterpretation == TiffPhotometricInterpretation.BlackIsZero) { var predictor = new ExifShort(ExifTagValue.Predictor) { Value = (ushort)TiffPredictor.Horizontal }; this.Collector.AddOrReplace(predictor); } } }
private static ushort[] GetBitsPerSampleValue(TiffEncoderCore encoder) { switch (encoder.PhotometricInterpretation) { case TiffPhotometricInterpretation.PaletteColor: if (encoder.BitsPerPixel == TiffBitsPerPixel.Bit4) { return(TiffConstants.BitsPerSample4Bit.ToArray()); } else { return(TiffConstants.BitsPerSample8Bit.ToArray()); } case TiffPhotometricInterpretation.Rgb: return(TiffConstants.BitsPerSampleRgb8Bit.ToArray()); case TiffPhotometricInterpretation.WhiteIsZero: if (encoder.BitsPerPixel == TiffBitsPerPixel.Bit1) { return(TiffConstants.BitsPerSample1Bit.ToArray()); } return(TiffConstants.BitsPerSample8Bit.ToArray()); case TiffPhotometricInterpretation.BlackIsZero: if (encoder.BitsPerPixel == TiffBitsPerPixel.Bit1) { return(TiffConstants.BitsPerSample1Bit.ToArray()); } return(TiffConstants.BitsPerSample8Bit.ToArray()); default: return(TiffConstants.BitsPerSampleRgb8Bit.ToArray()); } }
public void ProcessImageFormat(TiffEncoderCore encoder) => new ImageFormatProcessor(this).Process(encoder);