Commit dcdec792 authored by Ryan LeFevre's avatar Ryan LeFevre

Add CMYK image exporting

parent a2cae2d8
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
......@@ -7,8 +7,9 @@ Export = require './image_export.coffee'
module.exports = class Image extends Module
@includes ImageFormat.RAW
@includes ImageFormat.RLE
@includes ImageMode.RGB
@includes ImageMode.Greyscale
@includes ImageMode.RGB
@includes ImageMode.CMYK
@includes Export.PNG
COMPRESSIONS = [
......@@ -41,6 +42,7 @@ module.exports = class Image extends Module
switch @mode()
when 1 then @setGreyscaleChannels()
when 3 then @setRgbChannels()
when 4 then @setCmykChannels()
calculateLength: ->
@length = switch @depth()
......
module.exports =
RGB: require('./image_modes/rgb.coffee')
Greyscale: require('./image_modes/greyscale.coffee')
RGB: require('./image_modes/rgb.coffee')
CMYK: require('./image_modes/cmyk.coffee')
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
module.exports = class Util
@pad2: (i) -> (i + 1) & ~0x01
@pad4: (i) -> ((i + 4) & ~0x03) - 1
@getUnicodeCharacter: (cp) ->
module.exports =
pad2: (i) -> (i + 1) & ~0x01
pad4: (i) -> ((i + 4) & ~0x03) - 1
getUnicodeCharacter: (cp) ->
if cp >= 0 and cp <= 0xD7FF or cp >= 0xE000 and cp <= 0xFFFF
return String.fromCharCode(cp)
else if cp >= 0x10000 and cp <= 0x10FFFF
......@@ -18,3 +18,6 @@ module.exports = class Util
second = (0x3ff & cp) + 0xDC00
String.fromCharCode(first) + String.fromCharCode(second)
clamp: (num, min, max) ->
Math.min(Math.max(num, min), max)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment