Project1

标题: PNG文件输出[发布预备] [打印本页]

作者: 小传子    时间: 2008-6-14 05:05
标题: PNG文件输出[发布预备]
  1. #==============================================================================
  2. # PNG文件输出
  3. #   用法:bitmap.save2png(filename)
  4. # BY:轮回者
  5. #==============================================================================

  6. class Bitmap  
  7.   
  8.   # 是否自动颠倒上下?
  9.   #   false时输出图像上下会颠倒,但并不能节省很多时间
  10.   SWITCH_UP2DOWN = true
  11.   
  12.   # 存入PNG文件
  13.   def save2png(filename)
  14.     file = File.open(filename,"wb")
  15.     file.write(make_png_header)
  16.     file.write(make_png_ihdr)
  17.     file.write(make_png_idat)
  18.     file.write(make_png_iend)
  19.     file.close
  20.   end
  21.   
  22.   # PNG文件头数据块
  23.   def make_png_header
  24.     return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")
  25.   end

  26.   # PNG文件情报头数据块(IHDR)
  27.   def make_png_ihdr
  28.     ih_size = [13].pack("N")
  29.     ih_sign = "IHDR"
  30.     ih_width = [width].pack("N")
  31.     ih_height = [height].pack("N")
  32.     ih_bit_depth = [8].pack("C")
  33.     ih_color_type = [6].pack("C")
  34.     ih_compression_method = [0].pack("C")
  35.     ih_filter_method = [0].pack("C")
  36.     ih_interlace_method = [0].pack("C")
  37.     string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
  38.             ih_compression_method + ih_filter_method + ih_interlace_method
  39.     ih_crc = [Zlib.crc32(string)].pack("N")
  40.     return ih_size + string + ih_crc
  41.   end
  42.   
  43.   # PNG图像数据(IDAT)
  44.   def make_png_idat
  45.     header = "\x49\x44\x41\x54"
  46.     data = SWITCH_UP2DOWN ? make_png_data : make_png_data2
  47.     data = Zlib::Deflate.deflate(data, 8)
  48.     crc = [Zlib.crc32(header + data)].pack("N")
  49.     size = [data.length].pack("N")
  50.     return size + header + data + crc
  51.   end
  52.   
  53.   # PNG图像数据(点阵);自动颠倒上下
  54.   def make_png_data
  55.     data = get_data.unpack('x2aX2aX2ax2a'*height*width).to_s
  56.     len = width * 4      
  57.     for y in 0...height
  58.       break if 2*y >= height - 1
  59.       nth1 = y * len      
  60.       nth2 = (height - 1 - y) * len      
  61.       tStr = data[nth1,len]      
  62.       data[nth1, len] = data[nth2, len]      
  63.       data[nth2, len] = tStr
  64.     end
  65.    
  66.     for y in 0...height
  67.       nth = (height - 1 - y) * width * 4
  68.       data.insert(nth,"\000")
  69.     end
  70.     return data
  71.   end
  72.   
  73.   # PNG图像数据(点阵);不自动颠倒上下
  74.   def make_png_data2
  75.     data = get_data.unpack('x2aX2aX2ax2a'*height*width).to_s
  76.     for y in 0...height
  77.       nth = (height - 1 - y) * width * 4
  78.       data.insert(nth,"\000")
  79.     end
  80.     return data
  81.   end  
  82.   
  83.   # PNG文件尾数据块(IEND)
  84.   def make_png_iend
  85.     ie_size = [0].pack("N")
  86.     ie_sign = "IEND"
  87.     ie_crc = [Zlib.crc32(ie_sign)].pack("N")
  88.     return ie_size + ie_sign + ie_crc
  89.   end
  90.   
  91.   # 获取数据
  92.   def get_data
  93.     data = "rgba" * width * height
  94.     RtlMoveMemory_pi.call(data, address, data.length)
  95.     return data
  96.   end
  97. end

  98. #==============================================================================
  99. # Bitmap类修改尝试
  100. #==============================================================================

  101. class Bitmap
  102.   # 取得点(x,y)的颜色(Color)
  103.   def get_pixel_plus(x, y)
  104.     data = "rgba"
  105.     nth = ((height - 1 - y) * width + x) * data.length
  106.     RtlMoveMemory_pi.call(data, address + nth, data.length)   
  107.     clr_ary = data.unpack('c*')
  108.     return Color.new(clr_ary[2],clr_ary[1],clr_ary[0],clr_ary[3])
  109.   end
  110.   
  111.   # 设定点(x,y)的颜色为 color(Color)
  112.   def set_pixel_plus(x, y, color)
  113.     data = [color.blue,color.green,color.red,color.alpha].pack('c*')
  114.     nth = ((height - 1 - y) * width + x) * data.length
  115.     RtlMoveMemory_ip.call(address + nth, data, data.length)
  116.     return self
  117.   end
  118. end

  119. #==============================================================================
  120. # 快速存储Bitmap的Marshal(修改版)By 柳之一
  121. #==============================================================================
  122. class Font
  123.   def marshal_dump;end
  124.   def marshal_load(obj);end
  125. end

  126. class Bitmap
  127.   attr_accessor :address
  128.   # 初始化传送到内存的API函数
  129.   RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
  130.   RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')
  131.   
  132.   # 保存
  133.   def _dump(limit)
  134.     data = "rgba" * width * height
  135.     RtlMoveMemory_pi.call(data, address, data.length)
  136.     [width, height, Zlib::Deflate.deflate(data)].pack("LLa*") # 压缩
  137.   end
  138.   
  139.   # 读取
  140.   def self._load(str)
  141.     w, h, zdata = str.unpack("LLa*"); b = new(w, h)
  142.     RtlMoveMemory_ip.call(b.address, Zlib::Inflate.inflate(zdata), w * h * 4); b
  143.   end
  144.   
  145.   # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
  146.   #
  147.   def address
  148.     @address = ini_address if @address.nil?
  149.     return @address
  150.   end
  151.   
  152.   def ini_address
  153.     buffer, ad = "xxxx", object_id * 2 + 16
  154.     RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 8
  155.     RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 16
  156.     RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0]
  157.     return ad
  158.   end
  159. end

  160. #==============================================================================
  161. # 回收站~
  162. #==============================================================================

  163. =begin
  164. class Color_Plus
  165.   # 初始化实例变量
  166.   attr_accessor :red
  167.   attr_accessor :green
  168.   attr_accessor :blue
  169.   attr_accessor :alpha

  170.   # 初始化
  171.   def initialize(red, green, blue, alpha=255)
  172.     @red   = red
  173.     @green = green
  174.     @blue  = blue
  175.     @alpha = alpha
  176.   end
  177.   
  178.   # 设定所有属性
  179.   def set(red, green, blue, alpha=255)
  180.     @red   = red
  181.     @green = green
  182.     @blue  = blue
  183.     @alpha = alpha
  184.   end
  185. end
  186. =end

复制代码
用到了某柳的东西,感觉轮子这个还是不错的{/hx}
作者: hide秀    时间: 2008-6-14 17:53
和小夏的那个制作PNG很像啊~不过支持~{/qiang}
作者: yangff    时间: 2008-6-18 03:59
优化的什么?
速度?


快速存储Bitmap的Marshal(修改版)By 66
版权有错,是柳之一哦 {/hx}
作者: Infrared    时间: 2008-6-22 00:11
提示: 作者被禁止或删除 内容自动屏蔽
作者: 柳之一    时间: 2008-6-22 09:35
以下引用Infrared于2008-6-21 16:11:26的发言:

很多解密方法输出图片的核心都是轮回者的PNG文件输出脚本,把PNG输出部份改成了这个之后,速度快了1倍。原本30MB游戏要20-30分钟。

#============================================================================
# *** RGSSAD Extractor version 1.02, created by vgvgf
#============================================================================
*** RGSSAD Extraction - Started at 21/06/2008(d/m/y) 15:46:41
* Sprites founded inside the scripts - Total 68
省略

*** RGSSAD Extraction - Finished at 21/06/2008(d/m/y) 16:04:24 - Extraction time 00:11:58




[本贴由作者于 2008-6-21 16:12:18 最后编辑]



哈哈,你也这么用啦。原来都用在邪恶的地方。

夏娜的png输出造成了rm无密可加的状态。难道要我自己写加密啊,太麻烦,解密的就好了。{/hx}
作者: 灼眼的夏娜    时间: 2008-6-22 20:16
哈哈,你也这么用啦。原来都用在邪恶的地方。

夏娜的png输出造成了rm无密可加的状态。难道要我自己写加密啊,太麻烦,解密的就好了。

写吧写吧 偶以后用= =啊哈哈- -``
作者: yangff    时间: 2008-6-22 20:28
以下引用灼眼的夏娜于2008-6-22 12:16:02的发言:



哈哈,你也这么用啦。原来都用在邪恶的地方。

夏娜的png输出造成了rm无密可加的状态。难道要我自己写加密啊,太麻烦,解密的就好了。


写吧写吧 偶以后用= =啊哈哈- -``

也?
消失百年的人出现了 {/fd}
作者: 禾西    时间: 2008-6-27 21:44
偶然發現自己居然還有發布和加VIP的權限 = =
發布完畢,VIP += 3
作者: hide秀    时间: 2008-6-27 21:56
虽然自己也想写个~不过这个脚本确实很好~很实用~很方便 省得自己写的麻烦了
又见小夏回帖~{/jy}
作者: danny8376    时间: 2008-7-6 06:47
这是直接调用内存输出PNG的
直接把内存的点阵资料转存
因为一次就把全部的点阵信息输出了
所以效率比一点一点的读快多了

我之前有尝试过
但就苦在不知如何对内存的资料解码

话说有个有趣的事
内存的图是上下颠倒的耶
作者: yanzheng868    时间: 2008-7-6 23:58
#============================================================================
# *** RGSSAD Extractor version 1.02, created by vgvgf
#============================================================================
*** RGSSAD Extraction - Started at 21/06/2008(d/m/y) 15:46:41
* Sprites founded inside the scripts - Total 68
省略

*** RGSSAD Extraction - Finished at 21/06/2008(d/m/y) 16:04:24 - Extraction time 00:11:58
[/quote]

……
这东西已经普及了么
RGSSAD释放者
作者: 苏菲娅    时间: 2008-7-7 07:51
以下引用yanzheng868于2008-7-6 15:58:35的发言:

……
这东西已经普及了么
RGSSAD释放者

[本贴由作者于 2008-7-6 15:59:53 最后编辑]

下午偶然在某港站bbs上看到此物
而且不用注册就可以下...{/gg}
#=============================================================================
# *** RGSSAD Extractor
#=============================================================================
# Created by vgvgf
# Version: 1.02
# Last Modification: 20/03/08
#=============================================================================
# *** Author's Note
# Stealing is bad, realy bad. Don't do that! If you want to cheat a game, or
# if you are curious and want to know how a game is made for learning, that's
# OK, but if you are stealing unique scripts or graphics, you are a bad
# person.
# PD: I will kill a kitty for each stolen resource.
#=============================================================================
# *** Credits
#   * www.66rpg.com
#     - PNG files saver
#=============================================================================
# *** Version Histiory
#  - 1.00, 15/03/08
#    First Release
#  - 1.01, 19/03/08
#    Fixed a little bug.
#    Better modified RGSS102E.dll.
#  - 1.02, 20/03/08
#    Fixed fatal error when reading RGSSAD Data.txt and RGSSAD Graphics.txt.
#    Removed FileUtils.rb dependency.
#    Removed REAL_TIME_LOGGER, now it is by default.
#    Improved code.
#=============================================================================
# *** Description
# This program will extract the files contained by the RGSSAD files. The
# only problem, is that for extracting a file it needs to have the file's path.
# So it try to read all the programs data(Actors, classes, maps, events, etc)
# in search of the file paths, but if the paths are in the scripts the program
# may not obtain all the paths.
#=============================================================================
# *** How to use
# First, you need to place this "RGSSAD Extractor.rb" file, and the
# "RGSS102E.dll" in the game folder. You will need to change the "Library"
# field from the "Game.ini" file to "RGSS102E.dll", and after that execute
# Game.exe.
#
# This script will try to extract all the files listed in the database of the
# game, including maps and events. It will also read all the strings included
# in the scripts(Scripts.rxdata, and events) and search for sprites if the
# SCRIPT_STRINGS_READER flag is on, but it may doesn't work at 100%.
# So if it can't extract some files, you can use IN_GAME_EXTRACTOR option
# for extracting the sprites when playing the game, but it will only
# extract the sprites loaded by the game, so you will need to play the game
# until all sprites are loaded by it.
# You can also create a file named "RGSSAD Graphics.txt" in the game folder,
# containing the paths of the files(one path per line) that aren't listed in
# the database, events or maps; for manualy adding them into the extract list.
#
# * INCLUDE_RTP
# If you want to extract the files, that are already listed in the rtps, use
# this option. This may be useful, when the game have resources that have been
# edited from the rtp, and they conserve the same name. You can also use
# the "RGSSAD Graphics.txt" file for the same purpose, if you know the name
# of the edited files.
#
# * IN_GAME_EXTRACTOR
# This option will extract all the files used by the game when playing it.
# It's very useful, when the game stores the files path in the scripts data.
# The bad part is that you will need to play the game for extracting the sprites.
# It also puts the $DEBUG variable to true, and includes a frame skipper, for
# playing faster. For activating it press F5, and it will skip 5 frames per
# each Graphics.update, you can still press F5 for adding more frames to skip,
# you can press F6 for reducing the amount of frames to skip, and with F7 you
# will reset the frame skipper to normal speed.
#
# * SCRIPT_STRINGS_READER
# If this option is on, the extractor will read all the strings included in
# the scripts and will search for more sprites to extract. It is useful, when
# there are some sprites only listed in the scripts data.
#
# * "RGSSAD Graphics.txt"
# If you want to extract specifical graphic files from a RGSSAD, that aren't
# included in the database data, you can add a list of them in this file.
# You can inlude one file's path per line in this file. It must be a complete
# path for example: Graphics/Characters/Hero1
# You can also include files that aren't placed in the default folders, for
# example: Graphics/Cursors/Red Cursor
# Note: Don't use the file extensions here.
#
# * "RGSSAD Data.txt"
# If you want to extract specifical data files from a RGSSAD, that aren't
# the default ones, you can add a list of them in this file.
# You can inlude one file's path per line in this file. It must be a complete
# path for example: Data/Options.rxdata
# You can also include files that aren't placed in the default data folder,
# or have diferent extension, for example: BattleData/Battle01.bin
# Note: You need to include the extensions here.
#=============================================================================

if $RGSS_SCRIPTS.nil?
  Thread.new {system('Game.exe')}
  exit
end

#=============================================================================
# *** Options (Edit freely here)
#=============================================================================
INCLUDE_RTP = false
IN_GAME_EXTRACTOR = false
SCRIPT_STRINGS_READER = true

#=============================================================================
# *** Classes & methods definitions
#=============================================================================
#=============================================================================
# ** ZLIB
#=============================================================================
module Zlib
省略...
end

#=============================================================================
# ** Bitmap
#=============================================================================
class Bitmap
省略...
end

#=============================================================================
# ** Make folders
#=============================================================================
def create_folder(path)
省略...

end

#=============================================================================
# ** Copy file
#=============================================================================
def copy_file(s, d)
  begin
省略...
end

#=============================================================================
# ** Extract Data
#=============================================================================
def extract_data(o, f, saved_data = [])
省略...

end

#=============================================================================
# *** Initialize
#=============================================================================
log = File.open('RGSSAD Extractor log.txt', 'w')
省略...
#=============================================================================
# *** Script's strings reader
#=============================================================================
string_reader = false
省略...
end

#=============================================================================
# *** Search graphics files
#=============================================================================
sprites = {}
省略...

#=============================================================================
# ** Graphics List check
#=============================================================================
if FileTest.exists?('RGSSAD Graphics.txt')
省略...
#=============================================================================
# ** Extract data files
#=============================================================================
省略...
#=============================================================================
# *** Extract graphic files
#=============================================================================
省略...

#=============================================================================
# *** Finalize
#=============================================================================
log.puts("*** RGSSAD Extraction - #{Time.now.strftime("Finished at %d/%m/%Y(d/m/y) %H:%M:%S")} - Extraction time #{sprintf("%02d", h)}:#{sprintf("%02d", m)}:#{sprintf("%02d", s)}")省略...

#=============================================================================
# ** In Game Extraction
#=============================================================================
省略...
省略...
省略...
省略...
省略...
省略...
end

作者: 暫時用來說話    时间: 2008-7-7 08:00
提示: 作者被禁止或删除 内容自动屏蔽
作者: 苏菲娅    时间: 2008-7-7 08:14
没错是这个站

虽然我猜这工具无可避免地会泛滥起来
但为了不让部分隐私意识特强的人感到难过
楼上的还是编辑掉吧{/gg}

同时建议高人研究有效的加密脚本
加密和解密的戏才能继续唱下去...大家的脚本技术也会随之提高...{/hx}
作者: 暫時用來說話    时间: 2008-7-7 08:35
提示: 作者被禁止或删除 内容自动屏蔽
作者: yanzheng868    时间: 2008-7-8 03:07
那个站有成人内容
未成年人误入!
(小声的:包括我自己)
作者: Infrared    时间: 2008-7-8 03:23
提示: 作者被禁止或删除 内容自动屏蔽
作者: dna_7086    时间: 2008-7-8 11:05
提示: 作者被禁止或删除 内容自动屏蔽
作者: 轮回者    时间: 2008-7-9 00:17
以下引用danny8376于2008-7-5 22:47:34的发言:

这是直接调用内存输出PNG的
直接把内存的点阵资料转存
因为一次就把全部的点阵信息输出了
所以效率比一点一点的读快多了

我之前有尝试过
但就苦在不知如何对内存的资料解码

话说有个有趣的事
内存的图是上下颠倒的耶


不止如此!
修复上下颠倒不耗时间,但内存中的某点的储存格式是"bgra",改回“rgba”才费时





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1