Class BrightnessContrastOp

java.lang.Object
cloud.opencode.base.image.color.BrightnessContrastOp

public final class BrightnessContrastOp extends Object
Brightness and Contrast Adjustment Operations 亮度与对比度调整操作工具类

Provides pixel-level brightness and contrast adjustments using multiplicative factor-based transformations.

提供基于乘法因子的像素级亮度和对比度调整。

Features | 主要功能:

  • Brightness adjustment via multiplicative factor - 基于乘法因子的亮度调整
  • Contrast adjustment centered at 128 - 以 128 为中心的对比度调整
  • Preserves alpha channel - 保留 Alpha 通道

Usage Examples | 使用示例:

// Brighten image by 50%
Raster bright = BrightnessContrastOp.brightness(raster, 1.5);

// Increase contrast
Raster highContrast = BrightnessContrastOp.contrast(raster, 2.0);

Performance | 性能特性:

  • Time: O(n) where n = pixel count - 时间: O(n),n 为像素数量
  • Space: O(n) for output image - 空间: O(n) 用于输出图像

Security | 安全性:

  • Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-image V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • brightness

      public static Raster brightness(Raster raster, double factor)
      Adjust brightness of a Raster by multiplying each RGB component by the given factor. 通过将每个 RGB 分量乘以给定因子来调整 Raster 亮度。

      Returns a freshly allocated RGBA_8 raster preserving the source alpha channel.

      返回新分配的 RGBA_8 raster,保留源 alpha 通道。

      Parameters:
      raster - the source raster | 源 raster
      factor - the brightness factor (must be >= 0) | 亮度因子(必须 >= 0)
      Returns:
      the brightness-adjusted RGBA_8 raster | 亮度调整后的 RGBA_8 raster
      Throws:
      NullPointerException - if raster is null | 当 raster 为 null 时抛出
      ImageOperationException - if factor is negative, NaN, or infinite | 当因子为负数、NaN 或无穷时抛出
      Since:
      opencode-base-image V1.0.4
    • contrast

      public static Raster contrast(Raster raster, double factor)
      Adjust contrast of a Raster by scaling RGB components around the midpoint 128. 通过围绕中间值 128 缩放 RGB 分量来调整 Raster 对比度。

      Returns a freshly allocated RGBA_8 raster preserving the source alpha channel.

      返回新分配的 RGBA_8 raster,保留源 alpha 通道。

      Parameters:
      raster - the source raster | 源 raster
      factor - the contrast factor (must be >= 0) | 对比度因子(必须 >= 0)
      Returns:
      the contrast-adjusted RGBA_8 raster | 对比度调整后的 RGBA_8 raster
      Throws:
      NullPointerException - if raster is null | 当 raster 为 null 时抛出
      ImageOperationException - if factor is negative, NaN, or infinite | 当因子为负数、NaN 或无穷时抛出
      Since:
      opencode-base-image V1.0.4