Class: ZSteg::Extractor

Inherits:
Object
  • Object
show all
Includes:
ByteExtractor, ColorExtractor
Defined in:
lib/zsteg/extractor.rb,
lib/zsteg/extractor/byte_extractor.rb,
lib/zsteg/extractor/color_extractor.rb

Defined Under Namespace

Modules: ByteExtractor, ColorExtractor

Instance Method Summary collapse

Methods included from ColorExtractor

#color_extract, #coord_iterator

Methods included from ByteExtractor

#byte_extract, #byte_iterator

Constructor Details

#initialize(image, params = {}) ⇒ Extractor

image can be either filename or ZPNG::Image



11
12
13
14
# File 'lib/zsteg/extractor.rb', line 11

def initialize image, params = {}
  @image = image.is_a?(ZPNG::Image) ? image : ZPNG::Image.load(image)
  @verbose = params[:verbose] || 0
end

Instance Method Details

#bit_indexes(bits) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/zsteg/extractor.rb', line 38

def bit_indexes bits
  if (1..8).include?(bits)
    # number of bits
    # 1 => [0]
    # ...
    # 8 => [7,6,5,4,3,2,1,0]
    bits.times.to_a.reverse
  else
    # mask
    mask = bits & 0xff
    r = []
    8.times do |i|
      r << i if mask[i] == 1
    end
    r.reverse
  end
end

#extract(params = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/zsteg/extractor.rb', line 16

def extract params = {}
  @limit = params[:limit].to_i
  @limit = 2**32 if @limit <= 0

  if params[:order] =~ /b/i
    byte_extract params
  else
    color_extract params
  end
end

#pregenerate_primes(h) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/zsteg/extractor.rb', line 27

def pregenerate_primes h
  @primes ||= Set.new
  return if @primes.size >= h[:count]

  count = h[:count]
  Prime.each(h[:max]) do |prime|
    @primes << prime
    break if @primes.size >= count
  end
end