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 void AddColorMapTag() { using IMemoryOwner <byte> colorPaletteBuffer = this.MemoryAllocator.Allocate <byte>(this.colorPaletteBytes); Span <byte> colorPalette = colorPaletteBuffer.GetSpan(); ReadOnlySpan <TPixel> quantizedColors = this.quantizedImage.Palette.Span; int quantizedColorBytes = quantizedColors.Length * 3 * 2; // In the ColorMap, black is represented by 0, 0, 0 and white is represented by 65535, 65535, 65535. Span <Rgb48> quantizedColorRgb48 = MemoryMarshal.Cast <byte, Rgb48>(colorPalette.Slice(0, quantizedColorBytes)); PixelOperations <TPixel> .Instance.ToRgb48(this.Configuration, quantizedColors, quantizedColorRgb48); // It can happen that the quantized colors are less than the expected maximum per channel. int diffToMaxColors = this.maxColors - quantizedColors.Length; // In a TIFF ColorMap, all the Red values come first, followed by the Green values, // then the Blue values. Convert the quantized palette to this format. var palette = new ushort[this.colorPaletteSize]; int paletteIdx = 0; for (int i = 0; i < quantizedColors.Length; i++) { palette[paletteIdx++] = quantizedColorRgb48[i].R; } paletteIdx += diffToMaxColors; for (int i = 0; i < quantizedColors.Length; i++) { palette[paletteIdx++] = quantizedColorRgb48[i].G; } paletteIdx += diffToMaxColors; for (int i = 0; i < quantizedColors.Length; i++) { palette[paletteIdx++] = quantizedColorRgb48[i].B; } var colorMap = new ExifShortArray(ExifTagValue.ColorMap) { Value = palette }; this.EntriesCollector.AddOrReplace(colorMap); }
/// <summary> /// Gets a new <see cref="ExifShortArray"/> instance for the <see cref="ExifTag.PixelYDimension"/> tag. /// </summary> /// <param name="value">The value.</param> /// <returns>A new <see cref="ExifShortArray"/> instance.</returns> public static ExifShortArray PixelYDimension(ushort[] value) => ExifShortArray.Create(ExifTag.PixelYDimension, value);
/// <summary> /// Gets a new <see cref="ExifShortArray"/> instance for the <see cref="ExifTag.ConsecutiveBadFaxLines"/> tag. /// </summary> /// <param name="value">The value.</param> /// <returns>A new <see cref="ExifShortArray"/> instance.</returns> public static ExifShortArray ConsecutiveBadFaxLines(ushort[] value) => ExifShortArray.Create(ExifTag.ConsecutiveBadFaxLines, value);
/// <summary> /// Gets a new <see cref="ExifShortArray"/> instance for the <see cref="ExifTag.BadFaxLines"/> tag. /// </summary> /// <param name="value">The value.</param> /// <returns>A new <see cref="ExifShortArray"/> instance.</returns> public static ExifShortArray BadFaxLines(ushort[] value) => ExifShortArray.Create(ExifTag.BadFaxLines, value);
/// <summary> /// Gets a new <see cref="ExifShortArray"/> instance for the <see cref="ExifTag.TileLength"/> tag. /// </summary> /// <param name="value">The value.</param> /// <returns>A new <see cref="ExifShortArray"/> instance.</returns> public static ExifShortArray TileLength(ushort[] value) => ExifShortArray.Create(ExifTag.TileLength, value);
/// <summary> /// Gets a new <see cref="ExifShortArray"/> instance for the <see cref="ExifTag.ImageWidth"/> tag. /// </summary> /// <param name="value">The value.</param> /// <returns>A new <see cref="ExifShortArray"/> instance.</returns> public static ExifShortArray ImageWidth(ushort[] value) => ExifShortArray.Create(ExifTag.ImageWidth, value);