Module: Applitools::ChunkyPNG::Resampling

Defined in:
lib/applitools/chunky_png/resampling.rb

Instance Method Summary collapse

Instance Method Details

#bicubic_x_points(dst_width) ⇒ Object



27
28
29
# File 'lib/applitools/chunky_png/resampling.rb', line 27

def bicubic_x_points(dst_width)
  bicubic_points2(width, dst_width, false)
end

#bicubic_y_points(dst_height) ⇒ Object



31
32
33
# File 'lib/applitools/chunky_png/resampling.rb', line 31

def bicubic_y_points(dst_height)
  bicubic_points2(height, dst_height, true)
end

#imaginable_point(point1, point2) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/applitools/chunky_png/resampling.rb', line 43

def imaginable_point(point1, point2)
  r = [0, [255, ChunkyPNG::Color.r(point1) << 1].min - ChunkyPNG::Color.r(point2)].max
  g = [0, [255, ChunkyPNG::Color.g(point1) << 1].min - ChunkyPNG::Color.g(point2)].max
  b = [0, [255, ChunkyPNG::Color.b(point1) << 1].min - ChunkyPNG::Color.b(point2)].max
  a = [0, [255, ChunkyPNG::Color.a(point1) << 1].min - ChunkyPNG::Color.a(point2)].max
  ChunkyPNG::Color.rgba(r, g, b, a)
end

#line_with_bounds(y, src_dimension, direction) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/applitools/chunky_png/resampling.rb', line 35

def line_with_bounds(y, src_dimension, direction)
  line = (direction ? column(y) : row(y))
  [imaginable_point(line[0], line[1])] + line + [
    imaginable_point(line[src_dimension - 2], line[src_dimension - 3]),
    imaginable_point(line[src_dimension - 1], line[src_dimension - 2])
  ]
end

#resample_bicubic(new_width, new_height) ⇒ Object



23
24
25
# File 'lib/applitools/chunky_png/resampling.rb', line 23

def resample_bicubic(new_width, new_height)
  dup.resample_bicubic!(new_width, new_height)
end

#resample_bicubic!(dst_width, dst_height) ⇒ Object



17
18
19
20
21
# File 'lib/applitools/chunky_png/resampling.rb', line 17

def resample_bicubic!(dst_width, dst_height)
  new_pixels = resampling_first_step(dst_width, dst_height)
  replace_canvas!(dst_width, dst_height, new_pixels)
  self
end