-
Notifications
You must be signed in to change notification settings - Fork 3
Home
unXedDani edited this page Mar 6, 2016
·
17 revisions
Purpose is to expose the structure of .PSD files into LÖVE.
- ImageData for the layers.
- Names.
- Blendmodes.
- Clipping mode.
- Structure, folder / image.
-
artal = require("artal")
Load Library -
psdTable = artal.newPSD(FileNameOrFileData)
full structure with the layers loaded in as images. -
psdTable = artal.newPSD(FileNameOrFileData, "info")
full structure. -
ImageDataOrNil = artal.newPSD(FileNameOrFileData, layerNumber)
ImageData, ImageData for the specified layer number, nil if the layer is empty / folder. -
ImageData = artal.newPSD(FileNameOrFileData, "composed")
ImageData of the composed image as it's stored in the psd file itself. (Note that Photoshop has an slightly erroneous implementation composing the alpha into the composed image. So images without a fully opaque background will be slightly blended with white.)
local artal = require("artal")
local simpleSample = artal.newPSD("SomeFile.psd")
function love.draw()
for i = 1, #simpleSample do
if simpleSample[i].type == "image" then
love.graphics.draw(
simpleSample[i].image,
nil, -- Position X
nil, -- Position Y
nil, -- Rotation
nil, -- Scale X
nil, -- Scale Y
simpleSample[i].ox, -- Offset X
simpleSample[i].oy) -- Offset Y
end
end
end
This structure is generated from writetable.lua. And you can use that to visualize your own tables.
{
-- Table with 5 indexes, and 2 string keys.
-- Array values are all of type: "table".
height = 600,
width = 600,
[1] =
{
-- Table with 7 string keys.
oy = 0,
ox = 0,
image = "Image: 0x7f9ca8c9a4f0",
type = "image",
blend = "norm",
name = "Layer5",
clip = "false",
},
[2] =
{
-- Table with 7 string keys.
oy = -126,
ox = 0,
image = "Image: 0x7f9ca8c9b9c0",
type = "image",
blend = "norm",
name = "Layer2",
clip = "false",
},
[3] =
{
-- Table with 7 string keys.
oy = -41,
ox = -28,
image = "Image: 0x7f9ca8d312d0",
type = "image",
blend = "norm",
name = "Layer1",
clip = "false",
},
[4] =
{
-- Table with 7 string keys.
oy = 0,
ox = 0,
image = "Image: 0x7f9caa9514d0",
type = "image",
blend = "norm",
name = "Layer3",
clip = "false",
},
[5] =
{
-- Table with 7 string keys.
oy = -42,
ox = -112,
image = "Image: 0x7f9caa952200",
type = "image",
blend = "norm",
name = "Layer4",
clip = "false",
},
}
Some helper functions for easily loading / sorting the tables.
artalHelper = require("artalhelper")
-
artalHelper.load(FileNameOrFileData,psdTable)
Load in images on layers that are image layer. psdTable = artalHelper.sortSimple(psdTable)
psdTable = artalHelper.sortRecursive(psdTable)
Flattening: Clipping layers: Blendmodes implemented: Alpha, Multiply, Screen and Overlay.
Small library to generate shaders for blending and clipping layers.
psdShader = require("psdshader")
shaderString = psdShader.createShaderString(globalBlendmode, blendmodeBeingClipped, ...)
psdShader.setShader(shader)
-
psdShader.drawClip(drawOrderIndex,image,x,y,r,sx,sy,ox,oy,kx,ky)
(Rotation and shearing not implemented.) -
resultCanvas = psdShader.flatten(psdTableClipTo, psdTableBeingClipped, ...)
ox and oy will remain the same as the psdTableClipTo image.
psdShader = require("psdshader")
shaderString = psdShader.createShaderString("over") -- Overlay blendmode
--love.filesystem.write("ShaderInspect.glsl",shaderString) -- inspect the generated shader
blendShader = love.graphics.newShader(shaderString) -- Load the shader
someImage = love.graphics.newImage("someimagefile.png")
function love.draw()
psdShader.setShader(blendShader)
love.graphics.draw(someImage)
love.graphics.setShader()
end
Create a string from tables. So you can inspect tables created by artal.newPSD(). Or anything else for that matter.
tableAsString = writetable.createStringFromTable(table)