Skip to content

Instantly share code, notes, and snippets.

@RPGP1
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RPGP1/10013327 to your computer and use it in GitHub Desktop.
Save RPGP1/10013327 to your computer and use it in GitHub Desktop.
Image#marshal_dump/marshal_load作った。ひとまずこれで凌ぐ。
# 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