147 |
148 | );
149 | },
150 | _handleChange(event, selectedIndex, value) {
151 | this.setState({
152 | selectedOperation: value,
153 | selectedOperationDisplayName: this.state.operations[value].displayName,
154 | });
155 | },
156 | _handleApply() {
157 | if (this.state.proceedImage) {
158 | mangekyouAction.addHistory({
159 | operation: this.state.proceedOperation,
160 | operationDisplayName: this.state.proceedOperationDisplayName,
161 | image: this.state.proceedImage,
162 | });
163 | }
164 | },
165 | _onHistoryChange() {
166 | this.setState({
167 | currentRecord: mangekyouStore.getLastHistory(),
168 | });
169 | },
170 | _onShowingChange() {
171 | this.setState({
172 | showing: mangekyouStore.getShowing().toolPanel,
173 | });
174 | },
175 | _onProcessingChange() {
176 | this.setState({
177 | processingState: mangekyouStore.getProcessingState(),
178 | });
179 | },
180 | _WillProcess({operationName, operationParam}) {
181 | if (this.state.worker) {
182 | this.state.worker.terminate();
183 | }
184 | const currentRecord = mangekyouStore.getLastHistory();
185 | if (currentRecord) {
186 | // if there's an image, process it.
187 | const {width, height} = currentRecord.image;
188 | const imgData = currentRecord.image
189 | .getContext('2d')
190 | .getImageData(0, 0, width, height);
191 | const aworker = new Worker('script/worker.js');
192 | this.setState({
193 | worker: aworker,
194 | proceedOperation: this.state.selectedOperation,
195 | proceedOperationDisplayName: this.state.selectedOperationDisplayName,
196 | });
197 | aworker.onmessage = this._DidProcess;
198 | aworker.postMessage({
199 | operationName,
200 | operationParam,
201 | image: {
202 | width: imgData.width,
203 | height: imgData.height,
204 | data: imgData.data,
205 | },
206 | });
207 | mangekyouAction.setProcessingState(mangekyouConstant.COMPUTING);
208 | }
209 | },
210 | _DidProcess({data}) {
211 | if (data.proceed) {
212 | const imgd = new ImageData(new Uint8ClampedArray(data.image.buffer), data.image.width, data.image.height);
213 | const canvas = document.createElement('canvas');
214 | const ctx = canvas.getContext('2d');
215 | canvas.setAttribute('width', data.image.width);
216 | canvas.setAttribute('height', data.image.height);
217 | ctx.putImageData(imgd, 0, 0);
218 | mangekyouAction.updatePreviewImage(canvas);
219 | this.state.worker.terminate();
220 | this.setState({
221 | worker: null,
222 | processing: false,
223 | proceedImage: canvas,
224 | });
225 | }
226 | mangekyouAction.setProcessingState(mangekyouConstant.IDLE);
227 | },
228 | });
229 |
230 | export default ToolPanel;
231 |
--------------------------------------------------------------------------------
/src/app/script/component/TitleBar.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import AppBar from 'material-ui/lib/app-bar';
3 | import IconMenu from 'material-ui/lib/menus/icon-menu';
4 | import MenuItem from 'material-ui/lib/menus/menu-item';
5 | import Divider from 'material-ui/lib/divider';
6 | import IconButton from 'material-ui/lib/icon-button';
7 | import MoreVertIcon from 'material-ui/lib/svg-icons/navigation/more-vert';
8 | import ImageAddToPhotosIcon from 'material-ui/lib/svg-icons/image/add-to-photos';
9 | import ContentSaveIcon from 'material-ui/lib/svg-icons/content/save';
10 | import ActionHistoryIcon from 'material-ui/lib/svg-icons/action/history';
11 | import ImageStyleIcon from 'material-ui/lib/svg-icons/image/style';
12 | import ImageFilterVintageIcon from 'material-ui/lib/svg-icons/image/filter-vintage';
13 | import SocialCakeIcon from 'material-ui/lib/svg-icons/social/cake';
14 | import AVEqualizerIcon from 'material-ui/lib/svg-icons/av/equalizer';
15 | import KeyboardShortcut from './KeyboardShortcut';
16 | import mangekyouAction from '../action/mangekyouAction';
17 | import mangekyouStore from '../store/mangekyouStore';
18 | import mangekyouConstant from '../constant/mangekyouConstant';
19 | import {version as mangekyouVersion} from '../../../../package.json';
20 |
21 | const TitleBar = React.createClass({
22 | getInitialState() {
23 | return {
24 | showing: mangekyouStore.getShowing(),
25 | currentImage: null,
26 | processingState: mangekyouStore.getProcessingState(),
27 | animating: false,
28 | intervalId: Infinity,
29 | keyMap: [
30 | {
31 | char: 'o',
32 | action: () => { this._handleAddImageClick(); },
33 | },
34 | {
35 | char: 'e',
36 | action: () => { this._handleExportImageClick(); },
37 | },
38 | ],
39 | };
40 | },
41 | componentDidMount() {
42 | mangekyouStore.addShowingChangeListener(this._onShowingChange);
43 | mangekyouStore.addHistoryChangeListener(this._onHistoryChange);
44 | mangekyouStore.addProcessingChangeListener(this._onProcessingChange);
45 | },
46 | componentWillUnmount() {
47 | mangekyouStore.removeShowingChangeListener(this._onShowingChange);
48 | mangekyouStore.removeHistoryChangeListener(this._onHistoryChange);
49 | mangekyouStore.removeProcessingChangeListener(this._onProcessingChange);
50 | },
51 | render() {
52 | return ( // eslint-disable-line no-extra-parens
53 |
63 |
72 |
73 |
80 | }
81 | iconElementRight={
82 | }
86 | >
87 |
129 | }/>
130 | );
131 | },
132 | _handleFile() {
133 | mangekyouAction.setProcessingState(mangekyouConstant.LOADING_FILE);
134 | let fileCount = this.refs.fileInput.files.length;
135 | function extractAndAddFile(f) {
136 | const canvas = document.createElement('canvas');
137 | const ctx = canvas.getContext('2d');
138 | const img = new Image();
139 | const fr = new FileReader();
140 | img.onload = () => {
141 | canvas.setAttribute('width', img.width);
142 | canvas.setAttribute('height', img.height);
143 | ctx.drawImage(img, 0, 0);
144 | mangekyouAction.newImage(canvas);
145 | -- fileCount;
146 | if (fileCount < 1) {
147 | // loading files complete
148 | mangekyouAction.setProcessingState(mangekyouConstant.IDLE);
149 |
150 | // trigger a computing on current image
151 | mangekyouAction.triggerCompute();
152 | }
153 | };
154 | fr.onload = () => { img.src = fr.result; };
155 | fr.readAsDataURL(f);
156 | }
157 | for (const eachFile of new Array(...this.refs.fileInput.files)) {
158 | extractAndAddFile(eachFile);
159 | }
160 | },
161 | _handleAddImageClick() {
162 | this.refs.fileInput.click();
163 | },
164 | _handleExportImageClick() {
165 | if (this.state.currentImage) {
166 | const a = document.createElement('a');
167 | a.setAttribute('download', 'proceed.png');
168 | a.setAttribute('href', this.state.currentImage.toDataURL());
169 | a.setAttribute('style', 'position: fixed; width: 0; height: 0;');
170 |
171 | const link = document.body.appendChild(a);
172 | link.click();
173 | document.body.removeChild(link);
174 | }
175 | },
176 | _handleTriggerHistoryPanel() { mangekyouAction.triggerShowing('historyPanel'); },
177 | _handleTriggerToolPanel() { mangekyouAction.triggerShowing('toolPanel'); },
178 | _handleTriggerStatusPanel() { mangekyouAction.triggerShowing('statusPanel'); },
179 | _onShowingChange() {
180 | this.setState({
181 | showing: mangekyouStore.getShowing(),
182 | });
183 | },
184 | _onHistoryChange() {
185 | this.setState({
186 | currentImage: mangekyouStore.getLastHistory().image,
187 | });
188 | },
189 | _onProcessingChange() {
190 | const isProcessing = mangekyouStore.getProcessingState() !== mangekyouConstant.IDLE;
191 | const newState = {};
192 | if (isProcessing) {
193 | newState.processing = true;
194 | newState.animating = true;
195 | if (!isFinite(this.state.intervalId)) {
196 | // use setInterval making sure animation stop on end of cycle
197 | newState.intervalId = setInterval(()=>{
198 | if (!this.state.processing) {
199 | clearInterval(this.state.intervalId);
200 | this.setState({
201 | animating: false,
202 | intervalId: Infinity,
203 | });
204 | }
205 | }, 2000);
206 | }
207 | } else {
208 | newState.processing = false;
209 | }
210 | this.setState(newState);
211 | },
212 | });
213 |
214 | export default TitleBar;
215 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "babel-eslint", // https://github.com/babel/babel-eslint
3 | "plugins": [
4 | "react" // https://github.com/yannickcr/eslint-plugin-react
5 | ],
6 | "env": { // http://eslint.org/docs/user-guide/configuring.html#specifying-environments
7 | "browser": true, // browser global variables
8 | "node": true // Node.js global variables and Node.js-specific rules
9 | },
10 | "ecmaFeatures": {
11 | "arrowFunctions": true,
12 | "blockBindings": true,
13 | "classes": true,
14 | "defaultParams": true,
15 | "destructuring": true,
16 | "forOf": true,
17 | "generators": false,
18 | "modules": true,
19 | "objectLiteralComputedProperties": true,
20 | "objectLiteralDuplicateProperties": false,
21 | "objectLiteralShorthandMethods": true,
22 | "objectLiteralShorthandProperties": true,
23 | "spread": true,
24 | "superInFunctions": true,
25 | "templateStrings": true,
26 | "jsx": true
27 | },
28 | "rules": {
29 | /**
30 | * Strict mode
31 | */
32 | // babel inserts "use strict"; for us
33 | "strict": [2, "never"], // http://eslint.org/docs/rules/strict
34 |
35 | /**
36 | * ES6
37 | */
38 | "no-var": 2, // http://eslint.org/docs/rules/no-var
39 | "prefer-const": 2, // http://eslint.org/docs/rules/prefer-const
40 |
41 | /**
42 | * Variables
43 | */
44 | "no-shadow": 2, // http://eslint.org/docs/rules/no-shadow
45 | "no-shadow-restricted-names": 2, // http://eslint.org/docs/rules/no-shadow-restricted-names
46 | "no-unused-vars": [2, { // http://eslint.org/docs/rules/no-unused-vars
47 | "vars": "local",
48 | "args": "after-used"
49 | }],
50 | "no-use-before-define": 2, // http://eslint.org/docs/rules/no-use-before-define
51 |
52 | /**
53 | * Possible errors
54 | */
55 | "comma-dangle": [2, "always-multiline"], // http://eslint.org/docs/rules/comma-dangle
56 | "no-cond-assign": [2, "always"], // http://eslint.org/docs/rules/no-cond-assign
57 | "no-console": 1, // http://eslint.org/docs/rules/no-console
58 | "no-debugger": 1, // http://eslint.org/docs/rules/no-debugger
59 | "no-alert": 1, // http://eslint.org/docs/rules/no-alert
60 | "no-constant-condition": 1, // http://eslint.org/docs/rules/no-constant-condition
61 | "no-dupe-keys": 2, // http://eslint.org/docs/rules/no-dupe-keys
62 | "no-duplicate-case": 2, // http://eslint.org/docs/rules/no-duplicate-case
63 | "no-empty": 2, // http://eslint.org/docs/rules/no-empty
64 | "no-ex-assign": 2, // http://eslint.org/docs/rules/no-ex-assign
65 | "no-extra-boolean-cast": 0, // http://eslint.org/docs/rules/no-extra-boolean-cast
66 | "no-extra-semi": 2, // http://eslint.org/docs/rules/no-extra-semi
67 | "no-func-assign": 2, // http://eslint.org/docs/rules/no-func-assign
68 | "no-inner-declarations": 2, // http://eslint.org/docs/rules/no-inner-declarations
69 | "no-invalid-regexp": 2, // http://eslint.org/docs/rules/no-invalid-regexp
70 | "no-irregular-whitespace": 2, // http://eslint.org/docs/rules/no-irregular-whitespace
71 | "no-obj-calls": 2, // http://eslint.org/docs/rules/no-obj-calls
72 | "quote-props": [2, "as-needed"], // http://eslint.org/docs/rules/quote-props
73 | "no-sparse-arrays": 2, // http://eslint.org/docs/rules/no-sparse-arrays
74 | "no-unreachable": 2, // http://eslint.org/docs/rules/no-unreachable
75 | "use-isnan": 2, // http://eslint.org/docs/rules/use-isnan
76 | "block-scoped-var": 2, // http://eslint.org/docs/rules/block-scoped-var
77 |
78 | /**
79 | * Best practices
80 | */
81 | "consistent-return": 2, // http://eslint.org/docs/rules/consistent-return
82 | "curly": [2, "multi-line"], // http://eslint.org/docs/rules/curly
83 | "default-case": 2, // http://eslint.org/docs/rules/default-case
84 | "dot-notation": [2, { // http://eslint.org/docs/rules/dot-notation
85 | "allowKeywords": true
86 | }],
87 | "eqeqeq": 2, // http://eslint.org/docs/rules/eqeqeq
88 | "guard-for-in": 2, // http://eslint.org/docs/rules/guard-for-in
89 | "no-caller": 2, // http://eslint.org/docs/rules/no-caller
90 | "no-else-return": 2, // http://eslint.org/docs/rules/no-else-return
91 | "no-eq-null": 2, // http://eslint.org/docs/rules/no-eq-null
92 | "no-eval": 2, // http://eslint.org/docs/rules/no-eval
93 | "no-extend-native": 2, // http://eslint.org/docs/rules/no-extend-native
94 | "no-extra-bind": 2, // http://eslint.org/docs/rules/no-extra-bind
95 | "no-fallthrough": 2, // http://eslint.org/docs/rules/no-fallthrough
96 | "no-floating-decimal": 2, // http://eslint.org/docs/rules/no-floating-decimal
97 | "no-implied-eval": 2, // http://eslint.org/docs/rules/no-implied-eval
98 | "no-lone-blocks": 2, // http://eslint.org/docs/rules/no-lone-blocks
99 | "no-loop-func": 2, // http://eslint.org/docs/rules/no-loop-func
100 | "no-multi-str": 2, // http://eslint.org/docs/rules/no-multi-str
101 | "no-native-reassign": 2, // http://eslint.org/docs/rules/no-native-reassign
102 | "no-new": 2, // http://eslint.org/docs/rules/no-new
103 | "no-new-func": 2, // http://eslint.org/docs/rules/no-new-func
104 | "no-new-wrappers": 2, // http://eslint.org/docs/rules/no-new-wrappers
105 | "no-octal": 2, // http://eslint.org/docs/rules/no-octal
106 | "no-octal-escape": 2, // http://eslint.org/docs/rules/no-octal-escape
107 | "no-param-reassign": 2, // http://eslint.org/docs/rules/no-param-reassign
108 | "no-proto": 2, // http://eslint.org/docs/rules/no-proto
109 | "no-redeclare": 2, // http://eslint.org/docs/rules/no-redeclare
110 | "no-return-assign": 2, // http://eslint.org/docs/rules/no-return-assign
111 | "no-script-url": 2, // http://eslint.org/docs/rules/no-script-url
112 | "no-self-compare": 2, // http://eslint.org/docs/rules/no-self-compare
113 | "no-sequences": 2, // http://eslint.org/docs/rules/no-sequences
114 | "no-throw-literal": 2, // http://eslint.org/docs/rules/no-throw-literal
115 | "no-with": 2, // http://eslint.org/docs/rules/no-with
116 | "radix": 2, // http://eslint.org/docs/rules/radix
117 | "vars-on-top": 2, // http://eslint.org/docs/rules/vars-on-top
118 | "wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife
119 | "yoda": 2, // http://eslint.org/docs/rules/yoda
120 |
121 | /**
122 | * Style
123 | */
124 | "indent": [2, 2], // http://eslint.org/docs/rules/indent
125 | "brace-style": [2, // http://eslint.org/docs/rules/brace-style
126 | "1tbs", {
127 | "allowSingleLine": true
128 | }],
129 | "quotes": [
130 | 2, "single", "avoid-escape" // http://eslint.org/docs/rules/quotes
131 | ],
132 | "camelcase": [2, { // http://eslint.org/docs/rules/camelcase
133 | "properties": "never"
134 | }],
135 | "comma-spacing": [2, { // http://eslint.org/docs/rules/comma-spacing
136 | "before": false,
137 | "after": true
138 | }],
139 | "comma-style": [2, "last"], // http://eslint.org/docs/rules/comma-style
140 | "eol-last": 2, // http://eslint.org/docs/rules/eol-last
141 | "func-names": 1, // http://eslint.org/docs/rules/func-names
142 | "key-spacing": [2, { // http://eslint.org/docs/rules/key-spacing
143 | "beforeColon": false,
144 | "afterColon": true
145 | }],
146 | "new-cap": [2, { // http://eslint.org/docs/rules/new-cap
147 | "newIsCap": true
148 | }],
149 | "no-multiple-empty-lines": [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines
150 | "max": 2
151 | }],
152 | "no-nested-ternary": 2, // http://eslint.org/docs/rules/no-nested-ternary
153 | "no-new-object": 2, // http://eslint.org/docs/rules/no-new-object
154 | "no-spaced-func": 2, // http://eslint.org/docs/rules/no-spaced-func
155 | "no-trailing-spaces": 2, // http://eslint.org/docs/rules/no-trailing-spaces
156 | "no-extra-parens": 2, // http://eslint.org/docs/rules/no-extra-parens
157 | "no-underscore-dangle": 0, // http://eslint.org/docs/rules/no-underscore-dangle
158 | "one-var": [2, "never"], // http://eslint.org/docs/rules/one-var
159 | "padded-blocks": [2, "never"], // http://eslint.org/docs/rules/padded-blocks
160 | "semi": [2, "always"], // http://eslint.org/docs/rules/semi
161 | "semi-spacing": [2, { // http://eslint.org/docs/rules/semi-spacing
162 | "before": false,
163 | "after": true
164 | }],
165 | "space-after-keywords": 2, // http://eslint.org/docs/rules/space-after-keywords
166 | "space-before-blocks": 2, // http://eslint.org/docs/rules/space-before-blocks
167 | "space-before-function-paren": [2, "never"], // http://eslint.org/docs/rules/space-before-function-paren
168 | "space-infix-ops": 2, // http://eslint.org/docs/rules/space-infix-ops
169 | "space-return-throw-case": 2, // http://eslint.org/docs/rules/space-return-throw-case
170 | "spaced-comment": [2, "always"], // http://eslint.org/docs/rules/spaced-comment
171 |
172 | /**
173 | * JSX style
174 | */
175 | "react/display-name": 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
176 | "react/jsx-boolean-value": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
177 | "react/jsx-quotes": [0, "double"], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quotes.md
178 | "jsx-quotes": [2, "prefer-double"],
179 | "react/jsx-no-undef": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
180 | "react/jsx-sort-props": 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
181 | "react/jsx-sort-prop-types": 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md
182 | "react/jsx-uses-react": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
183 | "react/jsx-uses-vars": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
184 | "react/no-did-mount-set-state": [2, "allow-in-func"], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
185 | "react/no-did-update-set-state": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
186 | "react/no-multi-comp": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
187 | "react/no-unknown-property": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
188 | "react/prop-types": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
189 | "react/react-in-jsx-scope": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
190 | "react/self-closing-comp": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
191 | "react/wrap-multilines": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md
192 | "react/sort-comp": [2, { // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
193 | "order": [
194 | "displayName",
195 | "propTypes",
196 | "contextTypes",
197 | "childContextTypes",
198 | "mixins",
199 | "statics",
200 | "defaultProps",
201 | "constructor",
202 | "getDefaultProps",
203 | "getInitialState",
204 | "getChildContext",
205 | "componentWillMount",
206 | "componentDidMount",
207 | "componentWillReceiveProps",
208 | "shouldComponentUpdate",
209 | "componentWillUpdate",
210 | "componentDidUpdate",
211 | "componentWillUnmount",
212 | "/^on.+$/",
213 | "/^get.+$/",
214 | "/^render.+$/",
215 | "render"
216 | ]
217 | }]
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/src/app/script/worker/ColorConversion.js:
--------------------------------------------------------------------------------
1 | // Color space conversions
2 | // if not specified, parameter value range is: [0, 1]
3 |
4 | // disable one-var linting for frequently grouped color values declaration
5 | // disable new-cap linting for color space name usage in function name
6 | /* eslint-disable one-var, new-cap */
7 |
8 | import {clampBetween, minOf, maxOf} from './util';
9 |
10 | // sRGB Gamma decoding and encoding
11 | // https://en.wikipedia.org/wiki/SRGB
12 | // Csrgb, Clinear below are all in range [0, 1]
13 | function deGamma(Csrgb) {
14 | let Clinear;
15 | if (Csrgb <= 0.04045) {
16 | Clinear = Csrgb / 12.92;
17 | } else {
18 | Clinear = Math.pow(Csrgb + 0.055 / 1.055, 2.4);
19 | }
20 | return Clinear;
21 | }
22 |
23 | function enGamma(Clinear) {
24 | let Csrgb;
25 | if (Clinear <= 0.0031308) {
26 | Csrgb = 12.92 * Clinear;
27 | } else {
28 | Csrgb = 1.055 * Math.pow(Clinear, 1 / 2.4) - 0.055;
29 | }
30 | return Csrgb;
31 | }
32 |
33 | // Luma coefficients presets
34 | // https://en.wikipedia.org/wiki/Luma_%28video%29
35 | const Rec709 = [0.2126, 0.7152, 0.0722];
36 | const Rec601 = [0.299, 0.587, 0.114];
37 |
38 | function luma(r, g, b, R, G, B) {
39 | // R, G, B is coefficients for red/green/blue.
40 | return R * r + G * g + B * b;
41 | }
42 |
43 | function luma709(r, g, b) { return luma(r, g, b, ...Rec709); }
44 | function luma601(r, g, b) { return luma(r, g, b, ...Rec601); }
45 |
46 | // Hue/Saturation/Luma to Red/Green/Blue and back
47 | // These algorithms were taken from KDE Krita's source code.
48 | // https://github.com/KDE/krita/blob/fcf9a431b0af9f51546f986499b9621d5ccdf489/libs/pigment/KoColorConversions.cpp#L630-L841
49 | function HSYToRGB(h, s, y, R, G, B) {
50 | const hue = h >= 0 ? h % 1 : 1 - Math.abs(h % 1); // shift h into range [0, 1]
51 | const sat = clampBetween(s, 0, 1);
52 | const lum = clampBetween(y, 0, 1);
53 | const segment = 0.16666666666666666; // 1/6
54 | let r, g, b;
55 |
56 | let maxSat, m, fract, lumB, chroma, x;
57 |
58 | if (hue >= 0 && hue < segment) {
59 | maxSat = R + G * hue * 6;
60 |
61 | if (lum <= maxSat) {
62 | lumB = lum / maxSat * 0.5;
63 | chroma = sat * 2 * lumB;
64 | } else {
65 | lumB = (lum - maxSat) / ( 1 - maxSat) * 0.5 + 0.5;
66 | chroma = sat * (2 - 2 * lumB);
67 | }
68 |
69 | fract = hue * 6;
70 | x = (1 - Math.abs(fract % 2 - 1)) * chroma;
71 | r = chroma; g = x; b = 0;
72 | m = lum - luma(r, g, b, R, G, B);
73 | r += m; g += m; b += m;
74 | } else if ( hue >= segment && hue < 2 * segment) {
75 | maxSat = G + R - R * (hue - segment) * 6;
76 |
77 | if (lum < maxSat) {
78 | lumB = lum / maxSat * 0.5;
79 | chroma = sat * 2 * lumB;
80 | } else {
81 | lumB = (lum - maxSat) / (1 - maxSat) * 0.5 + 0.5;
82 | chroma = sat * (2 - 2 * lumB);
83 | }
84 |
85 | fract = hue * 6;
86 | x = (1 - Math.abs(fract % 2 - 1)) * chroma;
87 | r = x; g = chroma; b = 0;
88 | m = lum - luma(r, g, b, R, G, B);
89 | r += m; g += m; b += m;
90 | } else if (hue >= 2 * segment && hue < 3 * segment) {
91 | maxSat = G + B * (hue - 2 * segment) * 6;
92 |
93 | if (lum < maxSat) {
94 | lumB = lum / maxSat * 0.5;
95 | chroma = sat * 2 * lumB;
96 | } else {
97 | lumB = (lum - maxSat) / (1 - maxSat) * 0.5 + 0.5;
98 | chroma = sat * (2 - 2 * lumB);
99 | }
100 |
101 | fract = hue * 6.0;
102 | x = (1 - Math.abs(fract % 2 - 1)) * chroma;
103 | r = 0; g = chroma; b = x;
104 | m = lum - luma(r, g, b, R, G, B);
105 | r += m; g += m; b += m;
106 | } else if (hue >= 3 * segment && hue < 4 * segment) {
107 | maxSat = G + B - G * (hue - 3 * segment) * 6;
108 |
109 | if (lum < maxSat) {
110 | lumB = lum / maxSat * 0.5;
111 | chroma = sat * 2 * lumB;
112 | } else {
113 | lumB = (lum - maxSat) / (1 - maxSat) * 0.5 + 0.5;
114 | chroma = sat * (2 - 2 * lumB);
115 | }
116 |
117 | fract = hue * 6;
118 | x = (1 - Math.abs(fract % 2 - 1)) * chroma;
119 | r = 0; g = x; b = chroma;
120 | m = lum - luma(r, g, b, R, G, B);
121 | r += m; g += m; b += m;
122 | } else if (hue >= 4 * segment && hue <= 5 * segment) {
123 | maxSat = B + R * (hue - 4 * segment) * 6;
124 |
125 | if (lum < maxSat) {
126 | lumB = lum / maxSat * 0.5;
127 | chroma = sat * 2 * lumB;
128 | } else {
129 | lumB = (lum - maxSat) / (1 - maxSat) * 0.5 + 0.5;
130 | chroma = sat * (2 - 2 * lumB);
131 | }
132 |
133 | fract = hue * 6;
134 | x = (1 - Math.abs(fract % 2 - 1)) * chroma;
135 | r = x; g = 0; b = chroma;
136 | m = lum - luma(r, g, b, R, G, B);
137 | r += m; g += m; b += m;
138 | } else if (hue > 5 * segment && hue < 1) {
139 | maxSat = B + R - B * (hue - 5 * segment) * 6;
140 |
141 | if (lum < maxSat) {
142 | lumB = lum / maxSat * 0.5;
143 | chroma = sat * 2 * lumB;
144 | } else {
145 | lumB = (lum - maxSat) / (1 - maxSat) * 0.5 + 0.5;
146 | chroma = sat * (2 - 2 * lumB);
147 | }
148 |
149 | fract = hue * 6;
150 | x = (1 - Math.abs(fract % 2 - 1)) * chroma;
151 | r = chroma; g = 0; b = x;
152 | m = lum - luma(r, g, b, R, G, B);
153 | r += m; g += m; b += m;
154 | } else {
155 | r = 0;
156 | g = 0;
157 | b = 0;
158 | }
159 |
160 | r = clampBetween(r, 0, 1);
161 | g = clampBetween(g, 0, 1);
162 | b = clampBetween(b, 0, 1);
163 |
164 | return [r, g, b];
165 | }
166 |
167 | function RGBToHSY(r, g, b, R, G, B) {
168 | const red = clampBetween(r, 0, 1);
169 | const green = clampBetween(g, 0, 1);
170 | const blue = clampBetween(b, 0, 1);
171 | const m = minOf(r, g, b);
172 | const M = maxOf(r, g, b);
173 | const chroma = M - m;
174 | let hue, sat, lum;
175 | let lumB, maxSat;
176 | let h, s, y;
177 |
178 | lum = R * red + G * green + B * blue;
179 | lumB = lum;
180 | maxSat = 0.5;
181 |
182 | if (chroma === 0) {
183 | hue = 0;
184 | sat = 0;
185 | } else {
186 | // the following finds the hue
187 | if (M === r) {
188 | if ( m === b) {
189 | hue = (g - b) / chroma;
190 | } else {
191 | hue = (g - b) / chroma + 6;
192 | }
193 | } else if (M === g) {
194 | hue = (b - r) / chroma + 2;
195 | } else if (M === b) {
196 | hue = (r - g) / chroma + 4;
197 | }
198 | hue /= 6;
199 |
200 | const segment = 0.16666666666666666; // 1/6
201 | if (hue > 1 || hue < 0) { hue = hue % 1; }
202 |
203 | if (hue >= 0 && hue < segment) {
204 | maxSat = R + G * hue * 6;
205 | } else if (hue >= segment && hue < 2 * segment) {
206 | maxSat = G + R - R * (hue - segment) * 6;
207 | } else if (hue >= 2 * segment && hue < 3 * segment) {
208 | maxSat = G + B * (hue - 2 * segment) * 6;
209 | } else if (hue >= 3 * segment && hue < 4 * segment) {
210 | maxSat = B + G - G * (hue - 3 * segment) * 6;
211 | } else if (hue >= 4 * segment && hue < 5 * segment) {
212 | maxSat = B + R * (hue - 4 * segment) * 6;
213 | } else if (hue >= 5 * segment && hue < 1) {
214 | maxSat = R + B - B * (hue - 5 * segment) * 6;
215 | } else {
216 | maxSat = 0.5;
217 | }
218 |
219 | if (maxSat > 1 || maxSat < 0) { // this should not show up during normal use
220 | maxSat = maxSat % 1; // if it does, it'll try to correct, but it's not good !
221 | }
222 |
223 | if (lum <= maxSat) {
224 | lumB = lum / maxSat * 0.5;
225 | } else {
226 | lumB = (lum - maxSat) / (1 - maxSat) * 0.5 + 0.5; // This is weighting the luma for the saturation
227 | }
228 |
229 | sat = chroma;
230 | if (sat > 0) {
231 | sat = lum <= maxSat ? chroma / 2 * lumB : chroma / (2 - 2 * lumB);
232 | }
233 | }
234 |
235 | h = hue;
236 | s = clampBetween(sat, 0, 1);
237 | y = clampBetween(lum, 0, 1);
238 | return [h, s, y];
239 | }
240 |
241 | function HSY709ToRGB(h, s, y) { return HSYToRGB(h, s, y, ...Rec709); }
242 | function RGBToHSY709(r, g, b) { return RGBToHSY(r, g, b, ...Rec709); }
243 |
244 | function HSY601ToRGB(h, s, y) { return HSYToRGB(h, s, y, ...Rec601); }
245 | function RGBToHSY601(r, g, b) { return RGBToHSY(r, g, b, ...Rec601); }
246 |
247 | // Hue/Chroma/Luma to Red/Green/Blue and back
248 | // algorithm taken from Wiki, modified to fit [0, 1] hue range
249 | // https://en.wikipedia.org/wiki/HSL_and_HSV#From_luma.2Fchroma.2Fhue
250 | function HCYToRGB(iH, iC, iY, R, G, B) {
251 | // R, G, B is coefficients for red/green/blue.
252 | const h = iH >= 0 ? iH % 1 : 1 - Math.abs(iH % 1);
253 | const c = clampBetween(iC, 0, 1);
254 | const y = clampBetween(iY, 0, 1);
255 |
256 | const hm = h * 6;
257 | const x = clampBetween(c, 0, 1) * (1 - Math.abs(hm % 2 - 1));
258 | let r, g, b;
259 | let r1, g1, b1;
260 | if (hm >= 0 && hm < 1) {
261 | [r1, g1, b1] = [c, x, 0];
262 | } else if (hm >= 1 && hm < 2) {
263 | [r1, g1, b1] = [x, c, 0];
264 | } else if (hm >= 2 && hm < 3) {
265 | [r1, g1, b1] = [0, c, x];
266 | } else if (hm >= 3 && hm < 4) {
267 | [r1, g1, b1] = [0, x, c];
268 | } else if (hm >= 4 && hm < 5) {
269 | [r1, g1, b1] = [x, 0, c];
270 | } else if (hm >= 5 && hm <= 6) {
271 | [r1, g1, b1] = [c, 0, x];
272 | } else {
273 | [r1, g1, b1] = [0, 0, 0];
274 | }
275 | const m = y - (R * r1 + G * g1 + B * b1);
276 | [r, g, b] = [r1 + m, g1 + m, b1 + m];
277 | return [r, g, b];
278 | }
279 |
280 | function RGBToHCY(iR, iG, iB, R, G, B) {
281 | // R, G, B is coefficients for red/green/blue.
282 | const r = clampBetween(iR, 0, 1);
283 | const g = clampBetween(iG, 0, 1);
284 | const b = clampBetween(iB, 0, 1);
285 |
286 | const M = maxOf(r, g, b);
287 | const m = minOf(r, g, b);
288 | let h, c, y;
289 | let hm;
290 | c = M - m;
291 | if (c === 0) {
292 | hm = 0;
293 | } else {
294 | switch (M) {
295 | case r:
296 | hm = (g - b) / c % 6;
297 | break;
298 | case g:
299 | hm = (b - r) / c + 2;
300 | break;
301 | case b:
302 | hm = (r - g) / c + 4;
303 | break;
304 | default:
305 | break;
306 | }
307 | }
308 | h = hm / 6;
309 | y = luma(r, g, b, R, G, B);
310 | return [h, c, y];
311 | }
312 |
313 | function HCY709ToRGB(h, s, y) { return HCYToRGB(h, s, y, ...Rec709); }
314 | function RGBToHCY709(r, g, b) { return RGBToHCY(r, g, b, ...Rec709); }
315 |
316 | function HCY601ToRGB(h, s, y) { return HCYToRGB(h, s, y, ...Rec601); }
317 | function RGBToHCY601(r, g, b) { return RGBToHCY(r, g, b, ...Rec601); }
318 |
319 | // Hue/Saturation/Lightness to Red/Green/Blue and back
320 | // algorithm from Wiki, hue value modified to fit [0, 1] range.
321 | // https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSL
322 | function HSLToRGB(iH, iS, iL) {
323 | const h = iH >= 0 ? iH % 1 : 1 - Math.abs(iH % 1);
324 | const s = clampBetween(iS, 0, 1);
325 | const l = clampBetween(iL, 0, 1);
326 |
327 | const chroma = (1 - Math.abs(2 * l - 1)) * s;
328 | const hue = h * 6;
329 | const x = chroma * (1 - Math.abs(hue % 2 - 1));
330 | let r1, g1, b1;
331 | let r, g, b;
332 |
333 | if (hue >= 0 && hue < 1) {
334 | [r1, g1, b1] = [chroma, x, 0];
335 | } else if (hue >= 1 && hue < 2) {
336 | [r1, g1, b1] = [x, chroma, 0];
337 | } else if (hue >= 2 && hue < 3) {
338 | [r1, g1, b1] = [0, chroma, x];
339 | } else if (hue >= 3 && hue < 4) {
340 | [r1, g1, b1] = [0, x, chroma];
341 | } else if (hue >= 4 && hue < 5) {
342 | [r1, g1, b1] = [x, 0, chroma];
343 | } else if (hue >= 5 && hue <= 6) {
344 | [r1, g1, b1] = [chroma, 0, x];
345 | } else {
346 | [r1, g1, b1] = [0, 0, 0];
347 | }
348 |
349 | const m = l - 0.5 * chroma;
350 | [r, g, b] = [r1 + m, g1 + m, b1 + m];
351 | return [r, g, b];
352 | }
353 |
354 | function RGBToHSL(iR, iG, iB) {
355 | const r = clampBetween(iR, 0, 1);
356 | const g = clampBetween(iG, 0, 1);
357 | const b = clampBetween(iB, 0, 1);
358 |
359 | const M = maxOf(r, g, b);
360 | const m = minOf(r, g, b);
361 | const chroma = M - m;
362 | let hue;
363 | let h, s, l;
364 |
365 | if (r === M) {
366 | hue = (g - b) / chroma % 6;
367 | } else if (g === M) {
368 | hue = (b - r) / chroma + 2;
369 | } else if (b === M) {
370 | hue = (r - g) / chroma + 4;
371 | }
372 |
373 | h = hue / 6; // make sure h in [0, 1] range
374 | l = 0.5 * (M + m);
375 |
376 | if (chroma === 0) {
377 | s = 0;
378 | } else {
379 | s = chroma / (1 - Math.abs(2 * l - 1));
380 | }
381 |
382 | return [h, s, l];
383 | }
384 |
385 | // Hue/Saturation/Value to Red/Green/Blue and back
386 | // algorithm from Wiki, hue value modified to fit [0, 1] range
387 | // https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV
388 | function HSVToRGB(iH, iS, iV) {
389 | const h = iH >= 0 ? iH % 1 : 1 - Math.abs(iH % 1);
390 | const s = clampBetween(iS, 0, 1);
391 | const v = clampBetween(iV, 0, 1);
392 |
393 | const chroma = v * s;
394 | const hue = h * 6;
395 | const x = chroma * (1 - Math.abs(hue % 2 - 1));
396 | let r1, g1, b1;
397 | let r, g, b;
398 |
399 | if (hue >= 0 && hue < 1) {
400 | [r1, g1, b1] = [chroma, x, 0];
401 | } else if (hue >= 1 && hue < 2) {
402 | [r1, g1, b1] = [x, chroma, 0];
403 | } else if (hue >= 2 && hue < 3) {
404 | [r1, g1, b1] = [0, chroma, x];
405 | } else if (hue >= 3 && hue < 4) {
406 | [r1, g1, b1] = [0, x, chroma];
407 | } else if (hue >= 4 && hue < 5) {
408 | [r1, g1, b1] = [x, 0, chroma];
409 | } else if (hue >= 5 && hue <= 6) {
410 | [r1, g1, b1] = [chroma, 0, x];
411 | } else {
412 | [r1, g1, b1] = [0, 0, 0];
413 | }
414 |
415 | const m = v - chroma;
416 | [r, g, b] = [r1 + m, g1 + m, b1 + m];
417 | return [r, g, b];
418 | }
419 |
420 | function RGBToHSV(iR, iG, iB) {
421 | const r = clampBetween(iR, 0, 1);
422 | const g = clampBetween(iG, 0, 1);
423 | const b = clampBetween(iB, 0, 1);
424 |
425 | const M = maxOf(r, g, b);
426 | const m = minOf(r, g, b);
427 | const chroma = M - m;
428 | let hue;
429 | let h, s, v;
430 |
431 | if (r === M) {
432 | hue = (g - b) / chroma % 6;
433 | } else if (g === M) {
434 | hue = (b - r) / chroma + 2;
435 | } else if (b === M) {
436 | hue = (r - g) / chroma + 4;
437 | } else if (chroma === 0) {
438 | // if no chroma, set hue to 0
439 | hue = 0;
440 | }
441 |
442 | h = hue / 6;
443 | v = M;
444 |
445 | if (chroma === 0) {
446 | s = 0;
447 | } else {
448 | s = chroma / v;
449 | }
450 |
451 | return [h, s, v];
452 | }
453 |
454 | export {
455 | enGamma, deGamma,
456 | luma, luma601, luma709,
457 | HSYToRGB, RGBToHSY,
458 | HSY709ToRGB, RGBToHSY709,
459 | HSY601ToRGB, RGBToHSY601,
460 | HCYToRGB, RGBToHCY,
461 | HCY709ToRGB, RGBToHCY709,
462 | HCY601ToRGB, RGBToHCY601,
463 | HSLToRGB, RGBToHSL,
464 | HSVToRGB, RGBToHSV,
465 | };
466 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------