This repository has been archived by the owner on Aug 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
JobThread.lua
46 lines (37 loc) · 1.7 KB
/
JobThread.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--Texture Unpacker By RamiLego4Game--Github: https://github.com/RamiLego4Game/Texture-Unpacker .--
--[[
Copyright 2016 Rami Sabbagh
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
require("love.thread")
require("love.image")
local JSON = require("JSON")
local SDC = love.thread.getChannel("SDC") --Sheet Directory Channel
local SIC = love.thread.getChannel("SIC") --Sheet Image Channel
local JTC = love.thread.getChannel("JTC") --Job Target Channel
local RC = love.thread.getChannel("RC") --Results Channel
local SheetDirectory = SDC:demand()
local SheetImage = SIC:demand()
local JobTarget = JTC:demand()
while JobTarget do
local Target = JSON:decode(JobTarget)
--if Target.trimmed then Target.spriteSourceSize.x, Target.spriteSourceSize.y = Target.spriteSourceSize.x-1, Target.spriteSourceSize.y-1 end
local Image = love.image.newImageData(Target.sourceSize.w,Target.sourceSize.h)
for x = 0,Target.frame.w-1 do
for y = 0,Target.frame.h-1 do
Image:setPixel(x+Target.spriteSourceSize.x,y+Target.spriteSourceSize.y,
SheetImage:getPixel(Target.frame.x+x,Target.frame.y+y))
end
end
Image:encode("png",SheetDirectory..Target.filename)
RC:push(Target.filename)
JobTarget = JTC:demand()
end