Class ImageBuffers
java.lang.Object
cloud.opencode.base.image.buffer.ImageBuffers
Output buffer factory and validator for reusable image operators.
可复用图像算子的输出缓冲工厂与校验工具。
Operators that accept a dst parameter use these helpers to
validate the caller-provided buffer, or allocate one that matches the
required type/size. A null dst always falls back to the
allocate-per-call behavior of the original API, preserving binary
compatibility.
接受 dst 参数的算子用这里的方法校验调用方传入的缓冲,或按所需类型
与尺寸分配新缓冲。dst 为 null 时回退到原有 API 的每次分配行为,保持
二进制兼容。
- Since:
- JDK 25, opencode-base-image V1.0.4
- Author:
- Leon Soo
-
Method Summary
Modifier and TypeMethodDescriptionstatic Rasterensure(Raster dst, int w, int h, PixelFormat expectedFormat) Returnsdstwhen it matches (w, h, expectedFormat); otherwise allocates a freshly zero-filledRaster.static Rasterrequire(Raster dst, int w, int h, PixelFormat expectedFormat) Throwing variant forRaster— fails fast when caller passed a mismatched raster, intended for performance-critical paths that must not silently allocate.
-
Method Details
-
ensure
Returnsdstwhen it matches (w, h, expectedFormat); otherwise allocates a freshly zero-filledRaster. A nulldstalways allocates. 当dst匹配 (w, h, expectedFormat) 时直接复用;否则分配新Raster。dst为 null 时总是分配。- Parameters:
dst- caller-provided raster, may be null | 调用方提供的 raster,可为 nullw- required width | 所需宽度h- required height | 所需高度expectedFormat- required pixel format | 所需像素格式- Returns:
- a raster guaranteed to match the required spec | 保证匹配所需规格的 raster
- Since:
- opencode-base-image V1.0.4
-
require
Throwing variant forRaster— fails fast when caller passed a mismatched raster, intended for performance-critical paths that must not silently allocate. 严格模式(针对Raster)——调用方传入尺寸/格式不匹配时直接报错, 避免在关键路径上静默分配。- Parameters:
dst- caller-provided raster, must not be null | 调用方提供的 raster,不能为 nullw- required width | 所需宽度h- required height | 所需高度expectedFormat- required pixel format | 所需像素格式- Returns:
dstwhen all constraints match | 全部匹配时返回 dst- Throws:
IllegalArgumentException- when dst is null, size or format mismatch- Since:
- opencode-base-image V1.0.4
-