Comparing version 0.0.2 to 1.0.0
46
index.js
@@ -5,3 +5,3 @@ 'use strict'; | ||
var versionMap = { | ||
const versionMap = { | ||
0x02000000: '2.0', | ||
@@ -14,3 +14,3 @@ 0x02100000: '2.1', | ||
var intentMap = { | ||
const intentMap = { | ||
0: 'Perceptual', | ||
@@ -22,3 +22,3 @@ 1: 'Relative', | ||
var valueMap = { | ||
const valueMap = { | ||
// Device | ||
@@ -37,7 +37,7 @@ 'scnr': 'Scanner', | ||
'sunw': 'Sun Microsystems', | ||
'sgi' : 'Silicon Graphics', | ||
'sgi': 'Silicon Graphics', | ||
'tgnt': 'Taligent' | ||
}; | ||
var tagMap = { | ||
const tagMap = { | ||
'desc': 'description', | ||
@@ -49,14 +49,12 @@ 'cprt': 'copyright', | ||
var getContentAtOffsetAsString = function(buffer, offset) { | ||
var value = buffer.slice(offset, offset + 4).toString().trim(); | ||
const getContentAtOffsetAsString = (buffer, offset) => { | ||
const value = buffer.slice(offset, offset + 4).toString().trim(); | ||
return (value.toLowerCase() in valueMap) ? valueMap[value.toLowerCase()] : value; | ||
}; | ||
var hasContentAtOffset = function(buffer, offset) { | ||
return (buffer.readUInt32BE(offset) !== 0); | ||
}; | ||
const hasContentAtOffset = (buffer, offset) => buffer.readUInt32BE(offset) !== 0; | ||
module.exports.parse = function(buffer) { | ||
module.exports.parse = (buffer) => { | ||
// Verify expected length | ||
var size = buffer.readUInt32BE(0); | ||
const size = buffer.readUInt32BE(0); | ||
if (size !== buffer.length) { | ||
@@ -66,3 +64,3 @@ throw new Error('Invalid ICC profile: length mismatch'); | ||
// Verify 'acsp' signature | ||
var signature = buffer.slice(36, 40).toString(); | ||
const signature = buffer.slice(36, 40).toString(); | ||
if (signature !== 'acsp') { | ||
@@ -72,3 +70,3 @@ throw new Error('Invalid ICC profile: missing signature'); | ||
// Integer attributes | ||
var profile = { | ||
const profile = { | ||
version: versionMap[buffer.readUInt32BE(8)], | ||
@@ -79,3 +77,3 @@ intent: intentMap[buffer.readUInt32BE(64)] | ||
[ | ||
[ 4, 'cmm'], | ||
[4, 'cmm'], | ||
[12, 'deviceClass'], | ||
@@ -88,3 +86,3 @@ [16, 'colorSpace'], | ||
[80, 'creator'] | ||
].forEach(function(attr) { | ||
].forEach(attr => { | ||
if (hasContentAtOffset(buffer, attr[0])) { | ||
@@ -95,16 +93,16 @@ profile[attr[1]] = getContentAtOffsetAsString(buffer, attr[0]); | ||
// Tags | ||
var tagCount = buffer.readUInt32BE(128); | ||
var tagHeaderOffset = 132; | ||
for (var i = 0; i < tagCount; i++) { | ||
var tagSignature = getContentAtOffsetAsString(buffer, tagHeaderOffset); | ||
const tagCount = buffer.readUInt32BE(128); | ||
let tagHeaderOffset = 132; | ||
for (let i = 0; i < tagCount; i++) { | ||
const tagSignature = getContentAtOffsetAsString(buffer, tagHeaderOffset); | ||
if (tagSignature in tagMap) { | ||
var tagOffset = buffer.readUInt32BE(tagHeaderOffset + 4); | ||
var tagSize = buffer.readUInt32BE(tagHeaderOffset + 8); | ||
const tagOffset = buffer.readUInt32BE(tagHeaderOffset + 4); | ||
const tagSize = buffer.readUInt32BE(tagHeaderOffset + 8); | ||
if (tagOffset > buffer.length) { | ||
throw new Error('Invalid ICC profile: Tag offset out of bounds'); | ||
} | ||
var tagType = getContentAtOffsetAsString(buffer, tagOffset); | ||
const tagType = getContentAtOffsetAsString(buffer, tagOffset); | ||
// desc | ||
if (tagType === 'desc') { | ||
var tagValueSize = buffer.readUInt32BE(tagOffset + 8); | ||
const tagValueSize = buffer.readUInt32BE(tagOffset + 8); | ||
if (tagValueSize > tagSize) { | ||
@@ -111,0 +109,0 @@ throw new Error('Invalid ICC profile: Description tag value size out of bounds for ' + tagSignature); |
{ | ||
"name": "icc", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"author": "Lovell Fuller <npm@lovell.info>", | ||
"description": "Parse International Color Consortium (ICC) profiles", | ||
"scripts": { | ||
"test": "node ./node_modules/mocha/bin/mocha ./test/*.js" | ||
"test": "semistandard && mocha" | ||
}, | ||
@@ -12,3 +12,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git://github.com/dimensio/icc" | ||
"url": "git://github.com/lovell/icc" | ||
}, | ||
@@ -22,9 +22,14 @@ "keywords": [ | ||
"devDependencies": { | ||
"mocha": "^2.2.5", | ||
"mocha-jshint": "^2.2.3" | ||
"mocha": "^3.2.0", | ||
"semistandard": "^9.2.1" | ||
}, | ||
"license": "Apache-2.0", | ||
"engines": { | ||
"node": ">=0.10" | ||
"node": ">=4" | ||
}, | ||
"semistandard": { | ||
"env": [ | ||
"mocha" | ||
] | ||
} | ||
} |
# icc | ||
Node.js module to parse International Color Consortium (ICC) profiles. | ||
JavaScript module to parse International Color Consortium (ICC) profiles. | ||
@@ -12,5 +12,5 @@ ## Installation | ||
```javascript | ||
var icc = require('icc'); | ||
var profileData = fs.readFileSync('sRGB_IEC61966-2-1_black_scaled.icc'); | ||
var profile = icc.parse(profileData); | ||
import { parse } from 'icc'; | ||
const profileData = fs.readFileSync('sRGB_IEC61966-2-1_black_scaled.icc'); | ||
const profile = parse(profileData); | ||
console.dir(profile); | ||
@@ -39,3 +39,3 @@ ``` | ||
Copyright 2015 Lovell Fuller | ||
Copyright 2015, 2017 Lovell Fuller | ||
@@ -42,0 +42,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
16574
0
103