Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ImageCodecs.Register(HeifImageDecoder.Registration);
- `DecodeOptions`: `Region` (a crop; TIFF and HEIF read only the strips or tiles it touches, JPEG, PNG and WebP convert only its rows), `ScaleDenominator` (any power of two for every codec: JPEG 1/2–1/8 and JPEG 2000 resolution levels natively, the rest by a box filter; `TryGetClosestSize` says what a codec does natively), `Pool` (an `ArrayPool<byte>` for the pixels), `ApplyOrientation` (EXIF / TIFF orientation applied, the Exif Orientation reset to 1; `GetOutputSize(info)` sizes a buffer). Every entry point takes a `CancellationToken`.
- `ImageCodecs.TryReadInfo(file, out info)`: from the headers alone: format, size, stored bit depth, colour encoding (PQ / HLG HDR?), resolution (DPI), EXIF orientation, frame or page count, whether there is a thumbnail.
- `ImageCodecs.TryReadMetadata(file, out metadata)` / `TryDecodeThumbnail(file, out thumb)`: the Exif, XMP and ICC blocks for a transcoder to pass on, and the embedded preview (Exif IFD1, HEIF `thmb`). `PixelTransform.Orient` turns pixels you decoded without `ApplyOrientation`.
- `ImageDecoder.Open(stream | path | memory)` / `OpenAsync(stream)`: a WIC-style session: `Format`, `FrameCount`, then `GetFrame(i).Decode(options)` or `.CopyPixels(region, format, buffer, stride)`. A file path is memory-mapped; a non-seekable stream such as an upload is buffered for you.
- `ImageDecoder.Open(stream | path | memory)` / `OpenAsync(stream)`: a WIC-style session: `Format`, `FrameCount`, then `GetFrame(i).Decode(options)` or `.CopyPixels(region, format, buffer, stride)`. A file path is memory-mapped. A stream is read only as far as its header at open; when the codec decodes from a stream, the first full-size decode of frame 0 reads its rows as they arrive (`await frame.DecodeAsync()` / `CopyPixelsAsync` for a request body), and anything that needs the file again reads it whole first, from the bytes a non-seekable stream keeps as it is read. `Open(stream, leaveOpen, forwardOnly: true)` keeps nothing, so a single streamed decode never holds the file, and a later revisit throws `InvalidOperationException`.
- `ImageCodecs.TryOpenFrames(file, out reader)`: every frame by index, in any layout: animated WebP / GIF / APNG frames with durations, multi-page TIFF and JBIG2 pages, the images of an icon. `reader.EnumerateFramesInto(buffer, stride, format)` plays them through one buffer.
- `ImageCodecs.Encode(image, format, stream | writer, options)` / `Encode(pixels, width, height, pixelFormat, format, …)` / `CreateEncoder(format, writer)`: every encoder takes every `PixelFormat`, rows at any stride, and writes the image's metadata; `GetClosestInputFormat` shows where an 8-bit format narrows. The options are the format's own type (`JpegEncodeOptions`, `WebpLossyEncodeOptions`, …; null for its defaults); WebP with no options is lossy. An encoder session takes the image in bands and several frames for an animation.
- `ImageCodecs.TryReadPlanarInfo` / `TryDecodePlanes`: the YCbCr planes as coded (HEIF), for video pipelines and GPU upload.
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ImageCodecs.Register(HeifImageDecoder.Registration);
- `DecodeOptions`:`Region`(裁剪;TIFF 和 HEIF 只读与区域相交的条带或分块,JPEG、PNG、WebP 只转换区域内的行)、`ScaleDenominator`(每个 codec 都接受任意 2 的幂:JPEG 的 1/2–1/8 和 JPEG 2000 的分辨率级别是原生的,其余用 box 滤波;`TryGetClosestSize` 告诉你 codec 原生能做到什么)、`Pool`(像素用的 `ArrayPool<byte>`)、`ApplyOrientation`(应用 EXIF / TIFF 方向,Exif 里的方向改写为 1;缓冲区尺寸用 `GetOutputSize(info)` 算)。所有入口都接受 `CancellationToken`。
- `ImageCodecs.TryReadInfo(file, out info)`:只读文件头:格式、尺寸、存储位深、颜色编码(是不是 PQ / HLG HDR)、分辨率(DPI)、EXIF 方向、帧数或页数、有没有缩略图。
- `ImageCodecs.TryReadMetadata(file, out metadata)` / `TryDecodeThumbnail(file, out thumb)`:取出 Exif、XMP、ICC 原始块供转码透传,以及内嵌的预览图(Exif IFD1、HEIF `thmb`)。没开 `ApplyOrientation` 解出的像素,可以事后用 `PixelTransform.Orient` 转正。
- `ImageDecoder.Open(stream | path | memory)` / `OpenAsync(stream)`:WIC 式的会话:`Format`、`FrameCount`,再 `GetFrame(i).Decode(options)` 或 `.CopyPixels(region, format, buffer, stride)`。文件路径用内存映射;上传这类不可寻址的流会替你缓冲。
- `ImageDecoder.Open(stream | path | memory)` / `OpenAsync(stream)`:WIC 式的会话:`Format`、`FrameCount`,再 `GetFrame(i).Decode(options)` 或 `.CopyPixels(region, format, buffer, stride)`。文件路径用内存映射。打开流时只读到头部为止;编解码器支持从流解码时,第 0 帧第一次全尺寸解码直接按到达的数据逐行读取(请求体用 `await frame.DecodeAsync()` / `CopyPixelsAsync`),之后需要再次读文件的操作先读入整个文件,不可寻址的流用的是读取时保留下来的字节。`Open(stream, leaveOpen, forwardOnly: true)` 不保留任何字节,一次流式解码从不持有整个文件,之后再回头读会抛 `InvalidOperationException`。
- `ImageCodecs.TryOpenFrames(file, out reader)`:按索引、以任意布局逐帧解码:动画 WebP / GIF / APNG 的帧及其时长,多页 TIFF 和 JBIG2 的各页,图标里的每张图。`reader.EnumerateFramesInto(buffer, stride, format)` 用同一块缓冲区按顺序播放。
- `ImageCodecs.Encode(image, format, stream | writer, options)` / `Encode(pixels, width, height, pixelFormat, format, …)` / `CreateEncoder(format, writer)`:每个编码器都接收任意 `PixelFormat` 和任意行跨度,并写入图像的元数据;只能存 8 位的格式会在哪里降精度,用 `GetClosestInputFormat` 可以先看到。options 是该格式自己的类型(`JpegEncodeOptions`、`WebpLossyEncodeOptions` 等;null 表示默认值);WebP 不传 options 时为有损。编码会话可以按行带分批写入,也可以写多帧动画。
- `ImageCodecs.TryReadPlanarInfo` / `TryDecodePlanes`:按编码原样输出 YCbCr 平面(HEIF),供视频管线和 GPU 上传使用。
Expand Down
Loading