• The Eevee Expo Game Jam #10 has concluded, congratulations to all participants! Now it's time for the judges to play through the games, and you can play along to vote who deserves the community choice spotlight.
    You can check out the submitted games here!
    Play through the games and provide some feedback to the devs while you're at it!
  • Hi, Guest!
    Some images might be missing as we move away from using embedded images, sorry for the mess!
    From now on, you'll be required to use a third party to host images. You can learn how to add images here, and if your thread is missing images you can request them here.
    Do not use Discord to host any images you post, these links expire quickly!
Simple Bitmap Color Palette Swapper

Simple Bitmap Color Palette Swapper 1.0

Pokémon Essentials Version
Non-applicable
l8GEOrZ.gif


Simple C++ Library to swap colours of an input RPG Maker Bitmap.
Takes two input CSV-formatted color palettes to swap, one for the other.

This allows you to create simple greyscale or other images which can then be dynamically colorized, for example to create a character or item customisation option.

To use:

Download Release/PaletteSwap.dll from the GitHub repository. Place this in the root folder of your project.

Next, place this script above Main:
Code:
Expand Collapse Copy
module PaletteSwap
  VERSION = 1.0
  DLL_NAME = 'PaletteSwap' # Optionally change this to store the DLL elsewhere

  module Error
    def self.raise_error(err, obj, msg)
      klass = obj.class.to_s
      stack = caller.slice(1..15)
      stack.each do |i|
        script = i.scan(/\d+/)[0]
        i.sub!(/{\d+}/, $RGSS_SCRIPTS.at(script.to_i)[1]) if script
      end
      raise err, msg % klass << "\n\n#{stack.join("\n")}"
    end
    def self.raise_bitmap(bitmap)
      raise_error(RGSSError, bitmap, "%s is a disposed or invalid bitmap!")
    end
  end
end


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

class Bitmap
  @@colorize = Win32API.new(PaletteSwap::DLL_NAME, 'Colorize', ['l', 'p', 'p'], 'l').freeze

  # Colorize call
  def colorize!(og_palette, new_palette)
    PaletteSwap::Error::raise_bitmap(self) if self.disposed?
    @@colorize.call(object_id, og_palette, new_palette)
  end
end

Then call like so (example from Essentials):
Code:
Expand Collapse Copy
bmp = BitmapCache.load_bitmap("example.png")
bmp.colorize!("75,75,75\n105,105,105\n135,135,135", "50,65,98\n65,96,159\n57,119,198")

The palette sizes should be the same length. Please ensure these strings are properly formatted with the RGB values separated by commas and each separate color separated by "\n".

This will swap each color in the first list, e.g. rgb(105,105,105), with the corresponding item in the second list, i.e. rgb(65,96,159).

I'm using this for a clothing generator, but I thought this could potentially have more uses to a wider audience.

Credit to Copern for the error handling in the RGSS script, which is based on his version.
Credits
Please credit Boonzeet if used.
Author
boonzeet
Downloads
967
Views
1,879
First release
Last update

Ratings

0.00 star(s) 0 ratings

More resources from boonzeet

Back
Top