lib/chunky_png/canvas/resampling.rb
# Resamples the canvas with bilinear interpolation.
# @param [Integer] new_width The width of the resampled canvas.
# @param [Integer] new_height The height of the resampled canvas.
# @return [ChunkyPNG::Canvas] A new canvas instance with the resampled pixels.
Resamples the canvas with bilinear interpolation.
Resamples the canvas with bilinear interpolation .
def resample_bilinear!(new_width, new_height)
        index_x, interp_x = steps_residues(width, new_width)
        index_y, interp_y = steps_residues(height, new_height)
        pixels = Array.new(new_width * new_height)
        i = 0
        for y in 1..new_height
          y1 = [index_y[y - 1], 0].max
          y2 = [index_y[y - 1] + 1, height - 1].min
          y_residue = interp_y[y - 1]
          for x in 1..new_width
            x1 = [index_x[x - 1], 0].max
            x2 = [index_x[x - 1] + 1, width - 1].min
            x_residue = interp_x[x - 1]
            pixel_11 = get_pixel(x1, y1)
            pixel_21 = get_pixel(x2, y1)
            pixel_12 = get_pixel(x1, y2)
            pixel_22 = get_pixel(x2, y2)
            pixel_top = ChunkyPNG::Color.interpolate_quick(pixel_21, pixel_11, x_residue)
            pixel_bot = ChunkyPNG::Color.interpolate_quick(pixel_22, pixel_12, x_residue)
            pixels[i] = ChunkyPNG::Color.interpolate_quick(pixel_bot, pixel_top, y_residue)
            i += 1
          end
        end
        replace_canvas!(new_width.to_i, new_height.to_i, pixels)
      end
def resample_bilinear! ( new_width , new_height ) index_x , interp_x = steps_residues ( width , new_width ) index_y , interp_y = steps_residues ( height , new_height ) pixels = Array . new ( new_width * new_height ) i = 0 for y in 1 .. new_height y1 = [ index_y [ y - 1 ] , 0 ] . max y2 = [ index_y [ y - 1 ] + 1 , height - 1 ] . min y_residue = interp_y [ y - 1 ] for x in 1 .. new_width x1 = [ index_x [ x - 1 ] , 0 ] . max x2 = [ index_x [ x - 1 ] + 1 , width - 1 ] . min x_residue = interp_x [ x - 1 ] pixel_11 = get_pixel ( x1 , y1 ) pixel_21 = get_pixel ( x2 , y1 ) pixel_12 = get_pixel ( x1 , y2 ) pixel_22 = get_pixel ( x2 , y2 ) pixel_top = ChunkyPNG :: Color . interpolate_quick ( pixel_21 , pixel_11 , x_residue ) pixel_bot = ChunkyPNG :: Color . interpolate_quick ( pixel_22 , pixel_12 , x_residue ) pixels [ i ] = ChunkyPNG :: Color . interpolate_quick ( pixel_bot , pixel_top , y_residue ) i += 1 end end replace_canvas! ( new_width . to_i , new_height . to_i , pixels ) end
Resamples the canvas with bilinear interpolation.
Resamples the canvas with bilinear interpolation .
# Clamp the indicies to the edges of the image # Clamp the indicies to the edges of the image # Interpolate by Row # Interpolate by Column
A new canvas instance with the resampled pixels.
A new canvas instance with the resampled pixels .
ChunkyPNG::Canvas
new_width
<not_specific>
new_height
<not_specific>
<not_specific>
new_height The height of the resampled canvas.
new_height The height of the resampled canvas .