bitmap.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Models a bitmap that has been loaded from disk and kept in storage
  2. class Bitmap < Store
  3. extend Store::Forward
  4. # Loads a bitmap
  5. def self.load(name, vpath)
  6. load_something(forward_name(name), vpath, self) do | nid |
  7. Eruta::Store.load_bitmap(nid, vpath)
  8. end
  9. end
  10. # Loads bitmap with flags
  11. def self.load_flags(name, vpath, flags)
  12. load_something(forward_name(name), vpath, self) do | nid |
  13. Eruta::Store.load_bitmap_flags(nid, vpath, flags)
  14. end
  15. end
  16. # Converts the mask color of this bitmapp expressed by r, g, b to transparent.
  17. def mask_to_alpha(r, g, b)
  18. return Eruta::Store.mask_to_alpha(@id, r, g, b)
  19. end
  20. # Converts the average of the sr, sg, sb of each pixel of the image to
  21. # the given r, g, b, with with an alpha value equal to the aforementioned
  22. # alpha. Useful to make images monochromatic.
  23. def average_to_alpha(r, g, b)
  24. return Eruta::Store.average_to_alpha(@id, r, g, b)
  25. end
  26. # Flags of the loaded bitmap.
  27. def flags
  28. return Eruta::Store.bitmap_flags(@id)
  29. end
  30. # Width of the loaded bitmap.
  31. def width
  32. return Eruta::Store.bitmap_width(@id)
  33. end
  34. # Height of the loaded bitmap.
  35. def height
  36. return Eruta::Store.bitmap_height(@id)
  37. end
  38. end