Sha256: 056eebffd5690d36d013ed609fcf0415f9632803dd4591b8b70c36c9c2b8e839

Contents?: true

Size: 736 Bytes

Versions: 1

Compression:

Stored size: 736 Bytes

Contents

require 'chunky_png'
require 'mittsu/extras/image'

module Mittsu
  class ImageLoader
    attr_accessor :manager

    def initialize(manager = DefaultLoadingManager)
      @manager = manager
    end

    def load(url, flip: false, flop: false)
      chache_url = "#{url}?flip=#{flip}&flop=#{flop}"
      cached = Cache.get(chache_url )
      return cached unless cached.nil?

      png_image = ChunkyPNG::Image.from_file(url)
      png_image = png_image.flip_vertically if flip
      png_image = png_image.flip_horizontally if flop
      rgba_data = png_image.to_rgba_stream

      image = Image.new(png_image.width, png_image.height, rgba_data)

      Cache.add(url, image)
      @manager.item_start(url)
      image
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mittsu-0.1.5 lib/mittsu/loaders/image_loader.rb