Class ColorSpaceOp
java.lang.Object
cloud.opencode.base.image.color.ColorSpaceOp
Color Space Conversion Utilities
颜色空间转换工具类
Provides conversions between RGB and various color spaces including HSV, HSL, CIELAB, and YCbCr. All conversions operate on packed ARGB pixel arrays for maximum interoperability with PixelOp.
提供 RGB 与多种颜色空间(HSV、HSL、CIELAB、YCbCr)之间的转换。 所有转换操作在 ARGB 像素数组上进行,与 PixelOp 保持最大互操作性。
Features | 主要功能:
- RGB to/from HSV conversion - RGB 与 HSV 颜色空间互转
- RGB to/from HSL conversion - RGB 与 HSL 颜色空间互转
- RGB to/from CIELAB conversion (D65 illuminant, sRGB) - RGB 与 CIELAB 颜色空间互转(D65 光源,sRGB)
- RGB to/from YCbCr conversion (ITU-R BT.601) - RGB 与 YCbCr 颜色空间互转(ITU-R BT.601)
Usage Examples | 使用示例:
int[] pixels = PixelOp.getPixels(image);
float[][] hsv = ColorSpaceOp.toHsv(pixels);
// Manipulate hsv[0] (H), hsv[1] (S), hsv[2] (V)
int[] result = ColorSpaceOp.fromHsv(hsv);
Performance | 性能特性:
- Time: O(n) where n = pixel count - 时间: O(n),n 为像素数量
- Space: O(n) for output arrays - 空间: O(n) 用于输出数组
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-image V2.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic RasterfromArgb(int[] argb, int width, int height) static int[]fromHsl(float[][] hsl) Convert HSL color space to ARGB pixels (A=255).static int[]fromHsv(float[][] hsv) Convert HSV color space to ARGB pixels (A=255).static int[]fromLab(float[][] lab) Convert CIELAB color space to ARGB pixels (A=255).static int[]fromYCbCr(float[][] ycbcr) Convert YCbCr color space to ARGB pixels (A=255, ITU-R BT.601).static int[]ReadRasterpixels as a row-major packed ARGBint[].static float[][]toHsl(int[] argbPixels) Convert ARGB pixels to HSL color space.static float[][]Convert aRasterto HSL color space.static float[][]toHsv(int[] argbPixels) Convert ARGB pixels to HSV color space.static float[][]Convert aRasterto HSV color space.static float[][]toLab(int[] argbPixels) Convert ARGB pixels to CIELAB color space using D65 illuminant and sRGB.static float[][]Convert aRasterto CIELAB color space (D65, sRGB).static float[][]toYCbCr(int[] argbPixels) Convert ARGB pixels to YCbCr color space (ITU-R BT.601).static float[][]Convert aRasterto YCbCr color space (ITU-R BT.601).
-
Method Details
-
toHsv
public static float[][] toHsv(int[] argbPixels) Convert ARGB pixels to HSV color space. 将 ARGB 像素转换为 HSV 颜色空间。- Parameters:
argbPixels- the ARGB pixel array | ARGB 像素数组- Returns:
- float[3][pixelCount] for H(0-360), S(0-1), V(0-1) | float[3][像素数] 分别对应 H(0-360), S(0-1), V(0-1)
- Throws:
ImageOperationException- if argbPixels is null or empty | 当 argbPixels 为 null 或空时抛出
-
fromHsv
public static int[] fromHsv(float[][] hsv) Convert HSV color space to ARGB pixels (A=255). 将 HSV 颜色空间转换为 ARGB 像素(A=255)。- Parameters:
hsv- float[3][pixelCount] for H(0-360), S(0-1), V(0-1) | float[3][像素数] 分别对应 H(0-360), S(0-1), V(0-1)- Returns:
- ARGB pixel array | ARGB 像素数组
- Throws:
ImageOperationException- if hsv is null or invalid | 当 hsv 为 null 或无效时抛出
-
toHsl
public static float[][] toHsl(int[] argbPixels) Convert ARGB pixels to HSL color space. 将 ARGB 像素转换为 HSL 颜色空间。- Parameters:
argbPixels- the ARGB pixel array | ARGB 像素数组- Returns:
- float[3][pixelCount] for H(0-360), S(0-1), L(0-1) | float[3][像素数] 分别对应 H(0-360), S(0-1), L(0-1)
- Throws:
ImageOperationException- if argbPixels is null or empty | 当 argbPixels 为 null 或空时抛出
-
fromHsl
public static int[] fromHsl(float[][] hsl) Convert HSL color space to ARGB pixels (A=255). 将 HSL 颜色空间转换为 ARGB 像素(A=255)。- Parameters:
hsl- float[3][pixelCount] for H(0-360), S(0-1), L(0-1) | float[3][像素数] 分别对应 H(0-360), S(0-1), L(0-1)- Returns:
- ARGB pixel array | ARGB 像素数组
- Throws:
ImageOperationException- if hsl is null or invalid | 当 hsl 为 null 或无效时抛出
-
toLab
public static float[][] toLab(int[] argbPixels) Convert ARGB pixels to CIELAB color space using D65 illuminant and sRGB. 使用 D65 光源和 sRGB 将 ARGB 像素转换为 CIELAB 颜色空间。- Parameters:
argbPixels- the ARGB pixel array | ARGB 像素数组- Returns:
- float[3][pixelCount] for L(0-100), a(-128 to 127), b(-128 to 127) | float[3][像素数]
- Throws:
ImageOperationException- if argbPixels is null or empty | 当 argbPixels 为 null 或空时抛出
-
fromLab
public static int[] fromLab(float[][] lab) Convert CIELAB color space to ARGB pixels (A=255). 将 CIELAB 颜色空间转换为 ARGB 像素(A=255)。- Parameters:
lab- float[3][pixelCount] for L, a, b | float[3][像素数] 分别对应 L, a, b- Returns:
- ARGB pixel array | ARGB 像素数组
- Throws:
ImageOperationException- if lab is null or invalid | 当 lab 为 null 或无效时抛出
-
toYCbCr
public static float[][] toYCbCr(int[] argbPixels) Convert ARGB pixels to YCbCr color space (ITU-R BT.601). 使用 ITU-R BT.601 将 ARGB 像素转换为 YCbCr 颜色空间。- Parameters:
argbPixels- the ARGB pixel array | ARGB 像素数组- Returns:
- float[3][pixelCount] for Y, Cb, Cr | float[3][像素数] 分别对应 Y, Cb, Cr
- Throws:
ImageOperationException- if argbPixels is null or empty | 当 argbPixels 为 null 或空时抛出
-
fromYCbCr
public static int[] fromYCbCr(float[][] ycbcr) Convert YCbCr color space to ARGB pixels (A=255, ITU-R BT.601). 使用 ITU-R BT.601 将 YCbCr 颜色空间转换为 ARGB 像素(A=255)。- Parameters:
ycbcr- float[3][pixelCount] for Y, Cb, Cr | float[3][像素数] 分别对应 Y, Cb, Cr- Returns:
- ARGB pixel array | ARGB 像素数组
- Throws:
ImageOperationException- if ycbcr is null or invalid | 当 ycbcr 为 null 或无效时抛出
-
toArgb
ReadRasterpixels as a row-major packed ARGBint[]. 将Raster像素读为行优先打包的 ARGBint[]。Used as a bridge to the existing
int[]based color-space conversion methods.用作桥接:将现有
int[]颜色空间转换方法适配到Raster。- Parameters:
raster- the source raster | 源 raster- Returns:
- packed ARGB pixel array (length = w * h) | 打包的 ARGB 像素数组(长度 = w * h)
- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出- Since:
- opencode-base-image V1.0.4
-
fromArgb
- Parameters:
argb- packed ARGB pixel array | 打包的 ARGB 像素数组width- raster width | raster 宽度height- raster height | raster 高度- Returns:
- a fresh
RGBA_8raster | 新分配的RGBA_8raster - Throws:
ImageOperationException- ifargb.length != width * height| 长度不匹配时抛出- Since:
- opencode-base-image V1.0.4
-
toHsv
- Parameters:
raster- the source raster | 源 raster- Returns:
- float[3][pixelCount] for H, S, V | float[3][像素数] 分别为 H, S, V
- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出- Since:
- opencode-base-image V1.0.4
-
toHsl
- Parameters:
raster- the source raster | 源 raster- Returns:
- float[3][pixelCount] for H, S, L | float[3][像素数] 分别为 H, S, L
- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出- Since:
- opencode-base-image V1.0.4
-
toLab
- Parameters:
raster- the source raster | 源 raster- Returns:
- float[3][pixelCount] for L, a, b | float[3][像素数] 分别为 L, a, b
- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出- Since:
- opencode-base-image V1.0.4
-
toYCbCr
- Parameters:
raster- the source raster | 源 raster- Returns:
- float[3][pixelCount] for Y, Cb, Cr | float[3][像素数] 分别为 Y, Cb, Cr
- Throws:
NullPointerException- if raster is null | 当 raster 为 null 时抛出- Since:
- opencode-base-image V1.0.4
-