Browse files

Slight cleanup, v6 parser is broken, needs refactoring

git-svn-id: http://activereload.svn.engineyard.com/lighthouse/tools/groom-lake@2141 8456e5f2-bb15-0410-bd20-b44782a1fb1e
  • Loading branch information...
1 parent 1279661 commit a24dd27fc67dfeda093c1967c049d7380637a20c justin committed Sep 8, 2007
Showing with 87 additions and 80 deletions.
  1. +87 −80 lib/groom_lake/brush.rb
View
167 lib/groom_lake/brush.rb
@@ -11,28 +11,101 @@ def initialize(preset_file = nil)
super
@version = nil
@subversion = nil
- parse_abr_file unless @io.nil?
+ parse! unless @io.nil?
end
- def parse_abr_file
+ def parse!
parse_header
parse_brushes
end
def parse_header
-
+ @version = @io.read(2).unpack('n')[0]
+ if(@version == 6)
+ @subversion = @io.read(2).unpack('n')[0]
+ else
+ @brush_count = @io.read(2).unpack('n')[0]
+ end
end
def parse_brushes
- @version = @io.read(2).unpack('n')[0]
- puts "VERSION #{@version}"
case @version
when 6
- @subversion = @io.read(2).unpack('n')[0]
- puts "SUBV: #{@subversion}"
- @io.read(8) #8BIMsamp
+ parse_version_6
+ when 2
+ parse_version_12
+ end
+ end
+
+ def parse_version_12
+ puts "VERSION 2"
+ puts '-' * 100
+
+ 1.upto(@brush_count) do
+
+ #Brush type, 1 = computed, 2 = sampled
+ type = @io.read(2).unpack('n')[0]
+
+ #Number of bytes in the remainder of the brush definition
+ brush_bytes = @io.read(4).unpack('N')
+
+ if type == 1
+ @io.read(14) if @version == 1
+ elsif type == 2
+ @io.read(4) # Misc ignored
+
+ #brush spacing
+ spacing = @io.read(2).unpack('n')
+ puts "SPACING: #{spacing}"
+
+ # Length of the brush name
+ name_length = @io.read(4).unpack('xxn')[0]
+
+ #read it and convert it to utf-8
+ utf8_name = @io.read(name_length * 2).unpack('C*').pack('U*')
+ name = Iconv.iconv('UTF-8', 'UTF-16', utf8_name)[0].chop
+ puts name
+ @io.read(1) # Oh noez, the forgotton byte
+
+ top, left, bottom, right = @io.read(8).unpack('nnnn')
+
+ #long integer version of numbers above
+ ltop, lleft, lbottom, lright = @io.read(16).unpack('NNNN')
+
+ brush_width = lright - lleft
+ brush_height = lbottom - ltop
+
+ puts brush_width
+ puts brush_height
+
+ depth = @io.read(2).unpack('n')[0]
+ puts "DEPTH: #{depth}"
+ compression = @io.read(1).unpack('b')[0]
+ puts "COMPRESSION: #{compression}"
+
+ if compression == 0
+ decompression_data = @io.read(brush_width * brush_height)
+ else
+ puts "HEIGHT: #{brush_height}"
+ scanline_image = 0
+ brush_height.times do
+ scanline_image = scanline_image + @io.read(2).unpack('n')[0]
+ end
+ puts "SCI: #{scanline_image}"
+ scan = @io.read(scanline_image)
+ write_image(name, brush_width, brush_height, scan)
+ end
+ end
+ end
+ end
+
+ def parse_version_6
+ @io.read(4) # Begin 8BIM tag
+ type = @io.read(4) # [samp|pat|desc]
sample_size = @io.read(4).unpack('N')[0]
+ puts "SSIZE: #{sample_size}"
+ @io.pos = sample_size
endsample = sample_size + 12
while(@io.pos < endsample - 1)
@@ -47,7 +120,9 @@ def parse_brushes
puts "FBC: #{offset}"
puts "POS1: #{@io.pos}"
key = @io.read(37)
- puts "POS2: #{@io.pos}"
+ # name_length = @io.read(4).unpack('xxn')[0]
+
+ puts "key: #{key}"
if @subversion == 1
puts 'yeah'
@@ -70,82 +145,14 @@ def parse_brushes
scanline_image = scanline_image + @io.read(2).unpack('n')[0]
end
scan = @io.read(scanline_image)
- write_image(Time.now.to_s + 'brush', width, height, scan)
+ write_image(Time.now.to_s + @io.pos.to_s + 'brush', width, height, scan)
@io.read(offset) if @subversion == 1
if(@subversion == 2)
@io.read(8)
@io.read(offset)
end
-
- return
end
-
- when 2
- brush_count = @io.read(2).unpack('n')[0]
- puts brush_count
- 1.upto(brush_count) do
-
- #Brush type, 1 = computed, 2 = sampled
- type = @io.read(2).unpack('n')[0]
-
- #Number of bytes in the remainder of the brush definition
- brush_bytes = @io.read(4).unpack('N')
-
- if type == 1
- @io.read(14) if @version == 1
- elsif type == 2
- @io.read(4) # Misc ignored
-
- #brush spacing
- spacing = @io.read(2).unpack('n')
- puts "SPACING: #{spacing}"
-
- # Length of the brush name
- name_length = @io.read(4).unpack('xxn')[0]
-
- #read it and convert it to utf-8
- utf8_name = @io.read(name_length * 2).unpack('C*').pack('U*')
- name = Iconv.iconv('UTF-8', 'UTF-16', utf8_name)[0].chop
- puts name
- @io.read(1) # Oh noez, the forgotton byte
-
- top, left, bottom, right = @io.read(8).unpack('nnnn')
-
- #long integer version of numbers above
- ltop, lleft, lbottom, lright = @io.read(16).unpack('NNNN')
-
- brush_width = lright - lleft
- brush_height = lbottom - ltop
-
- puts brush_width
- puts brush_height
-
- depth = @io.read(2).unpack('n')[0]
- puts "DEPTH: #{depth}"
- compression = @io.read(1).unpack('b')[0]
- puts "COMPRESSION: #{compression}"
-
- if compression == 0
- decompression_data = @io.read(brush_width * brush_height)
- else
- puts "HEIGHT: #{brush_height}"
- scanline_image = 0
- brush_height.times do
- scanline_image = scanline_image + @io.read(2).unpack('n')[0]
- end
- puts "SCI: #{scanline_image}"
- scan = @io.read(scanline_image)
- img = Magick::Image.new(brush_width, brush_height)
- unpacked_data = unpack_scanline_data(scan)
- img.import_pixels(0, 0, brush_width, brush_height, "A", unpacked_data, Magick::CharPixel)
- img.format = "PNG"
- img = img.colorize(1, 1, 1, '#000000')
- img.write('../../vendor/' + name.downcase + ".png")
- end
- end
- end
- end
end
# Unpack a scanline image using the PackBits algorithm.
@@ -183,7 +190,7 @@ def write_image(name, width, height, scanline_data)
end
end
-GroomLake::Brush.new('../../test/presets/three-various-brushes.abr')
+#GroomLake::Brush.new('../../test/presets/scary-girl.abr')
#GroomLake::Brush.new('../../test/presets/cs2-square-brushes.abr')
#GroomLake::Brush.new('../../test/presets/onesquare24hard.abr')
-#GroomLake::Brush.new('../../test/presets/cs2-oldbooks.abr')
+GroomLake::Brush.new('../../test/presets/cs2-oldbooks.abr')

0 comments on commit a24dd27

Please sign in to comment.