Author Topic: [XP][VX] Spritesheet Separator/Combiner  (Read 12078 times)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
[XP][VX] Spritesheet Separator/Combiner
« on: April 24, 2011, 03:56:55 AM »
Spritesheet Separator/Combiner
Authors: ForeverZer0
Version: 1.0
Type: Image Splitter/Combiner
Key Term: Game Utility

Introduction

This is a very basic script I wrote to help myself split up one of them big icon sheets into individual files. After admiring its niftiness for a second, I realized someone else may get some use out of it as well, so here it is. I have also included the ability to combine multiple images into a single one.

Features

  • Extremely simple to use.
  • Splits large icon/sprite sheets up into uniform images, then saves them as individual files in a matter of seconds.
  • Can seperate any image into pieces of any size.
  • Can combine separate files into a single sheet.
  • Lightweight and fast

Screenshots

None.

Demo

None.

Script

Click spoiler for the script.
(click to show/hide)

Instructions

Place script anywhere above main, place source file in game directory, make any needed adjustments to the configuration, then run the game.

Compatibility

None.

Credits and Thanks

  • ForeverZer0, for the script.

Author's Notes

Please report any bugs/issues, I'll be sure to help you resolve them.
« Last Edit: May 14, 2011, 09:08:40 PM by Baraka »
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline WhiteRose

  • Trying to code in Ruby
  • Moderator
  • Lexima Warrior
  • ***
  • Posts: 2341
  • LV: 127
  • Gender: Female
  • <3
    • View Profile
Re: [XP][VX] Spritesheet Seperator
« Reply #1 on: April 24, 2011, 04:30:25 AM »
Excellent! I was looking for something like this a few weeks ago. Great work!

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX] Spritesheet Seperator
« Reply #2 on: April 24, 2011, 04:49:25 AM »
Oh yeah, I did see that post. Sorry I forgot about it then, I could have made it for you faster.
The script only took a little bit to write.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Jragyn

  • Ethereal Devastator
  • ****
  • Posts: 311
  • LV: 20
  • Gender: Male
  • A prodigy... maybe? Hoo hah.
    • View Profile
    • facenbooken.
Re: [XP][VX] Spritesheet Seperator
« Reply #3 on: April 24, 2011, 04:38:03 PM »
Wait, so this essentially rips a VX -styled iconsheet apart into XP -styled icons?
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX] Spritesheet Seperator
« Reply #4 on: April 24, 2011, 07:08:25 PM »
Yes, that is what I made it for, though you it could also be used to split other images up too, but I imagine it will be most beneficial for them large icon-sheets you see around.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline G_G

  • Green Gmod Game_Guy AKA G4 AKA hyper-G AKA G-force
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 6585
  • LV: 407
  • Gender: Male
    • View Profile
Re: [XP][VX] Spritesheet Seperator
« Reply #5 on: April 24, 2011, 07:26:33 PM »
No offense, but this could be done in C# a lot faster and more user friendly. In fact I have a program for it I created awhile ago, I'm gonna dig it up when I leave mah g'mas.

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX] Spritesheet Seperator
« Reply #6 on: April 24, 2011, 08:02:18 PM »
Of course it could, but this is a simple copy-past of text into a program that the user already has.
I was originally going to write a C# app for it, but then its going to require someone to download .NET if they don't have it and download the program. Not everything is better just because its a little prettier. This is less than 7 kb of text and is ran on an existing platform and it takes less than 3 seconds to split a sheet. If you make a Windows form for it, you're going to end up with a file around 200-300 kb, and at most it is 2 seconds faster, but you have the above issues.

You don't always need some type of GUI to perform minor actions, and I hardly think changing the name of the file in RMXP's script editor is that big of a pain in the ass to warrant it.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Jragyn

  • Ethereal Devastator
  • ****
  • Posts: 311
  • LV: 20
  • Gender: Male
  • A prodigy... maybe? Hoo hah.
    • View Profile
    • facenbooken.
Re: [XP][VX] Spritesheet Seperator
« Reply #7 on: April 25, 2011, 06:53:15 PM »
And here all this time I've been using Paint.NET to cut out and paste icons as needed...
Now I can have a bit that does it for me <3

Thanks again to ForeverZero for his rising l33tness.

And though it wouldn't hurt to practice programming something of this nature in C#, it most certainly benefits those who already have RMXP and want to use it without loading an external program.
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

Offline Jragyn

  • Ethereal Devastator
  • ****
  • Posts: 311
  • LV: 20
  • Gender: Male
  • A prodigy... maybe? Hoo hah.
    • View Profile
    • facenbooken.
Re: [XP][VX] Spritesheet Seperator
« Reply #8 on: April 26, 2011, 08:44:52 PM »
(click to show/hide)

It keeps droppin' this error whenever I use it to cut up an iconsheet :(

I put it in a new project as instructed with the iconsheet in the game-directory...
and when I run it, it pauses a second... and pops that error. Every time.
It also cuts a seemingly random number of icons from the sheet before doing so, most of which just end up being black squares that are... well... not the icons.
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX] Spritesheet Seperator
« Reply #9 on: April 26, 2011, 11:44:14 PM »
That looks like a problem with Window's UAC. You are likely running as Admin and accessing non-Admin files or vice-versa. That is unavoidable, and there is no "script fix" for it, since the file access is being blocked by Windows. If your not already, run RMXP as Administrator, and make sure that the file/directory it is accessing belong to the Administrator, or just make sure that RMXP is being invoked by the same user that the files belong to.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX] Spritesheet Separator
« Reply #10 on: May 14, 2011, 09:08:19 PM »
Double-posts

I updated and renamed the script.
It can now also make spritesheets from multiple files just as easily.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline sasofrass

  • Trained Member
  • *
  • Posts: 49
  • LV: 0
    • View Profile
Re: [XP][VX] Spritesheet Separator/Combiner
« Reply #11 on: June 04, 2011, 08:18:29 PM »
I am trying to split this huge iconset but all it does is make the file larger and I can't get it working..

Here is the iconset:

https://dl-web.dropbox.com/get/set.png?w=60c350ab

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX] Spritesheet Separator/Combiner
« Reply #12 on: June 05, 2011, 06:36:47 AM »
You aren't configuring properly from the sounds of it.
On a side note, the link you gave me is not valid. It may be for you, but I can't access directly from your user page.

If you get another link, or better yet show me your config and I'll be happy to help.  ;)
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline sasofrass

  • Trained Member
  • *
  • Posts: 49
  • LV: 0
    • View Profile
Re: [XP][VX] Spritesheet Separator/Combiner
« Reply #13 on: June 05, 2011, 04:52:14 PM »
So stupid me didn't have it set to mode = 0 :P   but I think the icon set is too big, it says script is hanging.

Here is the iconset:
http://i795.photobucket.com/albums/yy236/pureiiipker/set.png

Here is my config currently:
Code: [Select]
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Spritesheet Seperator/Combiner
# Author: ForeverZer0
# Date: 5.14.2011
# Version: 1.0
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
#
# Introduction:
#   This is a very basic script I wrote to help myself split up one of them big
#   icon sheets into individual files. After admiring its niftiness for a sec, I
#   realized someone else may get some use out of it as well, so here it is.
#
# Features:
#   - Extremely simple to use.
#   - Splits large icon/sprite sheets up into uniform images, then saves them as
#     individual files in a matter of seconds.
#   - Can seperate any image into pieces of any size.
#   - Combines many images of any size into one single file
#   - Lightweight and fast
#
# Instructions:
#   - Place script in new project or temporarily in an existing game anywhere
#     before "Main"
#   - Make any needed changes to the few configurations at the top of the script
#   - Run the game
#
# Credits:
#   - ForeverZer0, for the script
#
# Author's Notes:
#   - Report bugs/issues at www.chaos-project.com
#
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
#                          BEGIN CONFIGURATION
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

MODE = 0
# Select the mode to run in.
#   0 = Split Image
#   1 = Combine Images

FOLDER_NAME = 'Images'
# The folder name that the images will be placed into, or the folder where
# the images are contained that will be combined.

#---------------------------------
# Image Splitting
#---------------------------------

SOURCE_FILE = 'set.png'
# The name of the source file that will be split. Place in game directory.

SPLIT_X = 24
SPLIT_Y = 24
# The width/height in pixels to split the image file into on each axis.

BASE_NAME = 'icon'
# The base name used for the output files.

NAMING_TYPE = 0
# Define the naming convention applied to the base name.
# 0 = Numerically. (icon 1, icon 2, icon 3, etc, etc)
# 1 = Coordinates. (icon 1x2, icon 3x4, icon 3x5, etc. etc)

#---------------------------------
# Image Combining
#---------------------------------

IMAGES_WIDE = 12
# The number of images that will be placed per row

FILENAME = 'combined'
# The output filename

#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
#                           END CONFIGURATION
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

module Zlib
  class Png_File < GzipWriter
#-------------------------------------------------------------------------------
    def make_png(bitmap_Fx,mode)
      @mode = mode
      @bitmap_Fx = bitmap_Fx
      self.write(make_header)
      self.write(make_ihdr)
      self.write(make_idat)
      self.write(make_iend)
    end
#-------------------------------------------------------------------------------
    def make_header
      return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")
    end
#-------------------------------------------------------------------------------
    def make_ihdr
      ih_size = [13].pack("N")
      ih_sign = "IHDR"
      ih_width = [@bitmap_Fx.width].pack("N")
      ih_height = [@bitmap_Fx.height].pack("N")
      ih_bit_depth = [8].pack("C")
      ih_color_type = [6].pack("C")
      ih_compression_method = [0].pack("C")
      ih_filter_method = [0].pack("C")
      ih_interlace_method = [0].pack("C")
      string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
               ih_compression_method + ih_filter_method + ih_interlace_method
      ih_crc = [Zlib.crc32(string)].pack("N")
      return ih_size + string + ih_crc
    end
#-------------------------------------------------------------------------------
    def make_idat
      header = "\x49\x44\x41\x54"
      data = make_bitmap_data
      data = Zlib::Deflate.deflate(data, 8)
      crc = [Zlib.crc32(header + data)].pack("N")
      size = [data.length].pack("N")
      return size + header + data + crc
    end
#-------------------------------------------------------------------------------
    def make_bitmap_data1
      w = @bitmap_Fx.width
      h = @bitmap_Fx.height
      data = []
      for y in 0...h
        data.push(0)
        for x in 0...w
          color = @bitmap_Fx.get_pixel(x, y)
          red = color.red
          green = color.green
          blue = color.blue
          alpha = color.alpha
          data.push(red)
          data.push(green)
          data.push(blue)
          data.push(alpha)
        end
      end
      return data.pack("C*")
    end
#-------------------------------------------------------------------------------
    def make_bitmap_data
      gz = Zlib::GzipWriter.open('hoge.gz')
      t_Fx = 0
      w = @bitmap_Fx.width
      h = @bitmap_Fx.height
      data = []
      for y in 0...h
        data.push(0)
        for x in 0...w
          t_Fx += 1
          if t_Fx % 10000 == 0
            Graphics.update
          end
          if t_Fx % 100000 == 0
            s = data.pack("C*")
            gz.write(s)
            data.clear
          end
          color = @bitmap_Fx.get_pixel(x, y)
          red = color.red
          green = color.green
          blue = color.blue
          alpha = color.alpha
          data.push(red)
          data.push(green)
          data.push(blue)
          data.push(alpha)
        end
      end
      s = data.pack("C*")
      gz.write(s)
      gz.close   
      data.clear
      gz = Zlib::GzipReader.open('hoge.gz')
      data = gz.read
      gz.close
      File.delete('hoge.gz')
      return data
    end
#-------------------------------------------------------------------------------
    def make_iend
      ie_size = [0].pack("N")
      ie_sign = "IEND"
      ie_crc = [Zlib.crc32(ie_sign)].pack("N")
      return ie_size + ie_sign + ie_crc
    end
  end
end

#===============================================================================
# ** Bitmap
#===============================================================================

class Bitmap

  def make_png(name="like", path="",mode=0)
    make_dir(path) if path != ""
    Zlib::Png_File.open("temp.gz") {|gz| gz.make_png(self, mode) }
    Zlib::GzipReader.open("temp.gz") {|gz| $read = gz.read }
    f = File.open(path + name + ".png","wb")
    f.write($read)
    f.close
    File.delete('temp.gz')
    end
#-------------------------------------------------------------------------------
  def make_dir(path)
    dir = path.split("/")
    dir.each_index {|i|
      unless dir == "."
        add_dir = dir[0..i].join("/")
        begin
          Dir.mkdir(add_dir)
        rescue
        end
      end
    }
  end
end

#===============================================================================
# Processing
#===============================================================================

time = Time.now

if MODE == 0
  bitmap = Bitmap.new(SOURCE_FILE)
  count = 0
  (0...(bitmap.width / SPLIT_X)).each {|x| (0...(bitmap.height / SPLIT_Y)).each {|y|
    count += 1
    icon = Bitmap.new(SPLIT_X, SPLIT_Y)
    rect = Rect.new(x * SPLIT_X, y * SPLIT_Y, SPLIT_X, SPLIT_Y)
    icon.blt(0, 0, bitmap, rect)
    name = (BASE_NAME + (NAMING_TYPE == 0 ? " #{count}" : " #{x+1}x#{y+1}"))
    icon.make_png(name, FOLDER_NAME + '/')
    if count % 80 == 0
      Graphics.update
    end
  }}

elsif MODE == 1
 
  images = Dir.entries(FOLDER_NAME) - ['.', '..']
  if images.empty?
    print("No image files found in #{FOLDERNAME} directory.")
    exit
  end
  images.collect! {|filename| Bitmap.new("#{FOLDER_NAME}/#{filename}") }
  w, h, num = images[0].width, images[0].height, images.size
  canvas = Bitmap.new(w * IMAGES_WIDE, (num.to_f / IMAGES_WIDE).ceil * h)
  images.each_with_index {|image, i|
    x, y = (i % IMAGES_WIDE) * w, (i / IMAGES_WIDE) * h
    canvas.blt(x, y, image, Rect.new(0, 0, w, h))
    if (i % 80) == 0
      Graphics.update
    end
  }
  canvas.make_png(FILENAME, '')
end

print ("Process Complete!\n" +
      "#{count} images converted in #{Time.now.to_f - time.to_f} seconds.")
exit

EDIT: i keep running it and it is making about 30-50 icons every time. It works

EDIT 2: after it made 333 icons, it now says not in gzip format
« Last Edit: June 05, 2011, 04:55:42 PM by sasofrass »

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX] Spritesheet Separator/Combiner
« Reply #14 on: June 05, 2011, 05:17:42 PM »
Your spritesheet isn't using 24x24 icons like what you have defined in the config, there 8x8. I just ran it and got over 2000 icons.

http://dl.dropbox.com/u/20787370/test.zip

Here they are.

I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline sasofrass

  • Trained Member
  • *
  • Posts: 49
  • LV: 0
    • View Profile
Re: [XP][VX] Spritesheet Separator/Combiner
« Reply #15 on: June 08, 2011, 05:19:16 AM »
8x8?

I downloaded your file and they're extremely small and I can't even use them as icons.


Edit:  The icon set I gave you must have shrunk, they should have been 24x24 :\
« Last Edit: June 08, 2011, 05:25:09 AM by sasofrass »

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX] Spritesheet Separator/Combiner
« Reply #16 on: June 08, 2011, 05:28:18 AM »
Yes, the file you gave had 8x8 icons. I just split them that way. Either way it worked okay. If you get me the actual sheet, unshrunk, I can do the same.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline sasofrass

  • Trained Member
  • *
  • Posts: 49
  • LV: 0
    • View Profile
Re: [XP][VX] Spritesheet Separator/Combiner
« Reply #17 on: June 10, 2011, 05:40:29 PM »
Thanks.


Hopefully this doesn't shrink :\

http://www.mediafire.com/?xfmc2ckpm2dp06x

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX] Spritesheet Separator/Combiner
« Reply #18 on: June 11, 2011, 01:46:59 AM »


Converted Icons

The empty icons or any icons that appear as all black are because of the empty space in the sheet. I cropped the left side, but I didn't bother with the empty rows in between.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline sasofrass

  • Trained Member
  • *
  • Posts: 49
  • LV: 0
    • View Profile
Re: [XP][VX] Spritesheet Separator/Combiner
« Reply #19 on: June 18, 2011, 09:11:49 PM »
That is so boss.