java.lang.Object
io.github.stanio.xbrz.Xbrz

public class Xbrz extends Object
Defines the main API for xBRZ scaling. Instances are configured with specific scale factor, color blending type (alpha vs. no alpha) and color distance function. A single instance could be used to scale multiple images concurrently.

Sample usage:

 import java.awt.image.BufferedImage;

     BufferedImage source = ...;
     int srcWidth = source.getWidth();
     int srcHeight = source.getHeight();
     int[] srcPixels = source.getRGB(0, 0, srcWidth, srcHeight, null, 0, srcWidth);

     int factor = 2;
     int destWidth = srcWidth * factor;
     int destHeight = srcHeight * factor;
     boolean hasAlpha = source.getColorModel().hasAlpha();
     int[] destPixels = Xbrz.scaleImage(factor, hasAlpha, srcPixels, null, srcWidth, srcHeight);

     BufferedImage scaled = new BufferedImage(destWidth, destHeight,
                                              hasAlpha ? BufferedImage.TYPE_INT_ARGB
                                                       : BufferedImage.TYPE_INT_RGB);
     scaled.setRGB(0, 0, destWidth, destHeight, destPixels, 0, destWidth);
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    ScalerCfg
  • Constructor Summary

    Constructors
    Constructor
    Description
    Xbrz(int factor)
    Constructs a new xBRZ scaler.
    Xbrz(int factor, boolean withAlpha)
     
    Xbrz(int factor, boolean withAlpha, Xbrz.ScalerCfg cfg)
     
    Xbrz(int factor, boolean withAlpha, Xbrz.ScalerCfg cfg, ColorDistance colorDistance)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    The factor this Xbrz instance applies when scaling images.
    int
    factor alias.
    int[]
    scaleImage(int[] src, int[] trg, int srcWidth, int srcHeight)
    Scales the src pixels to the trg buffer.
    void
    scaleImage(int[] src, int[] trg, int srcWidth, int srcHeight, int yFirst, int yLast)
     
    static int[]
    scaleImage(int factor, boolean hasAlpha, int[] src, int[] trg, int srcWidth, int srcHeight)
    new Xbrz(factor, hasAlpha).scaleImage(src, trg, srcWidth, srcHeight)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Xbrz

      public Xbrz(int factor)
      Constructs a new xBRZ scaler.
      Parameters:
      factor - the scale factor to apply
      Throws:
      IllegalArgumentException - if the specified scale factor is < 2 or > 6
    • Xbrz

      public Xbrz(int factor, boolean withAlpha)
    • Xbrz

      public Xbrz(int factor, boolean withAlpha, Xbrz.ScalerCfg cfg)
    • Xbrz

      public Xbrz(int factor, boolean withAlpha, Xbrz.ScalerCfg cfg, ColorDistance colorDistance)
  • Method Details

    • factor

      public int factor()
      The factor this Xbrz instance applies when scaling images.
      Returns:
      The configured scaling factor
    • scale

      public int scale()
      factor alias.
      See Also:
    • scaleImage

      public int[] scaleImage(int[] src, int[] trg, int srcWidth, int srcHeight)
      Scales the src pixels to the trg buffer.

      The pixels are expected to be packed as ARGB int (32-bit) values.

    • scaleImage

      public void scaleImage(int[] src, int[] trg, int srcWidth, int srcHeight, int yFirst, int yLast)
    • scaleImage

      public static int[] scaleImage(int factor, boolean hasAlpha, int[] src, int[] trg, int srcWidth, int srcHeight)
      new Xbrz(factor, hasAlpha).scaleImage(src, trg, srcWidth, srcHeight)
      See Also: