Class ColorProfile

java.lang.Object
cloud.opencode.base.image.codec.color.ColorProfile
All Implemented Interfaces:
AutoCloseable

public final class ColorProfile extends Object implements AutoCloseable
ICC color profile handle backed by an lcms2 cmsHPROFILE. ICC 色彩配置文件句柄,底层为 lcms2 的 cmsHPROFILE

Created via static factories (srgb(), lab(), xyz(), fromIccBytes(byte[])). Must be closed via close() (try-with-resources recommended) — the underlying handle is a heap-allocated lcms2 structure freed by cmsCloseProfile.

通过静态工厂方法(srgb()lab()xyz()fromIccBytes(byte[]))创建。必须通过 close() 释放(建议使用 try-with-resources)— 底层 handle 是 lcms2 在堆上分配的结构体,由 cmsCloseProfile 释放。

Security | 安全性:

  • Thread-safe: No - external synchronization required for shared instances; each instance owns one native handle. - 线程安全: 否 — 共享实例需要外部同步;每个实例拥有一个 native handle。
  • Resource-safe: close() is idempotent and safe to call multiple times. After close, all access throws IllegalStateException. - 资源安全:close() 幂等;关闭后所有访问抛出 IllegalStateException
Since:
JDK 25, opencode-base-image-codec V1.0.4
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • srgb

      public static ColorProfile srgb()
      Creates a built-in sRGB profile (D65 white point, IEC 61966-2-1). 创建内置 sRGB 配置文件(D65 白点,IEC 61966-2-1)。
      Returns:
      open profile, caller must close() | 打开的配置文件,调用方需 close()
      Throws:
      OpenImageCodecException - if lcms2 fails to create the profile | lcms2 创建失败时
    • lab

      public static ColorProfile lab()
      Creates a built-in Lab v4 profile with D50 white point (passes NULL to cmsCreateLab4Profile per lcms2 contract). 创建内置 Lab v4 配置文件,D50 白点(按 lcms2 约定向 cmsCreateLab4Profile 传 NULL)。
      Returns:
      open profile | 打开的配置文件
      Throws:
      OpenImageCodecException - on native failure | native 失败时
    • xyz

      public static ColorProfile xyz()
      Creates a built-in XYZ profile (linear, D50 white point). 创建内置 XYZ 配置文件(线性,D50 白点)。
      Returns:
      open profile | 打开的配置文件
      Throws:
      OpenImageCodecException - on native failure | native 失败时
    • fromIccBytes

      public static ColorProfile fromIccBytes(byte[] iccData)
      Loads an ICC profile from a raw byte array (e.g. embedded in a PNG/JPEG iCCP / Exif chunk). The bytes are copied into a confined Arena before the native call, so the returned profile no longer references the input array. 从原始字节数组加载 ICC 配置文件(例如 PNG/JPEG 的 iCCP / Exif 嵌入)。 调用前会将字节复制到受限 Arena,返回的配置文件不再引用入参数组。
      Parameters:
      iccData - raw ICC profile bytes, non-null and non-empty | 原始 ICC 字节,非空且非 0 长
      Returns:
      open profile | 打开的配置文件
      Throws:
      IllegalArgumentException - if input is null/empty | 入参非法时
      OpenImageCodecException - if lcms2 rejects the data | lcms2 拒绝数据时
    • close

      public void close()
      Closes this profile via cmsCloseProfile. Idempotent — subsequent calls are no-ops. 通过 cmsCloseProfile 关闭。幂等 — 多次调用为空操作。
      Specified by:
      close in interface AutoCloseable