|
|
|
@ -3,9 +3,6 @@ |
|
|
|
|
|
|
|
using System.Buffers.Binary; |
|
|
|
using SixLabors.ImageSharp.Formats.Webp.Lossy; |
|
|
|
using SixLabors.ImageSharp.Metadata.Profiles.Exif; |
|
|
|
using SixLabors.ImageSharp.Metadata.Profiles.Icc; |
|
|
|
using SixLabors.ImageSharp.Metadata.Profiles.Xmp; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Formats.Webp.BitWriter; |
|
|
|
|
|
|
|
@ -394,56 +391,8 @@ internal class Vp8BitWriter : BitWriterBase |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Write the trunks before data trunk.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Think of it as a static method — none of the other members are called except for <see cref="BitWriterBase.scratchBuffer"/></remarks>
|
|
|
|
/// <param name="stream">The stream to write to.</param>
|
|
|
|
/// <param name="width">The width of the image.</param>
|
|
|
|
/// <param name="height">The height of the image.</param>
|
|
|
|
/// <param name="exifProfile">The exif profile.</param>
|
|
|
|
/// <param name="xmpProfile">The XMP profile.</param>
|
|
|
|
/// <param name="iccProfile">The color profile.</param>
|
|
|
|
/// <param name="hasAlpha">Flag indicating, if a alpha channel is present.</param>
|
|
|
|
/// <param name="alphaData">The alpha channel data.</param>
|
|
|
|
/// <param name="alphaDataIsCompressed">Indicates, if the alpha data is compressed.</param>
|
|
|
|
public void WriteTrunksBeforeData( |
|
|
|
Stream stream, |
|
|
|
uint width, |
|
|
|
uint height, |
|
|
|
ExifProfile? exifProfile, |
|
|
|
XmpProfile? xmpProfile, |
|
|
|
IccProfile? iccProfile, |
|
|
|
bool hasAlpha, |
|
|
|
Span<byte> alphaData, |
|
|
|
bool alphaDataIsCompressed) |
|
|
|
{ |
|
|
|
// Write file size later
|
|
|
|
this.WriteRiffHeader(stream, 0); |
|
|
|
|
|
|
|
// Write VP8X, header if necessary.
|
|
|
|
bool isVp8X = exifProfile != null || xmpProfile != null || iccProfile != null || hasAlpha; |
|
|
|
if (isVp8X) |
|
|
|
{ |
|
|
|
this.WriteVp8XHeader(stream, exifProfile, xmpProfile, iccProfile, width, height, hasAlpha); |
|
|
|
|
|
|
|
if (iccProfile != null) |
|
|
|
{ |
|
|
|
this.WriteColorProfile(stream, iccProfile.ToByteArray()); |
|
|
|
} |
|
|
|
|
|
|
|
if (hasAlpha) |
|
|
|
{ |
|
|
|
this.WriteAlphaChunk(stream, alphaData, alphaDataIsCompressed); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Writes the encoded image to the stream.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="stream">The stream to write to.</param>
|
|
|
|
public void WriteEncodedImageToStream(Stream stream) |
|
|
|
/// <inheritdoc />
|
|
|
|
public override void WriteEncodedImageToStream(Stream stream) |
|
|
|
{ |
|
|
|
uint numBytes = (uint)this.NumBytes; |
|
|
|
|
|
|
|
@ -474,31 +423,6 @@ internal class Vp8BitWriter : BitWriterBase |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Write the trunks after data trunk.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Think of it as a static method — none of the other members are called except for <see cref="BitWriterBase.scratchBuffer"/></remarks>
|
|
|
|
/// <param name="stream">The stream to write to.</param>
|
|
|
|
/// <param name="exifProfile">The exif profile.</param>
|
|
|
|
/// <param name="xmpProfile">The XMP profile.</param>
|
|
|
|
public void WriteTrunksAfterData( |
|
|
|
Stream stream, |
|
|
|
ExifProfile? exifProfile, |
|
|
|
XmpProfile? xmpProfile) |
|
|
|
{ |
|
|
|
if (exifProfile != null) |
|
|
|
{ |
|
|
|
this.WriteMetadataProfile(stream, exifProfile.ToByteArray(), WebpChunkType.Exif); |
|
|
|
} |
|
|
|
|
|
|
|
if (xmpProfile != null) |
|
|
|
{ |
|
|
|
this.WriteMetadataProfile(stream, xmpProfile.Data, WebpChunkType.Xmp); |
|
|
|
} |
|
|
|
|
|
|
|
OverwriteFileSize(stream); |
|
|
|
} |
|
|
|
|
|
|
|
private uint GeneratePartition0() |
|
|
|
{ |
|
|
|
this.PutBitUniform(0); // colorspace
|
|
|
|
|