byte-codec 1.0.1 → 1.0.2

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.
Files changed (41) hide show
  1. package/dist/index-DCdK98vS.d.cts +81 -0
  2. package/dist/index-DCdK98vS.d.ts +81 -0
  3. package/dist/index.cjs +562 -22
  4. package/dist/index.d.cts +81 -0
  5. package/dist/index.d.ts +81 -0
  6. package/dist/index.js +548 -8
  7. package/package.json +4 -4
  8. package/dist/bytes/crc32-BVCBBYa3.d.cts +0 -4
  9. package/dist/bytes/crc32-BVCBBYa3.d.ts +0 -4
  10. package/dist/bytes/crc32.cjs +0 -21
  11. package/dist/bytes/crc32.js +0 -20
  12. package/dist/bytes/flate-CbSD2OU9.d.cts +0 -12
  13. package/dist/bytes/flate-CbSD2OU9.d.ts +0 -12
  14. package/dist/bytes/flate.cjs +0 -53
  15. package/dist/bytes/flate.js +0 -49
  16. package/dist/bytes/reader-CDx_NmAQ.d.cts +0 -20
  17. package/dist/bytes/reader-CDx_NmAQ.d.ts +0 -20
  18. package/dist/bytes/reader.cjs +0 -60
  19. package/dist/bytes/reader.js +0 -58
  20. package/dist/bytes/writer-B9uaqo-B.d.cts +0 -13
  21. package/dist/bytes/writer-B9uaqo-B.d.ts +0 -13
  22. package/dist/bytes/writer.cjs +0 -37
  23. package/dist/bytes/writer.js +0 -35
  24. package/dist/image/jpeg-info-Dh6D8PRh.d.cts +0 -12
  25. package/dist/image/jpeg-info-Dh6D8PRh.d.ts +0 -12
  26. package/dist/image/jpeg-info.cjs +0 -71
  27. package/dist/image/jpeg-info.js +0 -70
  28. package/dist/image/png-decode-Dvizumot.d.cts +0 -14
  29. package/dist/image/png-decode-Dvizumot.d.ts +0 -14
  30. package/dist/image/png-decode.cjs +0 -181
  31. package/dist/image/png-decode.js +0 -180
  32. package/dist/image/png-encode-C5Jj9gBX.d.ts +0 -9
  33. package/dist/image/png-encode-CpwBOmkg.d.cts +0 -9
  34. package/dist/image/png-encode.cjs +0 -64
  35. package/dist/image/png-encode.js +0 -63
  36. package/dist/image/png-filter-5L1Q0PDF.d.cts +0 -6
  37. package/dist/image/png-filter-5L1Q0PDF.d.ts +0 -6
  38. package/dist/image/png-filter.cjs +0 -95
  39. package/dist/image/png-filter.js +0 -93
  40. package/dist/index-VKR9nd94.d.ts +0 -9
  41. package/dist/index-v-4chATX.d.cts +0 -9
@@ -1,93 +0,0 @@
1
- //#region src/image/png-filter.ts
2
- function paethPredictor(a, b, c) {
3
- const p = a + b - c;
4
- const pa = Math.abs(p - a);
5
- const pb = Math.abs(p - b);
6
- const pc = Math.abs(p - c);
7
- if (pa <= pb && pa <= pc) return a;
8
- if (pb <= pc) return b;
9
- return c;
10
- }
11
- function isPngFilterType(value) {
12
- return value === 0 || value === 1 || value === 2 || value === 3 || value === 4;
13
- }
14
- function predictorValue(filterType, a, b, c) {
15
- if (filterType === 1) return a;
16
- if (filterType === 2) return b;
17
- if (filterType === 3) return Math.floor((a + b) / 2);
18
- if (filterType === 4) return paethPredictor(a, b, c);
19
- return 0;
20
- }
21
- function unfilterScanlines(data, height, bytesPerRow, bpp) {
22
- const stride = bytesPerRow + 1;
23
- if (data.length < height * stride) throw new Error(`PNG scanline data too short: expected at least ${height * stride} bytes, got ${data.length}`);
24
- const out = new Uint8Array(height * bytesPerRow);
25
- for (let y = 0; y < height; y++) {
26
- const filterByte = data[y * stride];
27
- if (filterByte === void 0 || !isPngFilterType(filterByte)) throw new Error(`unknown PNG filter type: ${String(filterByte)}`);
28
- const rowStart = y * stride + 1;
29
- const outRowStart = y * bytesPerRow;
30
- const prevOutRowStart = y > 0 ? outRowStart - bytesPerRow : void 0;
31
- for (let x = 0; x < bytesPerRow; x++) {
32
- const raw = data[rowStart + x];
33
- const a = x >= bpp ? out[outRowStart + x - bpp] : 0;
34
- const b = prevOutRowStart === void 0 ? 0 : out[prevOutRowStart + x];
35
- const c = x >= bpp && prevOutRowStart !== void 0 ? out[prevOutRowStart + x - bpp] : 0;
36
- out[outRowStart + x] = raw + predictorValue(filterByte, a, b, c) & 255;
37
- }
38
- }
39
- return out;
40
- }
41
- function sumOfAbsSigned(bytes) {
42
- let sum = 0;
43
- for (const byte of bytes) sum += byte < 128 ? byte : 256 - byte;
44
- return sum;
45
- }
46
- function filterRowInto(raw, rowStart, prevRowStart, bytesPerRow, bpp, filterType, out, outOffset) {
47
- for (let x = 0; x < bytesPerRow; x++) {
48
- const rawByte = raw[rowStart + x];
49
- const a = x >= bpp ? raw[rowStart + x - bpp] : 0;
50
- const b = prevRowStart === void 0 ? 0 : raw[prevRowStart + x];
51
- const c = x >= bpp && prevRowStart !== void 0 ? raw[prevRowStart + x - bpp] : 0;
52
- out[outOffset + x] = rawByte - predictorValue(filterType, a, b, c) & 255;
53
- }
54
- }
55
- const ALL_FILTER_TYPES = [
56
- 0,
57
- 1,
58
- 2,
59
- 3,
60
- 4
61
- ];
62
- function filterScanlines(raw, height, bytesPerRow, bpp, strategy = "adaptive") {
63
- const stride = bytesPerRow + 1;
64
- const out = new Uint8Array(height * stride);
65
- const candidate = new Uint8Array(bytesPerRow);
66
- for (let y = 0; y < height; y++) {
67
- const rowStart = y * bytesPerRow;
68
- const prevRowStart = y > 0 ? rowStart - bytesPerRow : void 0;
69
- const outRowStart = y * stride;
70
- if (strategy === "none") {
71
- out[outRowStart] = 0;
72
- filterRowInto(raw, rowStart, prevRowStart, bytesPerRow, bpp, 0, out, outRowStart + 1);
73
- continue;
74
- }
75
- let bestType = 0;
76
- let bestSum = Number.POSITIVE_INFINITY;
77
- let best;
78
- for (const filterType of ALL_FILTER_TYPES) {
79
- filterRowInto(raw, rowStart, prevRowStart, bytesPerRow, bpp, filterType, candidate, 0);
80
- const sum = sumOfAbsSigned(candidate);
81
- if (sum < bestSum) {
82
- bestSum = sum;
83
- bestType = filterType;
84
- best = candidate.slice();
85
- }
86
- }
87
- out[outRowStart] = bestType;
88
- if (best !== void 0) out.set(best, outRowStart + 1);
89
- }
90
- return out;
91
- }
92
- //#endregion
93
- export { filterScanlines, unfilterScanlines };
@@ -1,9 +0,0 @@
1
- import { crc32 } from "./bytes/crc32-BVCBBYa3.js";
2
- import { DeflateLevel, InflateResult, MAX_INFLATE_OUTPUT_BYTES, deflate, inflate, inflateTolerant } from "./bytes/flate-CbSD2OU9.js";
3
- import { ByteReader, isAsciiWhitespace } from "./bytes/reader-CDx_NmAQ.js";
4
- import { ByteWriter, concatBytes } from "./bytes/writer-B9uaqo-B.js";
5
- import { JpegInfo, readJpegInfo } from "./image/jpeg-info-Dh6D8PRh.js";
6
- import { PngDecodeOptions, RawImage, decodePng } from "./image/png-decode-Dvizumot.js";
7
- import { PngEncodeOptions, encodePng } from "./image/png-encode-C5Jj9gBX.js";
8
- import { PngFilterType, filterScanlines, unfilterScanlines } from "./image/png-filter-5L1Q0PDF.js";
9
- export { ByteReader, ByteWriter, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, concatBytes, crc32, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, readJpegInfo, unfilterScanlines };
@@ -1,9 +0,0 @@
1
- import { crc32 } from "./bytes/crc32-BVCBBYa3.cjs";
2
- import { DeflateLevel, InflateResult, MAX_INFLATE_OUTPUT_BYTES, deflate, inflate, inflateTolerant } from "./bytes/flate-CbSD2OU9.cjs";
3
- import { ByteReader, isAsciiWhitespace } from "./bytes/reader-CDx_NmAQ.cjs";
4
- import { ByteWriter, concatBytes } from "./bytes/writer-B9uaqo-B.cjs";
5
- import { JpegInfo, readJpegInfo } from "./image/jpeg-info-Dh6D8PRh.cjs";
6
- import { PngDecodeOptions, RawImage, decodePng } from "./image/png-decode-Dvizumot.cjs";
7
- import { PngEncodeOptions, encodePng } from "./image/png-encode-CpwBOmkg.cjs";
8
- import { PngFilterType, filterScanlines, unfilterScanlines } from "./image/png-filter-5L1Q0PDF.cjs";
9
- export { ByteReader, ByteWriter, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, concatBytes, crc32, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, readJpegInfo, unfilterScanlines };