Browse Source

exercise 3 done

master
fdai7303 2 years ago
parent
commit
f2b2b11429
  1. 12
      src/03/gammacorrection.ts
  2. 15
      src/03/grayscale.ts
  3. 13
      src/03/quantisecolor.ts
  4. 24
      src/03/quantisegrayscale.ts

12
src/03/gammacorrection.ts

@ -15,4 +15,16 @@ export function gammaAdjust(gamma: number, source: Uint8ClampedArray,
width: number, height: number) {
// TODO: Perform a gamma correction with the given gamma value on the current pixel at position (x, y) in the source array, and store the result in the dest array.
var posInArrayX = x * 4;
var posInArrayY = y * 4 * width;
var R = source[0 + posInArrayX + posInArrayY];
var G = source[1 + posInArrayX + posInArrayY];
var B = source[2 + posInArrayX + posInArrayY];
var A = source[3 + posInArrayX + posInArrayY];
dest[0 + posInArrayX + posInArrayY] = Math.pow((R/256),(1/gamma))*256;
dest[1 + posInArrayX + posInArrayY] = Math.pow((G/256),(1/gamma))*256;
dest[2 + posInArrayX + posInArrayY] = Math.pow((B/256),(1/gamma))*256;
dest[3 + posInArrayX + posInArrayY] = A;
}

15
src/03/grayscale.ts

@ -13,4 +13,19 @@ export function grayscale(x: number, y: number, source: Uint8ClampedArray, targe
// TODO: Convert the pixel at position (x, y) in the source array from RGB to XYZ.
// TODO: Set the RGBA values in the target array according to the Y component of the source pixel in XYZ space.
var posInArrayX = x * 4;
var posInArrayY = y * 4 * width;
var matrix = [ 0.4124564, 0.3575761, 0.1804375,
0.2126729, 0.7151522, 0.0721750,
0.0193339, 0.1191920, 0.9503041];
var R = source[0 + posInArrayX + posInArrayY];
var G = source[1 + posInArrayX + posInArrayY];
var B = source[2 + posInArrayX + posInArrayY];
var A = source[3 + posInArrayX + posInArrayY];
target[0 + posInArrayX + posInArrayY] = Math.abs(matrix[3]*R + matrix[4]*G + matrix[5]*B); // (R+B+G)/3;
target[1 + posInArrayX + posInArrayY] = Math.abs(matrix[3]*R + matrix[4]*G + matrix[5]*B); // (R+B+G)/3;
target[2 + posInArrayX + posInArrayY] = Math.abs(matrix[3]*R + matrix[4]*G + matrix[5]*B); // (R+B+G)/3;
target[3 + posInArrayX + posInArrayY] = A;
}

13
src/03/quantisecolor.ts

@ -14,4 +14,17 @@ export function quantiseColor(x: number, y: number, source: Uint8ClampedArray, t
// TODO: Limit the brightness of each color channel to the set of 4 different values 0, 85, 170, 255.
// TODO: Set the RGBA values in the target array accordingly.
// TODO:
var posInArrayX = x * 4;
var posInArrayY = y * 4 * width;
var R = source[0 + posInArrayX + posInArrayY];
var G = source[1 + posInArrayX + posInArrayY];
var B = source[2 + posInArrayX + posInArrayY];
var A = source[3 + posInArrayX + posInArrayY];
//quantisierung
for(let i = 0; i < 3; i++) {
target[i + posInArrayX + posInArrayY] = (Math.floor((source[i + posInArrayX + posInArrayY]/256) * (4))) * (256/3);
}
target[3 + posInArrayX + posInArrayY] = A;
}

24
src/03/quantisegrayscale.ts

@ -14,4 +14,28 @@ export function quantisegrayscale(x: number, y: number, source: Uint8ClampedArra
// TODO: Convert the pixel at position (x, y) in the source array from RGB to XYZ. Limit the
// TODO: Limit the brightness to the set of 4 different values 0, 85, 170, 255.
// TODO: Set the RGBA values in the target array to this brightness.
var posInArrayX = x * 4;
var posInArrayY = y * 4 * width;
var matrix = [ 0.4124564, 0.3575761, 0.1804375,
0.2126729, 0.7151522, 0.0721750,
0.0193339, 0.1191920, 0.9503041];
var R = source[0 + posInArrayX + posInArrayY];
var G = source[1 + posInArrayX + posInArrayY];
var B = source[2 + posInArrayX + posInArrayY];
var A = source[3 + posInArrayX + posInArrayY];
var X = 0;
var Y = Math.abs(matrix[3]*R + matrix[4]*G + matrix[5]*B)
var Z = 0;
//quantisierung
let QY = (Y/256) * (4);
QY = Math.floor(QY);
QY = QY * (256/3);
target[0 + posInArrayX + posInArrayY] = QY;
target[1 + posInArrayX + posInArrayY] = QY;
target[2 + posInArrayX + posInArrayY] = QY;
target[3 + posInArrayX + posInArrayY] = A;
}
Loading…
Cancel
Save