viktor 发表于 2013-4-24 12:17
楼主请问SinVideo.dll是怎么实现的使用DDraw往RGSSBitmap渲染?
因为在下在考虑这个问题http://bbs.66rpg ...
SinVideo 并非用 Shader 实现的,而是直接拿 RGSSBitmap 的内存区作为视频播放的缓冲区。
class ::Bitmap # API @@RtlMoveMemory_pl = Win32API.new('kernel32', 'RtlMoveMemory', 'pll', 'l') @@RtlMoveMemory_lp = Win32API.new('kernel32', 'RtlMoveMemory', 'lpl', 'l') def _dump(limit) data = "rgba" * width * height @@RtlMoveMemory_pl.call(data, address, data.length) [width, height, Zlib::Deflate.deflate(data)].pack("LLa*") # compress end def self._load(str) w, h, zdata = str.unpack("LLa*") bmp = new(w, h) @@RtlMoveMemory_lp.call(bmp.address, Zlib::Inflate.inflate(zdata), w * h * 4) return bmp end # [[[bitmap.object_id * 2 + 16] + 8] + 16] == header def address buffer, ad = "rgba", object_id * 2 + 16 @@RtlMoveMemory_pl.call(buffer, ad, 4) ad = buffer.unpack("L")[0] + 8 @@RtlMoveMemory_pl.call(buffer, ad, 4) ad = buffer.unpack("L")[0] + 16 @@RtlMoveMemory_pl.call(buffer, ad, 4) return buffer.unpack("L")[0] end end
class ::Bitmap
# API
@@RtlMoveMemory_pl = Win32API.new('kernel32', 'RtlMoveMemory', 'pll', 'l')
@@RtlMoveMemory_lp = Win32API.new('kernel32', 'RtlMoveMemory', 'lpl', 'l')
def _dump(limit)
data = "rgba" * width * height
@@RtlMoveMemory_pl.call(data, address, data.length)
[width, height, Zlib::Deflate.deflate(data)].pack("LLa*") # compress
end
def self._load(str)
w, h, zdata = str.unpack("LLa*")
bmp = new(w, h)
@@RtlMoveMemory_lp.call(bmp.address, Zlib::Inflate.inflate(zdata), w * h * 4)
return bmp
end
# [[[bitmap.object_id * 2 + 16] + 8] + 16] == header
def address
buffer, ad = "rgba", object_id * 2 + 16
@@RtlMoveMemory_pl.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 8
@@RtlMoveMemory_pl.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 16
@@RtlMoveMemory_pl.call(buffer, ad, 4)
return buffer.unpack("L")[0]
end
end
这个是关键,先获得 Bitmap 的数据区地址,然后 DShow 解码视频- GetCurrentBuffer(&rgssBitmapAddress, NULL)
复制代码 仅此而已。
因为某些原因不能直接公布源码,不过你可以看看这个:
https://github.com/Shy07/SINRGE2/blob/develop/SINRGE2%20Core/sin_video.cpp
和 SinVideo.dll 区别仅在于把 RGSSBitmap 换成了 HTEXTURE。 |