Sha256: ecf50cf524bdda8ca1583471c24bb5a9bf51aea9161b7eb7a19d70e3c9110c9d

Contents?: true

Size: 764 Bytes

Versions: 13

Compression:

Stored size: 764 Bytes

Contents

begin
  require 'oily_png'
rescue LoadError
  require 'chunky_png'
end

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.flip_horizontally! if flip
      png_image.flip_vertically! 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

13 entries across 13 versions & 1 rubygems

Version Path
mittsu-0.5.0 lib/mittsu/loaders/image_loader.rb
mittsu-0.4.1 lib/mittsu/loaders/image_loader.rb
mittsu-0.4.0 lib/mittsu/loaders/image_loader.rb
mittsu-0.3.3 lib/mittsu/loaders/image_loader.rb
mittsu-0.3.2 lib/mittsu/loaders/image_loader.rb
mittsu-0.3.1 lib/mittsu/loaders/image_loader.rb
mittsu-0.3.0 lib/mittsu/loaders/image_loader.rb
mittsu-0.2.4 lib/mittsu/loaders/image_loader.rb
mittsu-0.2.3 lib/mittsu/loaders/image_loader.rb
mittsu-0.2.2 lib/mittsu/loaders/image_loader.rb
mittsu-0.2.1 lib/mittsu/loaders/image_loader.rb
mittsu-0.2.0 lib/mittsu/loaders/image_loader.rb
mittsu-0.1.7 lib/mittsu/loaders/image_loader.rb