Skip to content

Commit

Permalink
Take account of dummy width and height (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagletmt committed Apr 19, 2014
1 parent dd8f22e commit 435423f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 2 additions & 5 deletions lib/comic_walker/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ def save_content(client, cid)
when 'configuration_pack.json'
config = JSON.parse(zip.read)
decoder = ItemDecoder.new(config)
config['configuration']['contents'].each do |content|
pages[content['index']-1] = content['file']
end
when /end_layer\.json/
begin
pp EndLayerDecoder.new(license.key).decode(zip.read)
Expand All @@ -102,13 +99,13 @@ def save_content(client, cid)
end

img_dir = Pathname.new(title).join(cid).tap(&:mkpath)
pages.each.with_index do |file, i|
decoder.pages.each.with_index do |file, i|
dat_path = Pathname.new(file).join('0.dat')
data = items[dat_path.to_s]
img_fname = dat_path.parent.basename.sub_ext('.jpg')
img_path = img_dir.join(sprintf('%03d_%s', i, img_fname))
puts "#{dat_path} -> #{img_path}"
decoder.decode(dat_path, img_path, data)
decoder.decode(file, dat_path, img_path, data)
end
end
end
Expand Down
17 changes: 15 additions & 2 deletions lib/comic_walker/item_decoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

module ComicWalker
class ItemDecoder
attr_reader :pages

def initialize(configuration_pack)
fname = '0.dat'
ct = configuration_pack['ct']
Expand All @@ -11,9 +13,17 @@ def initialize(configuration_pack)
@key1 = (ct + st + fname).unpack('C*')
@key2 = (ct + fname + et).unpack('C*')
@key3 = (fname + st + et).unpack('C*')
@pages = []
configuration_pack['configuration']['contents'].each do |content|
pages[content['index']-1] = content['file']
end
@file_info = {}
@pages.each do |file|
@file_info[file] = configuration_pack[file]
end
end

def decode(dat_path, img_path, b64data)
def decode(file, dat_path, img_path, b64data)
bs = 128
hs = 1024
blob = Unknown.finish(@key1, hs,
Expand All @@ -27,11 +37,14 @@ def decode(dat_path, img_path, b64data)
src = Magick::Image.from_blob(blob).first
width = src.columns
height = src.rows
page_info = @file_info[file]['FileLinkInfo']['PageLinkInfoList'].first['Page']
dummy_height = page_info['DummyHeight']
dummy_width = page_info['DummyWidth']
t = dat_path.sub_ext('').to_s.chars.inject(0) { |acc, c| acc + c.ord }
pat = t%4 + 1
moves = Unknown.calculate_moves(width, height, 64, 64, pat)

dst = Magick::Image.new(width, height)
dst = Magick::Image.new(width - dummy_width, height - dummy_height)
dst.format = 'jpeg'
moves.each do |move|
crop = src.excerpt(move[:destX], move[:destY], move[:width], move[:height])
Expand Down

0 comments on commit 435423f

Please sign in to comment.