lib/chunky_png/canvas/resampling.rb
# Fractional Interpolation between two values
#
# Used for generating values for interpolation (eg, bilinear).
# Produces both the indices and the interpolation factors (residues).
#
# @param [Integer] width The width of the source
# @param [Integer] new_width The width of the destination
# @return [Array<Integer>, Array<Integer>] Two arrays of indicies and residues
Fractional Interpolation between two values
Used for generating values for interpolation .
Produces both the indices and the interpolation factors (residues).
Fractional Interpolation between two values Used for generating values for interpolation . Produces both the indices and the interpolation factors ( residues ) .
def steps_residues(width, new_width)
        indicies = Array.new(new_width, nil)
        residues = Array.new(new_width, nil)
        base_step = width / new_width
        err_step = (width % new_width) << 1
        denominator = new_width << 1
        index = (width - new_width) / denominator
        err = (width - new_width) % denominator
        for i in 1..new_width
          indicies[i - 1] = index
          residues[i - 1] = (255.0 * err.to_f / denominator.to_f).round
          index += base_step
          err += err_step
          if err >= denominator
            index += 1
            err -= denominator
          end
        end
        [indicies, residues]
      end
def steps_residues ( width , new_width ) indicies = Array . new ( new_width , nil ) residues = Array . new ( new_width , nil ) base_step = width / new_width err_step = ( width % new_width ) << 1 denominator = new_width << 1 index = ( width - new_width ) / denominator err = ( width - new_width ) % denominator for i in 1 .. new_width indicies [ i - 1 ] = index residues [ i - 1 ] = ( 255.0 * err . to_f / denominator . to_f ) . round index += base_step err += err_step if err >= denominator index += 1 err -= denominator end end [ indicies , residues ] end
Fractional Interpolation between two values
Used for generating values for interpolation (eg, bilinear).
Fractional Interpolation between two values Used for generating values for interpolation ( eg bilinear ) .
# This works by accumulating the fractional error and # overflowing when necessary. # We use mixed number arithmetic with a denominator of # 2 * new_width # Initial pixel
Two arrays of indicies and residues
Two arrays of indicies and residues
Array<Integer>, Array<Integer>
width
<not_specific>
new_width
<not_specific>
<not_specific>
new_width The width of the destination
new_width The width of the destination