Skip to content

Commit

Permalink
created exposure and tint in core
Browse files Browse the repository at this point in the history
  • Loading branch information
VinciGit00 committed Mar 12, 2024
1 parent 0a230d3 commit dd43793
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/change_exposure.js
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;
}
23 changes: 23 additions & 0 deletions src/core/change_tint.js
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;
}

0 comments on commit dd43793

Please sign in to comment.