pixel-data-js 0.31.0 → 0.33.0
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/dist/index.prod.cjs +433 -310
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +78 -52
- package/dist/index.prod.js +430 -306
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/ImageData/copyImageData.ts +4 -2
- package/src/ImageData/extractImageData.ts +54 -0
- package/src/ImageData/extractImageDataBuffer.ts +55 -28
- package/src/ImageData/writeImageData.ts +47 -69
- package/src/ImageData/writeImageDataBuffer.ts +77 -41
- package/src/PixelData/extractPixelDataBuffer.ts +51 -40
- package/src/PixelData/fillPixelData.ts +45 -28
- package/src/PixelData/fillPixelDataBinaryMask.ts +43 -38
- package/src/PixelData/fillPixelDataFast.ts +25 -16
- package/src/PixelData/invertPixelData.ts +38 -21
- package/src/PixelData/resizePixelData.ts +75 -0
- package/src/PixelData/writePixelData.ts +55 -0
- package/src/PixelData/writePixelDataBuffer.ts +53 -38
- package/src/index.ts +3 -1
- package/src/Rect/resolveClipping.ts +0 -140
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
export type ClippedRect = {
|
|
2
|
-
x: number
|
|
3
|
-
y: number
|
|
4
|
-
w: number
|
|
5
|
-
h: number
|
|
6
|
-
inBounds: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type ClippedBlit = {
|
|
10
|
-
x: number
|
|
11
|
-
y: number
|
|
12
|
-
sx: number
|
|
13
|
-
sy: number
|
|
14
|
-
w: number
|
|
15
|
-
h: number
|
|
16
|
-
inBounds: boolean
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// use factory functions when creating reusable objects ensure property order for JIT perf
|
|
20
|
-
export const makeClippedRect = (): ClippedRect => ({
|
|
21
|
-
x: 0,
|
|
22
|
-
y: 0,
|
|
23
|
-
w: 0,
|
|
24
|
-
h: 0,
|
|
25
|
-
inBounds: false,
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
export const makeClippedBlit = (): ClippedBlit => ({
|
|
29
|
-
x: 0,
|
|
30
|
-
y: 0,
|
|
31
|
-
sx: 0,
|
|
32
|
-
sy: 0,
|
|
33
|
-
w: 0,
|
|
34
|
-
h: 0,
|
|
35
|
-
inBounds: false,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Calculates the intersection of a target rectangle and a bounding box (usually 0,0 -> width,height).
|
|
40
|
-
* Handles negative offsets by shrinking dimensions.
|
|
41
|
-
*/
|
|
42
|
-
export function resolveRectClipping(
|
|
43
|
-
x: number,
|
|
44
|
-
y: number,
|
|
45
|
-
w: number,
|
|
46
|
-
h: number,
|
|
47
|
-
boundaryW: number,
|
|
48
|
-
boundaryH: number,
|
|
49
|
-
out: ClippedRect,
|
|
50
|
-
): ClippedRect {
|
|
51
|
-
// Destination Clipping (Top/Left)
|
|
52
|
-
if (x < 0) {
|
|
53
|
-
w += x
|
|
54
|
-
x = 0
|
|
55
|
-
}
|
|
56
|
-
if (y < 0) {
|
|
57
|
-
h += y
|
|
58
|
-
y = 0
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Destination Clipping (Bottom/Right)
|
|
62
|
-
const actualW = Math.min(w, boundaryW - x)
|
|
63
|
-
const actualH = Math.min(h, boundaryH - y)
|
|
64
|
-
|
|
65
|
-
if (actualW <= 0 || actualH <= 0) {
|
|
66
|
-
out.inBounds = false
|
|
67
|
-
return out
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
out.x = x
|
|
71
|
-
out.y = y
|
|
72
|
-
out.w = actualW
|
|
73
|
-
out.h = actualH
|
|
74
|
-
out.inBounds = true
|
|
75
|
-
|
|
76
|
-
return out
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Calculates the clipping for transferring data from a Source to a Destination.
|
|
81
|
-
* Handles cases where the source is out of bounds (shifting the destination target)
|
|
82
|
-
* AND cases where the destination is out of bounds (shifting the source target).
|
|
83
|
-
*/
|
|
84
|
-
export function resolveBlitClipping(
|
|
85
|
-
x: number,
|
|
86
|
-
y: number,
|
|
87
|
-
sx: number,
|
|
88
|
-
sy: number,
|
|
89
|
-
w: number,
|
|
90
|
-
h: number,
|
|
91
|
-
dstW: number,
|
|
92
|
-
dstH: number,
|
|
93
|
-
srcW: number,
|
|
94
|
-
srcH: number,
|
|
95
|
-
out: ClippedBlit,
|
|
96
|
-
): ClippedBlit {
|
|
97
|
-
// 1. Source Clipping: If reading from negative source, shift target right and shrink
|
|
98
|
-
if (sx < 0) {
|
|
99
|
-
x -= sx
|
|
100
|
-
w += sx
|
|
101
|
-
sx = 0
|
|
102
|
-
}
|
|
103
|
-
if (sy < 0) {
|
|
104
|
-
y -= sy
|
|
105
|
-
h += sy
|
|
106
|
-
sy = 0
|
|
107
|
-
}
|
|
108
|
-
w = Math.min(w, srcW - sx)
|
|
109
|
-
h = Math.min(h, srcH - sy)
|
|
110
|
-
|
|
111
|
-
// 2. Destination Clipping: If writing to negative dest, shift source right and shrink
|
|
112
|
-
if (x < 0) {
|
|
113
|
-
sx -= x
|
|
114
|
-
w += x
|
|
115
|
-
x = 0
|
|
116
|
-
}
|
|
117
|
-
if (y < 0) {
|
|
118
|
-
sy -= y
|
|
119
|
-
h += y
|
|
120
|
-
y = 0
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const actualW = Math.min(w, dstW - x)
|
|
124
|
-
const actualH = Math.min(h, dstH - y)
|
|
125
|
-
|
|
126
|
-
if (actualW <= 0 || actualH <= 0) {
|
|
127
|
-
out.inBounds = false
|
|
128
|
-
return out
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
out.x = x
|
|
132
|
-
out.y = y
|
|
133
|
-
out.sx = sx
|
|
134
|
-
out.sy = sy
|
|
135
|
-
out.w = actualW
|
|
136
|
-
out.h = actualH
|
|
137
|
-
out.inBounds = true
|
|
138
|
-
|
|
139
|
-
return out
|
|
140
|
-
}
|