Last active
August 29, 2015 13:58
-
-
Save RPGP1/10013327 to your computer and use it in GitHub Desktop.
Image#marshal_dump/marshal_load作った。ひとまずこれで凌ぐ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: ASCII | |
require 'dxruby' | |
require 'zlib' | |
module DXRuby | |
class Image | |
def marshal_dump | |
image_data = [] | |
for y in 0...height | |
image_data.push(0) | |
for x in 0...width | |
temp = self[x,y] | |
temp.push(temp.shift) # ARGB→RGBA | |
image_data.concat(temp) | |
end | |
end | |
def chunk(type, data) | |
[data.size, type, data, Zlib.crc32(type + data)].pack("NA4A*N") | |
end | |
"\x89PNG\r\n\x1a\n" + | |
chunk("IHDR", [width, height, 8, 6, 0, 0, 0].pack("NNCCCCC")) + | |
chunk("IDAT", Zlib::Deflate.deflate(image_data.pack("C*"))) + | |
chunk("IEND", "") | |
end | |
def marshal_load(str) | |
img = Image.loadFromFileInMemory(str) | |
self.__send__(:initialize_copy, img) | |
img.dispose | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment