pixel-data-js 0.9.0 → 0.9.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/dist/index.dev.js CHANGED
@@ -2250,6 +2250,84 @@ function invertPixelData(pixelData) {
2250
2250
  }
2251
2251
  return pixelData;
2252
2252
  }
2253
+
2254
+ // src/PixelData/reflectPixelData.ts
2255
+ function reflectPixelDataHorizontal(pixelData) {
2256
+ const width = pixelData.width;
2257
+ const height = pixelData.height;
2258
+ const data = pixelData.data32;
2259
+ const halfWidth = Math.floor(width / 2);
2260
+ for (let y = 0; y < height; y++) {
2261
+ const rowOffset = y * width;
2262
+ for (let x = 0; x < halfWidth; x++) {
2263
+ const leftIdx = rowOffset + x;
2264
+ const rightIdx = rowOffset + (width - 1 - x);
2265
+ const temp = data[leftIdx];
2266
+ data[leftIdx] = data[rightIdx];
2267
+ data[rightIdx] = temp;
2268
+ }
2269
+ }
2270
+ }
2271
+ function reflectPixelDataVertical(pixelData) {
2272
+ const width = pixelData.width;
2273
+ const height = pixelData.height;
2274
+ const data = pixelData.data32;
2275
+ const halfHeight = Math.floor(height / 2);
2276
+ for (let y = 0; y < halfHeight; y++) {
2277
+ const topRowOffset = y * width;
2278
+ const bottomRowOffset = (height - 1 - y) * width;
2279
+ for (let x = 0; x < width; x++) {
2280
+ const topIdx = topRowOffset + x;
2281
+ const bottomIdx = bottomRowOffset + x;
2282
+ const temp = data[topIdx];
2283
+ data[topIdx] = data[bottomIdx];
2284
+ data[bottomIdx] = temp;
2285
+ }
2286
+ }
2287
+ }
2288
+
2289
+ // src/PixelData/rotatePixelData.ts
2290
+ function rotatePixelData(pixelData) {
2291
+ const width = pixelData.width;
2292
+ const height = pixelData.height;
2293
+ const data = pixelData.data32;
2294
+ if (width === height) {
2295
+ rotateSquareInPlace(pixelData);
2296
+ return;
2297
+ }
2298
+ const newWidth = height;
2299
+ const newHeight = width;
2300
+ const newData = new Uint32Array(data.length);
2301
+ for (let y = 0; y < height; y++) {
2302
+ for (let x = 0; x < width; x++) {
2303
+ const oldIdx = y * width + x;
2304
+ const newX = height - 1 - y;
2305
+ const newY = x;
2306
+ const newIdx = newY * newWidth + newX;
2307
+ newData[newIdx] = data[oldIdx];
2308
+ }
2309
+ }
2310
+ pixelData.width = newWidth;
2311
+ pixelData.height = newHeight;
2312
+ pixelData.data32 = newData;
2313
+ }
2314
+ function rotateSquareInPlace(pixelData) {
2315
+ const n = pixelData.width;
2316
+ const data = pixelData.data32;
2317
+ for (let i = 0; i < n / 2; i++) {
2318
+ for (let j = i; j < n - i - 1; j++) {
2319
+ const temp = data[i * n + j];
2320
+ const top = i * n + j;
2321
+ const right = j * n + (n - 1 - i);
2322
+ const bottom = (n - 1 - i) * n + (n - 1 - j);
2323
+ const left = (n - 1 - j) * n + i;
2324
+ data[top] = data[left];
2325
+ data[left] = data[bottom];
2326
+ data[bottom] = data[right];
2327
+ data[right] = temp;
2328
+ }
2329
+ }
2330
+ }
2253
2331
  export {
2254
2332
  BlendMode,
2255
2333
  FAST_BLENDER_REGISTRY,
@@ -2342,7 +2420,10 @@ export {
2342
2420
  pinLightFast,
2343
2421
  pinLightPerfect,
2344
2422
  pixelDataToAlphaMask,
2423
+ reflectPixelDataHorizontal,
2424
+ reflectPixelDataVertical,
2345
2425
  resizeImageData,
2426
+ rotatePixelData,
2346
2427
  screenFast,
2347
2428
  screenPerfect,
2348
2429
  serializeImageData,