2014-04-30 15:24:44 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local CacheItem = require("cacheitem")
|
2014-04-30 15:24:44 +00:00
|
|
|
local serial = require("serialize")
|
2013-10-22 18:51:29 +00:00
|
|
|
local DEBUG = require("dbg")
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
local TileCacheItem = CacheItem:new{}
|
|
|
|
|
|
|
|
function TileCacheItem:onFree()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.bb.free then
|
|
|
|
DEBUG("free blitbuffer", self.bb)
|
|
|
|
self.bb:free()
|
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
2014-04-30 15:24:44 +00:00
|
|
|
function TileCacheItem:dump(filename)
|
|
|
|
DEBUG("dumping tile cache to", filename, self.excerpt)
|
|
|
|
return serial.dump(self.size, self.excerpt, self.pageno,
|
|
|
|
self.bb.w, self.bb.h, self.bb.pitch, self.bb:getType(),
|
|
|
|
Blitbuffer.tostring(self.bb), filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
function TileCacheItem:load(filename)
|
|
|
|
local w, h, pitch, bb_type, bb_data
|
|
|
|
self.size, self.excerpt, self.pageno,
|
|
|
|
w, h, pitch, bb_type, bb_data = serial.load(filename)
|
|
|
|
self.bb = Blitbuffer.fromstring(w, h, bb_type, bb_data, pitch)
|
|
|
|
DEBUG("loading tile cache from", filename, self)
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return TileCacheItem
|