[haiku-3rdparty-dev] Re: Getting svg icons out of an rdef file

  • From: Pete Goodeve <pete.goodeve@xxxxxxxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Sun, 18 Jan 2015 15:31:50 -0800

On Sun, Jan 18, 2015 at 01:01:23PM -0700, ryanmk54 . wrote:
> I am trying to create a javascript version of Critical Mass
> (http://haikuware.com/directory/view-details/games/strategy/critical-mass-23)
> and wanted to use the same icons that are in the haiku version of the
> game.  I was able to compile the Resources.rdef into a rsrc file.  I
> could then use QuickRes to get a image out of the file, but I didn't
> see an option to get the vector out the of file.  Is there a way to
> get the original svgs that the app uses?
>

I thought that Icon-O-Matic would read an icon rdef file, but apparently not...
 
However, the (text) icon data in the rdef is just a hex representation
of the (original) binary hvif, which Icon-O-Matic *will* read.

So -- as a service to the community (:-)) -- I present a little Ruby script
that converts an rdef (containing *only* the 'VICN' section back into
an hvif, "rdef2hvif.rb":

#! /bin/env ruby

open(ARGV[0]) {|f|
        out = ""
        outname = File.basename(ARGV[0], ".rdef")+".hvif"
        f.each_line {|ln|
                part = ln[/\$"(.*)"/,1]
                if part then
                        i = 0
                        while (v = part[i,2]) != ""
                                byte = v.hex
                                out << byte
                                i += 2
                        end
                end             
        }
        open(outname, "w") {|hvif| hvif.write(out)}
}


If you haven't got Ruby, get it from HaikuDepot.  (I would have
written it in Python, but it's so long since I've used it that I'd
have had to look *everything* up, rather that just half of it!)

To use it just make the script executable and run:

   rdef2hvif.rb <source>.rdef

where <source>.rdef is a file containing only the icon data
(use an editor if necessary).  It should generate "<source>.hvif",
which you can import into I-O-M and export an SVG.

HTH,

        -- Pete --

Other related posts: