bare-jpeg 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +26 -12
- package/package.json +1 -1
- package/prebuilds/android-arm/bare-jpeg.bare +0 -0
- package/prebuilds/android-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/android-ia32/bare-jpeg.bare +0 -0
- package/prebuilds/android-x64/bare-jpeg.bare +0 -0
- package/prebuilds/darwin-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/darwin-x64/bare-jpeg.bare +0 -0
- package/prebuilds/ios-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-jpeg.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-jpeg.bare +0 -0
- package/prebuilds/linux-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/linux-x64/bare-jpeg.bare +0 -0
- package/prebuilds/win32-arm64/bare-jpeg.bare +0 -0
- package/prebuilds/win32-x64/bare-jpeg.bare +0 -0
package/index.js
CHANGED
|
@@ -45,6 +45,8 @@ exports.replaceMarkers = function replaceMarkers(image, markers = []) {
|
|
|
45
45
|
|
|
46
46
|
const output = [image.subarray(0, 2)]
|
|
47
47
|
let offset = 2
|
|
48
|
+
let next = 0
|
|
49
|
+
let insertAt = 1
|
|
48
50
|
|
|
49
51
|
while (offset < image.length) {
|
|
50
52
|
const start = offset
|
|
@@ -60,18 +62,13 @@ exports.replaceMarkers = function replaceMarkers(image, markers = []) {
|
|
|
60
62
|
const marker = image[offset]
|
|
61
63
|
|
|
62
64
|
if (marker === SOS || marker === EOI) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
segment.writeUInt16BE(payload.length + 2, 2)
|
|
70
|
-
payload.copy(segment, 4)
|
|
71
|
-
|
|
72
|
-
output.push(segment)
|
|
65
|
+
const leftover = []
|
|
66
|
+
while (next < markers.length) {
|
|
67
|
+
leftover.push(buildSegment(markers[next++]))
|
|
68
|
+
}
|
|
69
|
+
if (leftover.length > 0) {
|
|
70
|
+
output.splice(insertAt, 0, ...leftover)
|
|
73
71
|
}
|
|
74
|
-
|
|
75
72
|
output.push(image.subarray(start))
|
|
76
73
|
return Buffer.concat(output)
|
|
77
74
|
}
|
|
@@ -87,7 +84,12 @@ exports.replaceMarkers = function replaceMarkers(image, markers = []) {
|
|
|
87
84
|
throw new Error('Invalid JPEG')
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
if ((marker
|
|
87
|
+
if ((marker >= APP0 && marker <= APP15) || marker === COM) {
|
|
88
|
+
if (next < markers.length) {
|
|
89
|
+
output.push(buildSegment(markers[next++]))
|
|
90
|
+
insertAt = output.length
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
91
93
|
output.push(image.subarray(start, end))
|
|
92
94
|
}
|
|
93
95
|
|
|
@@ -97,6 +99,18 @@ exports.replaceMarkers = function replaceMarkers(image, markers = []) {
|
|
|
97
99
|
throw new Error('Invalid JPEG')
|
|
98
100
|
}
|
|
99
101
|
|
|
102
|
+
function buildSegment(marker) {
|
|
103
|
+
const payload = Buffer.from(marker.data)
|
|
104
|
+
const segment = Buffer.allocUnsafe(payload.length + 4)
|
|
105
|
+
|
|
106
|
+
segment[0] = MARKER_PREFIX
|
|
107
|
+
segment[1] = marker.marker
|
|
108
|
+
segment.writeUInt16BE(payload.length + 2, 2)
|
|
109
|
+
payload.copy(segment, 4)
|
|
110
|
+
|
|
111
|
+
return segment
|
|
112
|
+
}
|
|
113
|
+
|
|
100
114
|
function clamp(value, min, max) {
|
|
101
115
|
return Math.max(min, Math.min(max, value))
|
|
102
116
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|