Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
psd.js
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
regiostart
psd.js
Commits
565c4a6e
Commit
565c4a6e
authored
Apr 15, 2014
by
Ryan LeFevre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement layer blend modes and info
parent
691412d9
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
146 additions
and
2395 deletions
+146
-2395
psd.js
dist/psd.js
+0
-2383
parse.js
examples/parse.js
+4
-3
psd.coffee
lib/psd.coffee
+3
-0
blend_mode.coffee
lib/psd/blend_mode.coffee
+61
-0
file.coffee
lib/psd/file.coffee
+1
-7
layer.coffee
lib/psd/layer.coffee
+38
-0
blend_modes.coffee
lib/psd/layer/blend_modes.coffee
+16
-0
position_channels.coffee
lib/psd/layer/position_channels.coffee
+16
-0
layer_mask.coffee
lib/psd/layer_mask.coffee
+7
-2
No files found.
dist/psd.js
View file @
565c4a6e
This diff is collapsed.
Click to expand it.
examples/parse.js
View file @
565c4a6e
...
...
@@ -4,6 +4,7 @@ psd = PSD.fromFile('./examples/images/example.psd');
psd
.
parse
();
console
.
log
(
psd
.
header
.
export
());
psd
.
image
.
saveAsPng
(
'./output.png'
).
then
(
function
()
{
console
.
log
(
"Finished!"
);
});
\ No newline at end of file
// psd.image.saveAsPng('./output.png').then(function () {
// console.log("Finished!");
// });
console
.
log
(
psd
.
layers
.
map
(
function
(
l
)
{
return
l
.
export
();
}));
\ No newline at end of file
lib/psd.coffee
View file @
565c4a6e
...
...
@@ -16,6 +16,9 @@ module.exports = class PSD
@
parsed
=
false
@
header
=
null
Object
.
defineProperty
@
,
'layers'
,
get
:
->
@
layerMask
.
layers
parse
:
->
return
if
@
parsed
...
...
lib/psd/blend_mode.coffee
0 → 100644
View file @
565c4a6e
{
Module
}
=
require
'coffeescript-module'
module
.
exports
=
class
BlendMode
extends
Module
@
aliasProperty
'blendingMode'
,
'mode'
# All of the blend modes are stored in the PSD file with a specific key.
# This is the mapping of that key to its readable name.
BLEND_MODES
=
{
norm
:
'normal'
,
dark
:
'darken'
,
lite
:
'lighten'
,
hue
:
'hue'
,
sat
:
'saturation'
,
colr
:
'color'
,
lum
:
'luminosity'
,
mul
:
'multiply'
,
scrn
:
'screen'
,
diss
:
'dissolve'
,
over
:
'overlay'
,
hLit
:
'hard_light'
,
sLit
:
'soft_light'
,
diff
:
'difference'
,
smud
:
'exclusion'
,
div
:
'color_dodge'
,
idiv
:
'color_burn'
,
lbrn
:
'linear_burn'
,
lddg
:
'linear_dodge'
,
vLit
:
'vivid_light'
,
lLit
:
'linear_light'
,
pLit
:
'pin_light'
,
hMix
:
'hard_mix'
,
pass
:
'passthru'
,
dkCl
:
'darker_color'
,
lgCl
:
'lighter_color'
,
fsub
:
'subtract'
,
fdiv
:
'divide'
}
constructor
:
(
@
file
)
->
@
blendKey
=
null
@
opacity
=
null
@
clipping
=
null
@
flags
=
null
@
mode
=
null
parse
:
->
@
file
.
seek
4
,
true
@
blendKey
=
@
file
.
readString
(
4
).
trim
()
@
opacity
=
@
file
.
readByte
()
@
clipping
=
@
file
.
readByte
()
@
flags
=
@
file
.
readByte
()
@
mode
=
BLEND_MODES
[
@
blendKey
]
@
clipped
=
@
clipping
is
1
@
visible
=
!
((
@
flags
&
(
0x01
<<
1
))
>
0
)
@
file
.
seek
1
,
true
opacityPercentage
:
->
@
opacity
*
100
/
255
lib/psd/file.coffee
View file @
565c4a6e
...
...
@@ -38,10 +38,4 @@ module.exports = class File
seek
:
(
amt
,
rel
=
false
)
->
if
rel
then
@
pos
+=
amt
else
@
pos
=
amt
readString
:
(
length
)
->
@
read
(
length
).
toString
()
# readUInt: ->
# @data.readUInt32(@pos)
# @pos += 4
# readInt: ->
# @data.readInt32(@pos)
# @pos += 4
\ No newline at end of file
readByte
:
->
@
read
(
1
)[
0
]
\ No newline at end of file
lib/psd/layer.coffee
0 → 100644
View file @
565c4a6e
{
Module
}
=
require
'coffeescript-module'
module
.
exports
=
class
Layer
extends
Module
@
includes
require
(
'./layer/position_channels.coffee'
)
@
includes
require
(
'./layer/blend_modes.coffee'
)
# @includes require('./layer/blending_ranges.coffee')
# @includes require('./layer/channel_image.coffee')
constructor
:
(
@
file
,
@
header
)
->
@
mask
=
{}
@
blendingRanges
=
{}
@
adjustments
=
{}
@
channelsInfo
=
[]
@
blendMode
=
{}
@
groupLayer
=
null
@
infoKeys
=
[]
parse
:
->
@
parsePositionAndChannels
()
@
parseBlendModes
()
extraLen
=
@
file
.
readInt
()
@
layerEnd
=
@
file
.
tell
()
+
extraLen
@
file
.
seek
@
layerEnd
return
@
export
:
->
top
:
@
top
right
:
@
right
bottom
:
@
bottom
left
:
@
left
width
:
@
width
height
:
@
height
opacity
:
@
opacity
visible
:
@
visible
clipped
:
@
clipped
\ No newline at end of file
lib/psd/layer/blend_modes.coffee
0 → 100644
View file @
565c4a6e
BlendMode
=
require
'../blend_mode.coffee'
module
.
exports
=
parseBlendModes
:
->
@
blendMode
=
new
BlendMode
(
@
file
)
@
blendMode
.
parse
()
@
opacity
=
@
blendMode
.
opacity
@
visible
=
@
blendMode
.
visible
@
clipped
=
@
blendMode
.
clipped
hidden
:
->
not
@
visible
# TODO: check section divider
blendingMode
:
->
@
blendMode
.
mode
\ No newline at end of file
lib/psd/layer/position_channels.coffee
0 → 100644
View file @
565c4a6e
module
.
exports
=
parsePositionAndChannels
:
->
@
top
=
@
file
.
readInt
()
@
left
=
@
file
.
readInt
()
@
bottom
=
@
file
.
readInt
()
@
right
=
@
file
.
readInt
()
@
channels
=
@
file
.
readShort
()
@
rows
=
@
height
=
@
bottom
-
@
top
@
cols
=
@
width
=
@
right
-
@
left
for
i
in
[
0
...
@
channels
]
id
=
@
file
.
readShort
()
length
=
@
file
.
readInt
()
@
channelsInfo
.
push
id
:
id
,
length
:
length
lib/psd/layer_mask.coffee
View file @
565c4a6e
Util
=
require
(
'./util.coffee'
)
Layer
=
require
(
'./layer.coffee'
)
module
.
exports
=
class
LayerMask
constructor
:
(
@
file
,
@
header
)
->
...
...
@@ -11,8 +12,6 @@ module.exports = class LayerMask
parse
:
->
maskSize
=
@
file
.
readInt
()
finish
=
maskSize
+
@
file
.
tell
()
@
file
.
seek
finish
return
return
if
maskSize
<=
0
...
...
@@ -25,3 +24,9 @@ module.exports = class LayerMask
layerCount
=
Math
.
abs
layerCount
@
mergedAlpha
=
true
for
i
in
[
0
...
layerCount
]
@
layers
.
push
new
Layer
(
@
file
,
@
header
).
parse
()
@
layers
.
reverse
()
@
file
.
seek
finish
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment