• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
  • Apologies if you've had troubles connecting to the site, you may need a VPN to access it. Staff are also facing issues connecting, so if it's urgent please message Cat on-site or through Discord directly.
  • Hey Guest, staff applications are open! If you are interested in becoming a forum staff member and/or Discord staff member, please apply through this Google Form before April 2! You can also message Cat with any questions.
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
1,108
Views
1,967
First release
Last update

Ratings

0.00 star(s) 0 ratings

More resources from boonzeet

Back
Top