Skip to content

Commit

Permalink
Add greyscale image exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
meltingice committed Mar 29, 2015
1 parent 111ea5a commit a2cae2d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.DS_Store
node_modules
index.html
output.png
Binary file added examples/images/example-greyscale.psd
Binary file not shown.
2 changes: 2 additions & 0 deletions lib/psd/image.coffee
Expand Up @@ -8,6 +8,7 @@ module.exports = class Image extends Module
@includes ImageFormat.RAW
@includes ImageFormat.RLE
@includes ImageMode.RGB
@includes ImageMode.Greyscale
@includes Export.PNG

COMPRESSIONS = [
Expand Down Expand Up @@ -38,6 +39,7 @@ module.exports = class Image extends Module

setChannelsInfo: ->
switch @mode()
when 1 then @setGreyscaleChannels()
when 3 then @setRgbChannels()

calculateLength: ->
Expand Down
3 changes: 2 additions & 1 deletion lib/psd/image_mode.coffee
@@ -1,2 +1,3 @@
module.exports =
RGB: require('./image_modes/rgb.coffee')
RGB: require('./image_modes/rgb.coffee')
Greyscale: require('./image_modes/greyscale.coffee')
14 changes: 14 additions & 0 deletions lib/psd/image_modes/greyscale.coffee
@@ -0,0 +1,14 @@
module.exports =
setGreyscaleChannels: ->
@channelsInfo = [{id: 0}]
@channelsInfo.push {id: -1} if @channels() is 2

combineGreyscaleChannel: ->
for i in [0...@numPixels]
grey = @channelData[i]
alpha = if @channels() is 2
@channelData[@channelLength + i]
else
255

@pixelData.push grey, grey, grey, alpha

0 comments on commit a2cae2d

Please sign in to comment.