Class ResampleOpSingleThread

java.lang.Object
com.mortennobel.imagescaling.AdvancedResizeOp
com.mortennobel.imagescaling.experimental.ResampleOpSingleThread
All Implemented Interfaces:
BufferedImageOp

public class ResampleOpSingleThread extends AdvancedResizeOp
Based on work from Java Image Util ( http://schmidt.devlib.org/jiu/ ) Note that the filter method is not thread safe
  • Field Details

    • MAX_CHANNEL_VALUE

      private final int MAX_CHANNEL_VALUE
      See Also:
    • nrChannels

      private int nrChannels
    • srcWidth

      private int srcWidth
    • srcHeight

      private int srcHeight
    • dstWidth

      private int dstWidth
    • dstHeight

      private int dstHeight
    • horizontalSubsamplingData

      private ResampleOpSingleThread.SubSamplingData horizontalSubsamplingData
    • verticalSubsamplingData

      private ResampleOpSingleThread.SubSamplingData verticalSubsamplingData
    • processedItems

      private int processedItems
    • totalItems

      private int totalItems
    • filter

      private ResampleFilter filter
  • Constructor Details

    • ResampleOpSingleThread

      public ResampleOpSingleThread(int destWidth, int destHeight)
    • ResampleOpSingleThread

      public ResampleOpSingleThread(DimensionConstrain dimensionConstrain)
  • Method Details

    • getFilter

      public ResampleFilter getFilter()
    • setFilter

      public void setFilter(ResampleFilter filter)
    • doFilter

      public BufferedImage doFilter(BufferedImage srcImg, BufferedImage dest, int dstWidth, int dstHeight)
      Specified by:
      doFilter in class AdvancedResizeOp
    • createSubSampling

      private ResampleOpSingleThread.SubSamplingData createSubSampling(int srcSize, int dstSize)
    • scale

      private void scale(BufferedImage srcImg, byte[][] workPixels, BufferedImage outImage)
      Pseudocode: for each for in destination image check that all dependent rows in source image is scaled horizontally and stored in work pixels if not then scale missing rows horizontal and store them in work pixels Scale the destination row vertically and store the result in out pixels It may seem counter intuitive that the vertical scale is done for each row. The simple scaling algorithm would first scale the image horizontal (a row at a time) into the temp image, and then scale the temp image vertically (a column at a time) into the final image. The disadvantage of the simple approach is that you need a large temporary image. I have avoided this by doing the vertically scale a row at a time. Scaling a single row vertically, needs the horizontally scaled rows that the scaling depends on. These dependencies will be lazy initialized. Since we know the height of the 'window' we work on (the maximum number of source rows needed to calculate a dest row), the work pixels only needs to have the same height. Instead of creating a temporary image with a height different from the source image's height, I created a double array where inner array is repeated (so if the window height is 3 the first and the forth row is the same instance). This keeps algorithm a bit simpler (the alternative would be to maintain a mapping between)
      Parameters:
      srcImg - source image
      workPixels - temporary image
      outImage - result image
    • putSample

      private void putSample(byte[] image, int channel, float sample, int location)
    • getSamplesHorizontal

      private void getSamplesHorizontal(byte[] src, int channel, int[] dest)
    • setProgress

      private void setProgress(int zeroBasedIndex, int totalItems)
    • getResultBufferedImageType

      protected int getResultBufferedImageType(BufferedImage srcImg)