JpegXlTranscoder Class
Converts between JPEG files and JPEG XL files without decoding pixels: a JPEG XL file can hold the quantized coefficients of a JPEG file, about a fifth smaller, with the data that rebuild the JPEG file byte for byte.
public static class JpegXlTranscoderRemarks
These operations work on files, not on images: an Image holds pixels, and a JPEG file cannot be rebuilt from pixels. Image.Load reads the pixels of such a JPEG XL file like the ones of any other.
Nothing is approximated: an input that cannot be converted exactly throws, and the destination is only written once the whole output is known. A path destination is replaced once it is written.
Methods
| Name | Description |
|---|---|
| HasJpegReconstructionData(Stream, JpegXlTranscodeOptions?) | Tells whether a JPEG XL file holds the data that rebuild the JPEG file it was made from. |
| HasJpegReconstructionData(ReadOnlySpan<byte>, JpegXlTranscodeOptions?) | Tells whether a JPEG XL file holds the data that rebuild the JPEG file it was made from. |
| HasJpegReconstructionData(string, JpegXlTranscodeOptions?) | Tells whether a JPEG XL file holds the data that rebuild the JPEG file it was made from. |
| HasJpegReconstructionDataAsync(Stream, JpegXlTranscodeOptions?, CancellationToken) | Asynchronously tells whether a JPEG XL file holds the data that rebuild the JPEG file it was made from. |
| RecompressJpeg(Stream, Stream, JpegXlTranscodeOptions?) | Recompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it: JpegXlTranscoder.ReconstructJpeg gives the JPEG file back, byte for byte. No pixel is decoded, and nothing is lost. |
| RecompressJpeg(ReadOnlySpan<byte>, Stream, JpegXlTranscodeOptions?) | Recompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it: JpegXlTranscoder.ReconstructJpeg gives the JPEG file back, byte for byte. No pixel is decoded, and nothing is lost. |
| RecompressJpeg(string, string, JpegXlTranscodeOptions?) | Recompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it. |
| RecompressJpegAsync(Stream, Stream, JpegXlTranscodeOptions?, CancellationToken) | Asynchronously recompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it. |
| RecompressJpegAsync(string, string, JpegXlTranscodeOptions?, CancellationToken) | Asynchronously recompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it. |
| ReconstructJpeg(Stream, Stream, JpegXlTranscodeOptions?) | Rebuilds the JPEG file a JPEG XL file was made from, byte for byte. |
| ReconstructJpeg(ReadOnlySpan<byte>, Stream, JpegXlTranscodeOptions?) | Rebuilds the JPEG file a JPEG XL file was made from, byte for byte. |
| ReconstructJpeg(string, string, JpegXlTranscodeOptions?) | Rebuilds the JPEG file a JPEG XL file was made from, byte for byte. |
| ReconstructJpegAsync(Stream, Stream, JpegXlTranscodeOptions?, CancellationToken) | Asynchronously rebuilds the JPEG file a JPEG XL file was made from, byte for byte. |
| ReconstructJpegAsync(string, string, JpegXlTranscodeOptions?, CancellationToken) | Asynchronously rebuilds the JPEG file a JPEG XL file was made from, byte for byte. |
| TryReconstructJpeg(Stream, Stream, JpegXlTranscodeOptions?) | Rebuilds the JPEG file a JPEG XL file was made from, byte for byte, when the file holds the data that rebuild it. |
| TryReconstructJpeg(ReadOnlySpan<byte>, Stream, JpegXlTranscodeOptions?) | Rebuilds the JPEG file a JPEG XL file was made from, byte for byte, when the file holds the data that rebuild it. |
| TryReconstructJpeg(string, string, JpegXlTranscodeOptions?) | Rebuilds the JPEG file a JPEG XL file was made from, byte for byte, when the file holds the data that rebuild it. |
| TryReconstructJpegAsync(Stream, Stream, JpegXlTranscodeOptions?, CancellationToken) | Asynchronously rebuilds the JPEG file a JPEG XL file was made from, byte for byte, when the file holds the data that rebuild it. |
HasJpegReconstructionData overloads
HasJpegReconstructionData(Stream, JpegXlTranscodeOptions?)
JpegXlTranscoder.csTells whether a JPEG XL file holds the data that rebuild the JPEG file it was made from.
public static bool HasJpegReconstructionData(Stream jpegXl, JpegXlTranscodeOptions? options = null)Parameters
jpegXlStream- The JPEG XL file.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Returns
bool true when the data are present; they are not validated.
Exceptions
ArgumentNullExceptionjpegXlisnull.ArgumentExceptionjpegXlis not readable.
Remarks
Encoders write the data before the image: the answer is then known from the start of the file, and nothing else is read. When no data precede an image that could be the one of a JPEG file, the rest of the file is read, without decoding it, since the data may follow the image.
HasJpegReconstructionData(ReadOnlySpan<byte>, JpegXlTranscodeOptions?)
JpegXlTranscoder.csTells whether a JPEG XL file holds the data that rebuild the JPEG file it was made from.
public static bool HasJpegReconstructionData(ReadOnlySpan<byte> jpegXl, JpegXlTranscodeOptions? options = null)Parameters
jpegXlReadOnlySpan<byte>- The JPEG XL file.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Returns
bool true when the data are present; they are not validated.
Exceptions
UnknownImageFormatException- The format of the input is not recognized.
UnsupportedImageFeatureException- The input is not a JPEG XL file.
InvalidImageContentException- The part of the file that is read is malformed or truncated.
Remarks
Encoders write the data before the image: the answer is then known from the start of the file, and nothing else is read. When no data precede an image that could be the one of a JPEG file, the rest of the file is read, without decoding it, since the data may follow the image.
HasJpegReconstructionData(string, JpegXlTranscodeOptions?)
JpegXlTranscoder.csTells whether a JPEG XL file holds the data that rebuild the JPEG file it was made from.
public static bool HasJpegReconstructionData(string jpegXlPath, JpegXlTranscodeOptions? options = null)Parameters
jpegXlPathstring- The path of the JPEG XL file.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Returns
bool true when the data are present; they are not validated.
Exceptions
ArgumentNullExceptionjpegXlPathisnull.ArgumentExceptionjpegXlPathis empty.UnknownImageFormatException- The format of the input is not recognized.
UnsupportedImageFeatureException- The input is not a JPEG XL file.
InvalidImageContentException- The part of the file that is read is malformed or truncated.
HasJpegReconstructionDataAsync(Stream, JpegXlTranscodeOptions?, CancellationToken)
JpegXlTranscoder.csAsynchronously tells whether a JPEG XL file holds the data that rebuild the JPEG file it was made from.
public static Task<bool> HasJpegReconstructionDataAsync(Stream jpegXl, JpegXlTranscodeOptions? options = null, CancellationToken cancellationToken = default)Parameters
jpegXlStream- The JPEG XL file.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones. cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task<bool> true when the data are present; they are not validated.
Exceptions
ArgumentNullExceptionjpegXlisnull.ArgumentExceptionjpegXlis not readable.
RecompressJpeg overloads
RecompressJpeg(Stream, Stream, JpegXlTranscodeOptions?)
JpegXlTranscoder.csRecompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it: JpegXlTranscoder.ReconstructJpeg gives the JPEG file back, byte for byte. No pixel is decoded, and nothing is lost.
public static void RecompressJpeg(Stream jpeg, Stream destination, JpegXlTranscodeOptions? options = null)Parameters
jpegStream- The JPEG file.
destinationStream- Receives the JPEG XL file, once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Exceptions
ArgumentNullExceptionjpegordestinationisnull.ArgumentExceptionjpegis not readable, ordestinationis not writable.
RecompressJpeg(ReadOnlySpan<byte>, Stream, JpegXlTranscodeOptions?)
JpegXlTranscoder.csRecompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it: JpegXlTranscoder.ReconstructJpeg gives the JPEG file back, byte for byte. No pixel is decoded, and nothing is lost.
public static void RecompressJpeg(ReadOnlySpan<byte> jpeg, Stream destination, JpegXlTranscodeOptions? options = null)Parameters
jpegReadOnlySpan<byte>- The JPEG file.
destinationStream- Receives the JPEG XL file, once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Exceptions
ArgumentNullExceptiondestinationisnull.ArgumentExceptiondestinationis not writable.UnknownImageFormatException- The format of the input is not recognized.
UnsupportedImageFeatureException- The input is not a JPEG file, or it is a JPEG file that a JPEG XL frame cannot hold: four components, sampling factors other than 1 or 2, arithmetic coding, 12-bit samples, or entropy-coded data that could not be rebuilt byte for byte.
InvalidImageContentException- The file is malformed or truncated.
ImageResourceLimitException- A configured limit is exceeded.
RecompressJpeg(string, string, JpegXlTranscodeOptions?)
JpegXlTranscoder.csRecompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it.
public static void RecompressJpeg(string jpegPath, string destinationPath, JpegXlTranscodeOptions? options = null)Parameters
jpegPathstring- The path of the JPEG file.
destinationPathstring- The path of the JPEG XL file, which is created or replaced once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Exceptions
ArgumentNullExceptionjpegPathordestinationPathisnull.ArgumentExceptionjpegPathordestinationPathis empty.UnknownImageFormatException- The format of the input is not recognized.
UnsupportedImageFeatureException- The input is not a JPEG file, or it is a JPEG file that a JPEG XL frame cannot hold.
InvalidImageContentException- The file is malformed or truncated.
ImageResourceLimitException- A configured limit is exceeded.
RecompressJpegAsync overloads
RecompressJpegAsync(Stream, Stream, JpegXlTranscodeOptions?, CancellationToken)
JpegXlTranscoder.csAsynchronously recompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it.
public static Task RecompressJpegAsync(Stream jpeg, Stream destination, JpegXlTranscodeOptions? options = null, CancellationToken cancellationToken = default)Parameters
jpegStream- The JPEG file.
destinationStream- Receives the JPEG XL file, once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones. cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task A task that completes when the file is written.
Exceptions
ArgumentNullExceptionjpegordestinationisnull.ArgumentExceptionjpegis not readable, ordestinationis not writable.
RecompressJpegAsync(string, string, JpegXlTranscodeOptions?, CancellationToken)
JpegXlTranscoder.csAsynchronously recompresses a JPEG file as a JPEG XL file that holds its quantized coefficients and the data that rebuild it.
public static Task RecompressJpegAsync(string jpegPath, string destinationPath, JpegXlTranscodeOptions? options = null, CancellationToken cancellationToken = default)Parameters
jpegPathstring- The path of the JPEG file.
destinationPathstring- The path of the JPEG XL file, which is created or replaced once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones. cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task A task that completes when the file is written.
Exceptions
ArgumentNullExceptionjpegPathordestinationPathisnull.ArgumentExceptionjpegPathordestinationPathis empty.
ReconstructJpeg overloads
ReconstructJpeg(Stream, Stream, JpegXlTranscodeOptions?)
JpegXlTranscoder.csRebuilds the JPEG file a JPEG XL file was made from, byte for byte.
public static void ReconstructJpeg(Stream jpegXl, Stream destination, JpegXlTranscodeOptions? options = null)Parameters
jpegXlStream- The JPEG XL file.
destinationStream- Receives the JPEG file, once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Exceptions
ArgumentNullExceptionjpegXlordestinationisnull.ArgumentExceptionjpegXlis not readable, ordestinationis not writable.
ReconstructJpeg(ReadOnlySpan<byte>, Stream, JpegXlTranscodeOptions?)
JpegXlTranscoder.csRebuilds the JPEG file a JPEG XL file was made from, byte for byte.
public static void ReconstructJpeg(ReadOnlySpan<byte> jpegXl, Stream destination, JpegXlTranscodeOptions? options = null)Parameters
jpegXlReadOnlySpan<byte>- The JPEG XL file.
destinationStream- Receives the JPEG file, once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Exceptions
ArgumentNullExceptiondestinationisnull.ArgumentExceptiondestinationis not writable.UnknownImageFormatException- The format of the input is not recognized.
UnsupportedImageFeatureException- The input is not a JPEG XL file, or it does not hold the data that rebuild a JPEG file (
JpegXlTranscoder.TryReconstructJpegreturnsfalseinstead). InvalidImageContentException- The file is malformed or truncated, or its reconstruction data do not match its image.
ImageResourceLimitException- A configured limit is exceeded.
ReconstructJpeg(string, string, JpegXlTranscodeOptions?)
JpegXlTranscoder.csRebuilds the JPEG file a JPEG XL file was made from, byte for byte.
public static void ReconstructJpeg(string jpegXlPath, string destinationPath, JpegXlTranscodeOptions? options = null)Parameters
jpegXlPathstring- The path of the JPEG XL file.
destinationPathstring- The path of the JPEG file, which is created or replaced once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Exceptions
ArgumentNullExceptionjpegXlPathordestinationPathisnull.ArgumentExceptionjpegXlPathordestinationPathis empty.UnknownImageFormatException- The format of the input is not recognized.
UnsupportedImageFeatureException- The input is not a JPEG XL file, or it does not hold the data that rebuild a JPEG file.
InvalidImageContentException- The file is malformed or truncated, or its reconstruction data do not match its image.
ImageResourceLimitException- A configured limit is exceeded.
ReconstructJpegAsync overloads
ReconstructJpegAsync(Stream, Stream, JpegXlTranscodeOptions?, CancellationToken)
JpegXlTranscoder.csAsynchronously rebuilds the JPEG file a JPEG XL file was made from, byte for byte.
public static Task ReconstructJpegAsync(Stream jpegXl, Stream destination, JpegXlTranscodeOptions? options = null, CancellationToken cancellationToken = default)Parameters
jpegXlStream- The JPEG XL file.
destinationStream- Receives the JPEG file, once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones. cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task A task that completes when the file is written.
Exceptions
ArgumentNullExceptionjpegXlordestinationisnull.ArgumentExceptionjpegXlis not readable, ordestinationis not writable.
ReconstructJpegAsync(string, string, JpegXlTranscodeOptions?, CancellationToken)
JpegXlTranscoder.csAsynchronously rebuilds the JPEG file a JPEG XL file was made from, byte for byte.
public static Task ReconstructJpegAsync(string jpegXlPath, string destinationPath, JpegXlTranscodeOptions? options = null, CancellationToken cancellationToken = default)Parameters
jpegXlPathstring- The path of the JPEG XL file.
destinationPathstring- The path of the JPEG file, which is created or replaced once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones. cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task A task that completes when the file is written.
Exceptions
ArgumentNullExceptionjpegXlPathordestinationPathisnull.ArgumentExceptionjpegXlPathordestinationPathis empty.
TryReconstructJpeg overloads
TryReconstructJpeg(Stream, Stream, JpegXlTranscodeOptions?)
JpegXlTranscoder.csRebuilds the JPEG file a JPEG XL file was made from, byte for byte, when the file holds the data that rebuild it.
public static bool TryReconstructJpeg(Stream jpegXl, Stream destination, JpegXlTranscodeOptions? options = null)Parameters
jpegXlStream- The JPEG XL file.
destinationStream- Receives the JPEG file, once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Returns
bool false when the file does not hold the data that rebuild a JPEG file: nothing is written.
Exceptions
ArgumentNullExceptionjpegXlordestinationisnull.ArgumentExceptionjpegXlis not readable, ordestinationis not writable.
TryReconstructJpeg(ReadOnlySpan<byte>, Stream, JpegXlTranscodeOptions?)
JpegXlTranscoder.csRebuilds the JPEG file a JPEG XL file was made from, byte for byte, when the file holds the data that rebuild it.
public static bool TryReconstructJpeg(ReadOnlySpan<byte> jpegXl, Stream destination, JpegXlTranscodeOptions? options = null)Parameters
jpegXlReadOnlySpan<byte>- The JPEG XL file.
destinationStream- Receives the JPEG file, once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Returns
bool false when the file does not hold the data that rebuild a JPEG file: nothing is written.
Exceptions
ArgumentNullExceptiondestinationisnull.ArgumentExceptiondestinationis not writable.UnknownImageFormatException- The format of the input is not recognized.
UnsupportedImageFeatureException- The input is not a JPEG XL file.
InvalidImageContentException- The file is malformed or truncated, or its reconstruction data do not match its image.
ImageResourceLimitException- A configured limit is exceeded.
TryReconstructJpeg(string, string, JpegXlTranscodeOptions?)
JpegXlTranscoder.csRebuilds the JPEG file a JPEG XL file was made from, byte for byte, when the file holds the data that rebuild it.
public static bool TryReconstructJpeg(string jpegXlPath, string destinationPath, JpegXlTranscodeOptions? options = null)Parameters
jpegXlPathstring- The path of the JPEG XL file.
destinationPathstring- The path of the JPEG file, which is created or replaced once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones.
Returns
bool false when the file does not hold the data that rebuild a JPEG file: nothing is written.
Exceptions
ArgumentNullExceptionjpegXlPathordestinationPathisnull.ArgumentExceptionjpegXlPathordestinationPathis empty.UnknownImageFormatException- The format of the input is not recognized.
UnsupportedImageFeatureException- The input is not a JPEG XL file.
InvalidImageContentException- The file is malformed or truncated, or its reconstruction data do not match its image.
ImageResourceLimitException- A configured limit is exceeded.
TryReconstructJpegAsync(Stream, Stream, JpegXlTranscodeOptions?, CancellationToken)
JpegXlTranscoder.csAsynchronously rebuilds the JPEG file a JPEG XL file was made from, byte for byte, when the file holds the data that rebuild it.
public static Task<bool> TryReconstructJpegAsync(Stream jpegXl, Stream destination, JpegXlTranscodeOptions? options = null, CancellationToken cancellationToken = default)Parameters
jpegXlStream- The JPEG XL file.
destinationStream- Receives the JPEG file, once it is whole.
optionsJpegXlTranscodeOptions?- The options, or
nullfor the default ones. cancellationTokenCancellationToken- The token to monitor for cancellation requests.
Returns
Task<bool> false when the file does not hold the data that rebuild a JPEG file: nothing is written.
Exceptions
ArgumentNullExceptionjpegXlordestinationisnull.ArgumentExceptionjpegXlis not readable, ordestinationis not writable.