#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # Bitmap2Code by Blizzard # Version: 1.2 # Date: 22.6.2007 # Date 1.1: 10.1.2008 # Date 1.2: 23.3.2019 #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # # This work is licensed under BSD License 2.0: # # #---------------------------------------------------------------------------- # # # # Copyright (c) Boris "Blizzard" Mikić # # All rights reserved. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided that the following conditions are met: # # # # 1. Redistributions of source code must retain the above copyright notice, # # this list of conditions and the following disclaimer. # # # # 2. Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer in the # # documentation and/or other materials provided with the distribution. # # # # 3. Neither the name of the copyright holder nor the names of its # # contributors may be used to endorse or promote products derived from # # this software without specific prior written permission. # # # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # # POSSIBILITY OF SUCH DAMAGE. # # # #---------------------------------------------------------------------------- # # You may use this script for both non-commercial and commercial products # without limitations as long as you fulfill the conditions presented by the # above license. The "complete" way to give credit is to include the license # somewhere in your product (e.g. in the credits screen), but a "simple" way # is also acceptable. The "simple" way to give credit is as follows: # # Bitmap2Code licensed under BSD License 2.0 # Copyright (c) Boris "Blizzard" Mikić # # Alternatively, if your font doesn't support diacritic characters, you may # use this variant: # # Bitmap2Code licensed under BSD License 2.0 # Copyright (c) Boris "Blizzard" Mikic # # In general other similar variants are allowed as long as it is clear who # the creator is (e.g. "Bitmap2Code created by Blizzard" is acceptable). But # if possible, prefer to use one of the two variants listed above. # # If you fail to give credit and/or claim that this work was created by you, # this may result in legal action and/or payment of damages even though this # work is free of charge to use normally. # #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # # Compatibility # # Does not load normal resource image files. Easy to implement into any # script. 90% chance of full compatibility with SDK. # # # Idea # # Ever made a script, but you need to include several little image files for # it to work? This is not necessary anymore! With the Bitmap2Code converter # you can simply convert bitmap images into RGSS code. Instead of loading the # file into the memory from a file, the bitmap will be generated via code. # # # Function # # This little script allows you to quickly load bitmaps converted to code # with the Bitmap2Code.exe converter. # # # Features # # - instead of loading image files, the bitmaps will be generated via code # - optimizer recognizes same colors and optimizes generated code if possible # - several quality options to simplify code by decreasing the number of # colors # - easy to use: set up the config file, copy the files, run the converter # and just copy paste the generated code into your RGSS Editor # - easy to implement into any script: just call RPG::Cache.load_code("NAME") # instead of the usual bitmap loading methods # # # Example how to load a bitmap: # # bitmap = RPG::Cache.load_code("NAME") # # It is highly recommened to NOT use this converter on files with large # dimensions. If you do so anyway, please read Troubleshooting if you # encounter any problems. Also, read the Bitmap2Code converter readme for # further information. # # # Troubleshooting # # - Problem: # The converter decreases the quality of my bitmaps. # # - Solution: # Set the [Quantization Type] option in the Config.ini to 0 and lossless # conversion will be applied. # # - Problem: # I get the "Script is hanging" error during the conversion. # # - Solution: # This can only happen if you try to convert bitmaps of large dimentions. # There is no possibility to avoid this problem. However, you can decrease # the [Power] option in the Config.ini, but this will also slow down the # conversion. Another solution would be to decrease the quality of the # bitmap. # # # If you find any bugs, please report them here: # http://forum.chaos-project.com #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= #============================================================================== # module RPG::Cache #============================================================================== module RPG::Cache def self.load_code(file) return nil if file == '' key = [file, 'code'] if !@cache.include?(key) || @cache[key].disposed? eval("@cache[key] = Bitmap2Code.#{file}") end return @cache[key] end end