Sha256: 93cdde061d7099b0458d2799088659ee7be732c0843958c792b34b0713d17883

Contents?: true

Size: 1.13 KB

Versions: 14

Compression:

Stored size: 1.13 KB

Contents

module ZPNG
  class Pixels
    include Enumerable

    module ImageEnum
      def each
        @image.height.times do |y|
          @image.width.times do |x|
            yield @image[x,y]
          end
        end
      end

      def keep_if otherwise = Color::TRANSPARENT
        @image.height.times do |y|
          @image.width.times do |x|
            @image[x,y] = otherwise unless yield(@image[x,y])
          end
        end
      end

      def filter!
        @image.height.times do |y|
          @image.width.times do |x|
            @image[x,y] = yield(@image[x,y])
          end
        end
      end
      alias :map! :filter!
    end

    module ScanLineEnum
      def each
        @scanline.width.times do |x|
          yield @scanline[x]
        end
      end
    end

    def initialize x
      case x
      when Image
        @image = x
        extend ImageEnum
      when ScanLine
        @scanline = x
        extend ScanLineEnum
      else raise ArgumentError, "don't know how to enumerate #{x.inspect}"
      end
    end

    def == other
      self.to_a == other.to_a
    end

    def uniq
      self.to_a.uniq
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
zpng-0.4.5 lib/zpng/pixels.rb
zpng-0.4.4 lib/zpng/pixels.rb
zpng-0.4.3 lib/zpng/pixels.rb
zpng-0.4.2 lib/zpng/pixels.rb
zpng-0.4.1 lib/zpng/pixels.rb
zpng-0.4.0 lib/zpng/pixels.rb
zpng-0.3.4 lib/zpng/pixels.rb
zpng-0.3.3 lib/zpng/pixels.rb
zpng-0.3.2 lib/zpng/pixels.rb
zpng-0.3.1 lib/zpng/pixels.rb
zpng-0.3.0 lib/zpng/pixels.rb
zpng-0.2.5 lib/zpng/pixels.rb
zpng-0.2.4 lib/zpng/pixels.rb
zpng-0.2.3 lib/zpng/pixels.rb