-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Scopics/main
Merge main in release-branch
- Loading branch information
Showing
13 changed files
with
81 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules/ | ||
static/ | ||
test/ | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
README.md | ||
test/ | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const brightnessTransofrm = (options, data) => { | ||
const { ajustment } = options; | ||
for (let i = 0; i < data.length; i++) { | ||
data[i] += ajustment; | ||
} | ||
return Array.from(data); | ||
}; | ||
|
||
module.exports = brightnessTransofrm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
'use strict'; | ||
|
||
const grayscaleCofs = { | ||
red: 0.2126, | ||
green: 0.7152, | ||
blue: 0.0722, | ||
}; | ||
const PIXEL_DATA_LEN = 4; | ||
|
||
module.exports = (data) => { | ||
const grayscaleCofs = [0.2126, 0.7152, 0.0722]; | ||
const length = data.length; | ||
for (let i = 0; i < length; i += 4) { | ||
const pictureColors = data.slice(i, i + 3); | ||
for (let i = 0; i < length; i += PIXEL_DATA_LEN) { | ||
const pictureColors = data.slice(i, i + PIXEL_DATA_LEN); | ||
|
||
const val = pictureColors.reduce( | ||
(acc, color, index) => acc + color * grayscaleCofs[index], | ||
const val = Object.values(grayscaleCofs).reduce( | ||
(acc, color, index) => acc + color * pictureColors[index], | ||
0 | ||
); | ||
|
||
data[i] = data[i + 1] = data[i + 2] = val; | ||
const rIndex = i; | ||
const gIndex = i + 1; | ||
const bIndex = i + 2; | ||
|
||
data[rIndex] = data[gIndex] = data[bIndex] = val; | ||
} | ||
return data; | ||
return Array.from(data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = (data) => { | ||
for (let i = 0; i < data.length; i += 3) { | ||
data[i] += 40; | ||
data[i + 1] += 40; | ||
data[i + 2] += 40; | ||
} | ||
return data; | ||
const brightnessTransofrm = require('./brightness'); | ||
|
||
const testOptions = { | ||
ajustment: 40, | ||
}; | ||
|
||
module.exports = brightnessTransofrm.bind(null, testOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = (data) => { | ||
for (let i = 0; i < data.length; i += 3) { | ||
data[i] += 50; | ||
data[i + 1] += 50; | ||
data[i + 2] += 50; | ||
} | ||
return data; | ||
const brightnessTransofrm = require('./brightness'); | ||
|
||
const testOptions = { | ||
ajustment: 30, | ||
}; | ||
|
||
module.exports = brightnessTransofrm.bind(null, testOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
const currentUrl = window.location.pathname; | ||
const errorBlockElement = document.getElementById('error-block'); | ||
const url = `/api${currentUrl}`; | ||
generateBtn.addEventListener('click', () => { | ||
generateBtn.addEventListener('click', async () => { | ||
const body = { | ||
data: Array.from(state.imageData.data), | ||
}; | ||
|
||
fetch(url, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(body), | ||
}) | ||
.then((response) => { | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
imageDataToImg(data); | ||
}) | ||
.catch(() => { | ||
errorBlockElement.innerHTML = 'Error happened'; | ||
try { | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(body), | ||
}); | ||
const imageData = await response.json(); | ||
imageDataToImg(imageData); | ||
} catch (e) { | ||
errorBlockElement.innerHTML = 'Error happened'; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters