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
dcdec792
Commit
dcdec792
authored
Mar 29, 2015
by
Ryan LeFevre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CMYK image exporting
parent
a2cae2d8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
7 deletions
+62
-7
example-cmyk.psd
examples/images/example-cmyk.psd
+0
-0
color.coffee
lib/psd/color.coffee
+16
-0
image.coffee
lib/psd/image.coffee
+3
-1
image_mode.coffee
lib/psd/image_mode.coffee
+2
-1
cmyk.coffee
lib/psd/image_modes/cmyk.coffee
+33
-0
util.coffee
lib/psd/util.coffee
+8
-5
No files found.
examples/images/example-cmyk.psd
0 → 100644
View file @
dcdec792
File added
lib/psd/color.coffee
0 → 100644
View file @
dcdec792
Util
=
require
'./util.coffee'
module
.
exports
=
cmykToRgb
:
(
c
,
m
,
y
,
k
)
->
r
=
Util
.
clamp
(
65535
-
(
c
*
(
255
-
k
)
+
(
k
<<
8
)))
>>
8
,
0
,
255
g
=
Util
.
clamp
(
65535
-
(
m
*
(
255
-
k
)
+
(
k
<<
8
)))
>>
8
,
0
,
255
b
=
Util
.
clamp
(
65535
-
(
y
*
(
255
-
k
)
+
(
k
<<
8
)))
>>
8
,
0
,
255
[
r
,
g
,
b
]
# def cmyk_to_rgb(c, m, y, k)
# Hash[{
# r: (65535 - (c * (255 - k) + (k << 8))) >> 8,
# g: (65535 - (m * (255 - k) + (k << 8))) >> 8,
# b: (65535 - (y * (255 - k) + (k << 8))) >> 8
# }.map { |k, v| [k, Util.clamp(v, 0, 255)] }]
# end
lib/psd/image.coffee
View file @
dcdec792
...
@@ -7,8 +7,9 @@ Export = require './image_export.coffee'
...
@@ -7,8 +7,9 @@ Export = require './image_export.coffee'
module
.
exports
=
class
Image
extends
Module
module
.
exports
=
class
Image
extends
Module
@
includes
ImageFormat
.
RAW
@
includes
ImageFormat
.
RAW
@
includes
ImageFormat
.
RLE
@
includes
ImageFormat
.
RLE
@
includes
ImageMode
.
RGB
@
includes
ImageMode
.
Greyscale
@
includes
ImageMode
.
Greyscale
@
includes
ImageMode
.
RGB
@
includes
ImageMode
.
CMYK
@
includes
Export
.
PNG
@
includes
Export
.
PNG
COMPRESSIONS
=
[
COMPRESSIONS
=
[
...
@@ -41,6 +42,7 @@ module.exports = class Image extends Module
...
@@ -41,6 +42,7 @@ module.exports = class Image extends Module
switch
@
mode
()
switch
@
mode
()
when
1
then
@
setGreyscaleChannels
()
when
1
then
@
setGreyscaleChannels
()
when
3
then
@
setRgbChannels
()
when
3
then
@
setRgbChannels
()
when
4
then
@
setCmykChannels
()
calculateLength
:
->
calculateLength
:
->
@
length
=
switch
@
depth
()
@
length
=
switch
@
depth
()
...
...
lib/psd/image_mode.coffee
View file @
dcdec792
module
.
exports
=
module
.
exports
=
RGB
:
require
(
'./image_modes/rgb.coffee'
)
Greyscale
:
require
(
'./image_modes/greyscale.coffee'
)
Greyscale
:
require
(
'./image_modes/greyscale.coffee'
)
RGB
:
require
(
'./image_modes/rgb.coffee'
)
CMYK
:
require
(
'./image_modes/cmyk.coffee'
)
lib/psd/image_modes/cmyk.coffee
0 → 100644
View file @
dcdec792
Color
=
require
'../color.coffee'
module
.
exports
=
setCmykChannels
:
->
@
channelsInfo
=
[
{
id
:
0
},
{
id
:
1
},
{
id
:
2
},
{
id
:
3
}
]
@
channelsInfo
.
push
{
id
:
-
1
}
if
@
channels
()
is
5
combineCmykChannel
:
->
cmykChannels
=
@
channelsInfo
.
map
(
ch
)
->
ch
.
id
.
filter
(
ch
)
->
ch
>=
-
1
for
i
in
[
0
...
@
numPixels
]
c
=
m
=
y
=
k
=
0
a
=
255
for
chan
,
index
in
cmykChannels
val
=
@
channelData
[
i
+
(
@
channelLength
*
index
)]
switch
chan
when
-
1
then
a
=
val
when
0
then
c
=
val
when
1
then
m
=
val
when
2
then
y
=
val
when
3
then
k
=
val
[
r
,
g
,
b
]
=
Color
.
cmykToRgb
(
255
-
c
,
255
-
m
,
255
-
y
,
255
-
k
)
@
pixelData
.
push
r
,
g
,
b
,
a
lib/psd/util.coffee
View file @
dcdec792
module
.
exports
=
class
Util
module
.
exports
=
@
pad2
:
(
i
)
->
(
i
+
1
)
&
~
0x01
pad2
:
(
i
)
->
(
i
+
1
)
&
~
0x01
@
pad4
:
(
i
)
->
((
i
+
4
)
&
~
0x03
)
-
1
pad4
:
(
i
)
->
((
i
+
4
)
&
~
0x03
)
-
1
@
getUnicodeCharacter
:
(
cp
)
->
getUnicodeCharacter
:
(
cp
)
->
if
cp
>=
0
and
cp
<=
0xD7FF
or
cp
>=
0xE000
and
cp
<=
0xFFFF
if
cp
>=
0
and
cp
<=
0xD7FF
or
cp
>=
0xE000
and
cp
<=
0xFFFF
return
String
.
fromCharCode
(
cp
)
return
String
.
fromCharCode
(
cp
)
else
if
cp
>=
0x10000
and
cp
<=
0x10FFFF
else
if
cp
>=
0x10000
and
cp
<=
0x10FFFF
...
@@ -17,4 +17,7 @@ module.exports = class Util
...
@@ -17,4 +17,7 @@ module.exports = class Util
# to give the second byte
# to give the second byte
second
=
(
0x3ff
&
cp
)
+
0xDC00
second
=
(
0x3ff
&
cp
)
+
0xDC00
String
.
fromCharCode
(
first
)
+
String
.
fromCharCode
(
second
)
String
.
fromCharCode
(
first
)
+
String
.
fromCharCode
(
second
)
\ No newline at end of file
clamp
:
(
num
,
min
,
max
)
->
Math
.
min
(
Math
.
max
(
num
,
min
),
max
)
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