Class ImageBuffers

java.lang.Object
cloud.opencode.base.image.buffer.ImageBuffers

public final class ImageBuffers extends Object
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 Details

    • ensure

      public static Raster ensure(Raster dst, int w, int h, PixelFormat expectedFormat)
      Returns dst when it matches (w, h, expectedFormat); otherwise allocates a freshly zero-filled Raster. A null dst always allocates. 当 dst 匹配 (w, h, expectedFormat) 时直接复用;否则分配新 Rasterdst 为 null 时总是分配。
      Parameters:
      dst - caller-provided raster, may be null | 调用方提供的 raster,可为 null
      w - 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

      public static Raster require(Raster dst, int w, int h, PixelFormat expectedFormat)
      Throwing variant for Raster — 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,不能为 null
      w - required width | 所需宽度
      h - required height | 所需高度
      expectedFormat - required pixel format | 所需像素格式
      Returns:
      dst when all constraints match | 全部匹配时返回 dst
      Throws:
      IllegalArgumentException - when dst is null, size or format mismatch
      Since:
      opencode-base-image V1.0.4