Sha256: c8c6274348259d82c7330b9d096f6ba6dfeab86d72824c29a50132d5c581af50

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

#!/usr/bin/env ruby
require 'zpng'
require 'awesome_print'

images = ARGV.map{ |fname| ZPNG::Image.load(fname) }
raise "need at least 2 images" if images.size < 2

limit = 100
alpha_used = images.any?(&:alpha_used?)
channels = alpha_used ? %w'r g b a' : %w'r g b'

printf "%6s %4s %4s : %s  ...\n".magenta, "#", "X", "Y", (alpha_used ? "RRGGBBAA":"RRGGBB")

idx = ndiff = 0
images[0].each_pixel do |c,x,y|
  colors = images.map{ |img| img[x,y] }
  if colors.uniq.size > 1
    ndiff += 1
    printf "%6d %4d %4d : ", idx, x, y
    t = Array.new(images.size){ '' }
    channels.each do |channel|
      values = colors.map{ |color| color.send(channel) }
      if values.uniq.size == 1
        # all equal
        values.each_with_index do |value,idx|
          t[idx] << "%02x".gray % value
        end
      else
        # got diff
        values.each_with_index do |value,idx|
          t[idx] << "%02x".red % value
        end
      end
    end
    puts t.join('  ')
  end
  idx += 1
  if limit && ndiff >= limit
    puts "[.] diff limit #{limit} reached"
    break
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zsteg-0.2.13 cmp_png.rb