Class: Contrek::Bitmaps::PngBitmap

Inherits:
Bitmap
  • Object
show all
Defined in:
lib/contrek/bitmaps/png_bitmap.rb

Direct Known Subclasses

RawBitmap

Instance Method Summary collapse

Methods inherited from Bitmap

#clear!, #copy_rect, #scan

Methods included from Painting

#bitmap_colors, direct_draw_polygons

Constructor Details

#initialize(file_path) ⇒ PngBitmap

Returns a new instance of PngBitmap.



8
9
10
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 8

def initialize(file_path)
  @image = ChunkyPNG::Image.from_file(file_path)
end

Instance Method Details

#clearObject



63
64
65
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 63

def clear
  @image = ChunkyPNG::Image.new(w, h, ChunkyPNG::Color.rgba(255, 255, 255, 255))
end

#draw_line(start_x, start_y, end_x, end_y, value) ⇒ Object



20
21
22
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 20

def draw_line(start_x, start_y, end_x, end_y, value)
  @image.line_xiaolin_wu(start_x, start_y, end_x, end_y, value)
end

#hObject



16
17
18
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 16

def h
  @image.dimension.height
end

#hsv_at(x, y) ⇒ Object



32
33
34
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 32

def hsv_at(x, y)
  @image.get_pixel(x, y).to_hsv
end

#inspectObject



59
60
61
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 59

def inspect
  "PngBitMap"
end

#resize_h(new_h) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 51

def resize_h(new_h)
  old_w = w
  old_h = h

  new_w = (old_w * new_h) / old_h
  @image = @image.resize(new_w, new_h)
end

#rgb_value_at(x, y) ⇒ Object



28
29
30
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 28

def rgb_value_at(x, y)
  value_at(x, y)
end

#save(filename) ⇒ Object



40
41
42
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 40

def save(filename)
  @image.save(filename, interlace: true, compression: Zlib::NO_COMPRESSION)
end

#to_tmp_fileObject



44
45
46
47
48
49
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 44

def to_tmp_file
  tmp_png_file = Tempfile.new
  tmp_png_file.binmode
  tmp_png_file.write(@image.to_blob)
  tmp_png_file
end

#value_at(x, y) ⇒ Object



24
25
26
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 24

def value_at(x, y)
  @image[x, y]
end

#value_set(x, y, value) ⇒ Object



36
37
38
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 36

def value_set(x, y, value)
  @image[x, y] = value
end

#wObject



12
13
14
# File 'lib/contrek/bitmaps/png_bitmap.rb', line 12

def w
  @image.dimension.width
end