-
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.
- Loading branch information
1 parent
0a230d3
commit dd43793
Showing
2 changed files
with
46 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Function to change the exposure of an image. | ||
* @param {number[]} pixelArray: Image pixel array in the format [R, G, B, alpha,..., R, G, B, alpha]. | ||
* @param {number} factor: Factor to adjust the exposure (-100 to 100). | ||
* @returns {number[]} Pixel array of the image with adjusted exposure. | ||
*/ | ||
function changeExposure(pixelArray, factor) { | ||
for (let i = 0; i < pixelArray.length; i += 4) { | ||
const r = pixelArray[i]; | ||
const g = pixelArray[i + 1]; | ||
const b = pixelArray[i + 2]; | ||
|
||
// Apply exposure adjustment to each channel | ||
const newR = Math.max(0, Math.min(255, r + factor * 2.55)); // Factor scaled to range 0-255 | ||
const newG = Math.max(0, Math.min(255, g + factor * 2.55)); | ||
const newB = Math.max(0, Math.min(255, b + factor * 2.55)); | ||
|
||
pixelArray[i] = newR; | ||
pixelArray[i + 1] = newG; | ||
pixelArray[i + 2] = newB; | ||
} | ||
return pixelArray; | ||
} |
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,23 @@ | ||
/** | ||
* Function to change the tint of an image. | ||
* @param {number[]} pixelArray: Image pixel array in the format [R, G, B, alpha,..., R, G, B, alpha]. | ||
* @param {number} tint: Tint to apply (-100 to 100). | ||
* @returns {number[]} Pixel array of the image with adjusted tint. | ||
*/ | ||
function changeTint(pixelArray, tint) { | ||
for (let i = 0; i < pixelArray.length; i += 4) { | ||
const r = pixelArray[i]; | ||
const g = pixelArray[i + 1]; | ||
const b = pixelArray[i + 2]; | ||
|
||
// Apply tint adjustment to each channel | ||
const newR = Math.max(0, Math.min(255, r + (255 - r) * (tint / 100))); | ||
const newG = Math.max(0, Math.min(255, g + (255 - g) * (tint / 100))); | ||
const newB = Math.max(0, Math.min(255, b + (255 - b) * (tint / 100))); | ||
|
||
pixelArray[i] = newR; | ||
pixelArray[i + 1] = newG; | ||
pixelArray[i + 2] = newB; | ||
} | ||
return pixelArray; | ||
} |