canvas-editor-engine 1.1.5 → 1.1.7

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.
@@ -18,7 +18,7 @@ export interface IImageSize extends ISize {
18
18
  }
19
19
  export type TRGBABuff = TByteRGBColor[];
20
20
  export type TByteRGBColor = [number, number, number, number];
21
- export type TBuff = TStringMatrix;
21
+ export type TBuff<T> = T[][];
22
22
  export type TQualityBuff = TStringMatrix;
23
23
  export type TRangeCommit = IPixelPosition[][];
24
24
  export type TFilterMethod = 'pixel';
@@ -1,5 +1,4 @@
1
- import type { IImageOptions, IImageSize, TRGBABuff } from "../types/image";
2
- import type { TStringMatrix } from '../types/general';
1
+ import type { IImageOptions, IImageSize, TBuff, TRGBABuff } from "../types/image";
3
2
  export declare class Filter {
4
3
  ctx: CanvasRenderingContext2D;
5
4
  imageSize: IImageSize;
@@ -11,8 +10,9 @@ export declare class Filter {
11
10
  getBuffCollection(imageData: ImageData): {
12
11
  rowRGBABuff: TRGBABuff;
13
12
  hexBuff: `#${string}`[];
14
- buff: TStringMatrix;
13
+ buff: TBuff<string>;
15
14
  };
16
15
  private getBuff;
16
+ private getRGBAMatrix;
17
17
  private getRowRGBABuff;
18
18
  }
@@ -17,7 +17,7 @@ class Filter {
17
17
  const width = (options?.width) ? options.width : config_1.default.CANVAS_SIZE.width;
18
18
  const height = (options?.height) ? options.height : config_1.default.CANVAS_SIZE.height;
19
19
  const imgData = this.ctx.getImageData(options.x, options.y, width, height);
20
- this.clearEmptyPixels(imgData);
20
+ const clearedImageData = this.clearEmptyPixels(imgData);
21
21
  return imgData;
22
22
  }
23
23
  update(imgData, options) {
@@ -26,11 +26,44 @@ class Filter {
26
26
  }
27
27
  clearEmptyPixels(imageData) {
28
28
  const rowRGBABuff = this.getRowRGBABuff(imageData);
29
- const cleared = rowRGBABuff.filter((byteArray) => {
30
- const a = byteArray[3];
31
- return !!a;
32
- });
33
- console.log('cleared', cleared);
29
+ const RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, { width: imageData.width, height: imageData.height });
30
+ const tempSize = {
31
+ width: imageData.width,
32
+ height: imageData.height,
33
+ };
34
+ ;
35
+ // case 1: Xcanvas -> Ximage
36
+ let leftIndex;
37
+ for (const [iy, row] of RGBAMatrix.entries()) {
38
+ for (const [ix, rowItem] of row.entries()) {
39
+ const isNotEmpty = rowItem[3 /* E_RGBA.a */] !== 0;
40
+ if (isNotEmpty) {
41
+ leftIndex = ix;
42
+ break;
43
+ }
44
+ }
45
+ if (leftIndex !== undefined) {
46
+ break;
47
+ }
48
+ }
49
+ console.log('case 1: Xcanvas -> Ximage; leftIndex:', leftIndex);
50
+ // case 2: Ximage <- Xcanvas
51
+ let rightIndex;
52
+ // case 3: Ycanvas -> Yimage
53
+ let upIndex;
54
+ // case 4: Yimage <- Ycanvas
55
+ let downIndex;
56
+ // const cleared = rowRGBABuff.filter((byteArray) => {
57
+ // const alpha = byteArray[E_RGBA.a];
58
+ // return !!alpha;
59
+ // });
60
+ // const clearedBuff = cleared.flat();
61
+ // const tempCanvas = document.createElement('canvas');
62
+ // const tempCtx = tempCanvas.getContext('2d');
63
+ // const tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
64
+ // clearedBuff.forEach((_, i) => tempImageData.data[i] = clearedBuff[i]);
65
+ // console.log('cleared', cleared);
66
+ // return tempImageData;
34
67
  }
35
68
  getBuffCollection(imageData) {
36
69
  const rowRGBABuff = this.getRowRGBABuff(imageData);
@@ -51,6 +84,23 @@ class Filter {
51
84
  });
52
85
  return buff;
53
86
  }
87
+ getRGBAMatrix(RGBABuff, size) {
88
+ const maybeSize = {
89
+ width: size.width || this.imageSize.width,
90
+ height: size.height || this.imageSize.height,
91
+ };
92
+ const distanceRow = (0, lodash_1.range)(0, maybeSize.height).map((i) => maybeSize.width * i);
93
+ const buff = [];
94
+ let indexOfDistance = 0;
95
+ RGBABuff.forEach((pxRGBA, pxIndex) => {
96
+ if (pxIndex >= distanceRow[indexOfDistance + 1]) {
97
+ indexOfDistance++;
98
+ }
99
+ buff[indexOfDistance] ??= [];
100
+ buff[indexOfDistance].push(pxRGBA);
101
+ });
102
+ return buff;
103
+ }
54
104
  getRowRGBABuff(imageData) {
55
105
  const rowRGBABuff = []; // [ [0, 0, 0, 0], [0, 0, 0, 0], ... ]
56
106
  let colorIndx = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",