Sha256: 54047e61b5870c908f04705af76f6b66f056788ae9f9023a02f9eb25174f9fcb

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 KB

Contents

module RFreeImage
	module ImageBPP
		GRAY = 8
		BGR = 24
		BGRA = 32
	end
	module Color
		BLUE    = 0xff0000ff
		GREEN   = 0xff00ff00
		RED     = 0xffff0000
		YELLOW  = 0xffffff00
		CYAN    = 0xff00ffff
		WHITE   = 0xffffffff
		BLACK   = 0xff000000
		GRAY    = 0xffa9a9a9
	end
	module Filter
		FILTER_BOX = 0
		FILTER_BICUBIC = 1
		FILTER_BILINEAR = 2
		FILTER_BSPLINE = 3
		FILTER_CATMULLROM = 4
		FILTER_LANCZOS3 = 5
	end
	class Image
		def bytes
			@bytes ||= read_bytes
		end

		def destroy!
			release
			@bytes = nil
		end

		def gray?
			bpp == ImageBPP::GRAY
		end

		def to_gray
			return self if gray?
			to_bpp 8
		end

		def bgra?
			bpp == ImageBPP::BGRA
		end

		def to_bgra
			return self if bgra?
			to_bpp 32
		end

		def resize(width, height, filter = Filter::FILTER_CATMULLROM)
			return self.rescale(width, height, filter)
		end

    def self.load_downscale file, max_size
      # only work on jpeg
      img = Image.new file, 0, max_size
      _downscale_nocopy img, max_size
    end

    def self.from_blob_downscale blob, max_size
      # only work on jpeg
      img = Image.from_blob blob, 0, max_size
      _downscale_nocopy img, max_size
    end

		alias_method :write, :save
		alias_method :columns, :cols

    private
    def self._downscale_nocopy img, max_size
      return img if img.cols <= max_size && img.rows <= max_size
      nimg = img.downscale max_size
      img.destroy!
      nimg
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rfreeimage-0.2.1 lib/rfreeimage/image.rb
rfreeimage-0.2.4 lib/rfreeimage/image.rb
rfreeimage-0.2.0 lib/rfreeimage/image.rb
rfreeimage-0.1.9 lib/rfreeimage/image.rb
rfreeimage-0.1.8 lib/rfreeimage/image.rb
rfreeimage-0.1.7 lib/rfreeimage/image.rb