-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pull dominantColor
s per https://github.com/randytarampi/lwip/pull/28
#30
Changes from all commits
bc8b6c8
dace4e9
9900ac9
f026d87
4672dd2
57ca166
61a2f87
6c513d8
135ecbc
e8cb568
d99d82d
02df8f6
7cd33d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,8 @@ const judges = { | |
toBuffer: decree(defs.args.toBuffer), | ||
writeFile: decree(defs.args.writeFile), | ||
setPixel: decree(defs.args.setPixel), | ||
getPixel: decree(defs.args.getPixel) | ||
getPixel: decree(defs.args.getPixel), | ||
dominantColor: decree(defs.args.dominantColor) | ||
}; | ||
|
||
module.exports = class Image { | ||
|
@@ -82,6 +83,47 @@ module.exports = class Image { | |
}; | ||
} | ||
|
||
dominantColor () { | ||
let dominantColor; | ||
judges.dominantColor( | ||
arguments, | ||
skips => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6'). |
||
if (typeof skips !== 'number' || skips < 0 || parseInt(skips,10) !== skips) { | ||
throw Error('Pass a positive integer argument for number of pixels to skip over each iteration'); | ||
} | ||
|
||
const colorCounter = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
for (let i = 0; i < this.width(); i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
for (let j = 0; j < this.height(); j+= skips+1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
const pixel = this.__lwip.getPixel(i,j), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
pixelColor = pixel[0].toString()+','+pixel[1].toString()+','+pixel[2].toString()+','+pixel[3].toString(), | ||
occurence = colorCounter[pixelColor]; | ||
if (occurence === undefined) colorCounter[pixelColor] = 1; | ||
else colorCounter[pixelColor]++; | ||
} | ||
} | ||
|
||
let the_key = '0,0,0,0', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
count = 0; | ||
for (let key in colorCounter) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
if (colorCounter[key] > count) { | ||
the_key = key; | ||
count = colorCounter[key]; | ||
} | ||
} | ||
the_key = the_key.split(','); | ||
|
||
dominantColor = { | ||
r: parseInt(the_key[0],10), | ||
g: parseInt(the_key[1],10), | ||
b: parseInt(the_key[2],10), | ||
a: parseInt(the_key[3],10) | ||
}; | ||
} | ||
); | ||
return dominantColor; | ||
} | ||
|
||
getPixel () { | ||
const args = judges.getPixel(arguments), | ||
left = args[0], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).