Parcourir la source

Fix byte clamping, close #252

phoboslab il y a 6 ans
Parent
révision
8e3d87f8ec
2 fichiers modifiés avec 10 ajouts et 9 suppressions
  1. 1 1
      jsmpeg.min.js
  2. 9 8
      src/wasm/mpeg1.c

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 1
jsmpeg.min.js


+ 9 - 8
src/wasm/mpeg1.c Voir le fichier

@@ -1643,6 +1643,7 @@ void add_block_to_destination(int *block, uint8_t *dest, int index, int scan) {
1643 1643
 }
1644 1644
 
1645 1645
 void copy_value_to_destination(int value, uint8_t *dest, int index, int scan) {
1646
+	value = clamp_to_uint8(value);
1646 1647
 	for (int n = 0; n < 64; n += 8, index += scan+8) {
1647 1648
 		dest[index+0] = value;
1648 1649
 		dest[index+1] = value;
@@ -1657,14 +1658,14 @@ void copy_value_to_destination(int value, uint8_t *dest, int index, int scan) {
1657 1658
 
1658 1659
 void add_value_to_destination(int value, uint8_t *dest, int index, int scan) {
1659 1660
 	for (int n = 0; n < 64; n += 8, index += scan+8) {
1660
-		dest[index+0] += value;
1661
-		dest[index+1] += value;
1662
-		dest[index+2] += value;
1663
-		dest[index+3] += value;
1664
-		dest[index+4] += value;
1665
-		dest[index+5] += value;
1666
-		dest[index+6] += value;
1667
-		dest[index+7] += value;
1661
+		dest[index+0] = clamp_to_uint8(dest[index+0] + value);
1662
+		dest[index+1] = clamp_to_uint8(dest[index+1] + value);
1663
+		dest[index+2] = clamp_to_uint8(dest[index+2] + value);
1664
+		dest[index+3] = clamp_to_uint8(dest[index+3] + value);
1665
+		dest[index+4] = clamp_to_uint8(dest[index+4] + value);
1666
+		dest[index+5] = clamp_to_uint8(dest[index+5] + value);
1667
+		dest[index+6] = clamp_to_uint8(dest[index+6] + value);
1668
+		dest[index+7] = clamp_to_uint8(dest[index+7] + value);
1668 1669
 	}
1669 1670
 }
1670 1671