canvas-editor-engine 1.1.17 → 1.1.18

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.
@@ -6,6 +6,7 @@ export default class VagueFilter extends Filter {
6
6
  constructor(ctx: CanvasRenderingContext2D, options: IImageOptions);
7
7
  on(action: TFilterMethod, filterOptions: IFilterOptions): Promise<IImageLoggingDataVague>;
8
8
  pixel(imageData: ImageData, filterOptions: IFilterOptions): ImageData;
9
+ private getQualityProcessedRemainder;
9
10
  private getQualityBuff;
10
11
  private getMostCommonQuanlityBuff;
11
12
  private getMostCommonElement;
@@ -31,15 +31,16 @@ class VagueFilter extends filter_1.Filter {
31
31
  });
32
32
  }
33
33
  pixel(imageData, filterOptions) {
34
+ const { quality } = filterOptions;
35
+ console.log('quality', quality);
36
+ const processedImageData = this.getQualityProcessedRemainder(imageData, +quality);
34
37
  const imageSize = {
35
- width: imageData.width,
36
- height: imageData.height,
38
+ width: processedImageData.width,
39
+ height: processedImageData.height,
37
40
  };
38
41
  console.log('imageSize', imageSize);
39
42
  this.setImageSize(imageSize);
40
- const { quality } = filterOptions;
41
- console.log('quality', quality);
42
- const { rowRGBABuff, buff } = this.getBuffCollection(imageData);
43
+ const { rowRGBABuff, buff } = this.getBuffCollection(processedImageData);
43
44
  const { qualityBuff, rangeCommit } = this.getQualityBuff(buff, +quality);
44
45
  const qualityBuffWithMostCommonElement = this.getMostCommonQuanlityBuff(qualityBuff, rangeCommit);
45
46
  const rowQualityBuffWithMostCommonElement = qualityBuffWithMostCommonElement.flat();
@@ -51,11 +52,36 @@ class VagueFilter extends filter_1.Filter {
51
52
  });
52
53
  const rowBuff = occurrenceRGBAbuff.flat();
53
54
  rowBuff.forEach((color, index) => {
54
- imageData.data[index] = color;
55
+ processedImageData.data[index] = color;
55
56
  });
56
- console.log('imageData', imageData);
57
57
  }
58
- return imageData;
58
+ return processedImageData;
59
+ }
60
+ getQualityProcessedRemainder(imageData, quality) {
61
+ const rowRGBABuff = this.getRowRGBABuff(imageData);
62
+ const RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, { width: imageData.width, height: imageData.height });
63
+ const cqx = quality - (imageData.width % quality);
64
+ const cqy = quality - (imageData.height % quality);
65
+ const xCommit = (0, lodash_1.range)(0, cqx);
66
+ const yCommit = (0, lodash_1.range)(0, cqy);
67
+ const tempSize = {
68
+ width: imageData.width + cqx,
69
+ height: imageData.height + cqy,
70
+ };
71
+ const xLastIndex = RGBAMatrix[0].length - 1;
72
+ RGBAMatrix.forEach((row, y) => {
73
+ const xLastRGBAByte = row[xLastIndex];
74
+ xCommit.forEach(() => RGBAMatrix[y].push(xLastRGBAByte));
75
+ });
76
+ const yLastIndex = RGBAMatrix.length - 1;
77
+ const yLastRGBARow = RGBAMatrix[yLastIndex];
78
+ yCommit.forEach(() => RGBAMatrix.push(yLastRGBARow));
79
+ const buffWithRemainder = RGBAMatrix.flat(2);
80
+ const tempCanvas = document.createElement('canvas');
81
+ const tempCtx = tempCanvas.getContext('2d');
82
+ const tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
83
+ buffWithRemainder.forEach((_, i) => tempImageData.data[i] = buffWithRemainder[i]);
84
+ return tempImageData;
59
85
  }
60
86
  getQualityBuff(buff, quality) {
61
87
  const wq = Math.floor(this.imageSize.width / quality);
@@ -1,5 +1,5 @@
1
1
  import { IExtendedImageDataModel, type IImageOptions, type IImageSize, type TBuff, type TRGBABuff } from "../types/image";
2
- import type { ISize } from '../types/general';
2
+ import type { ISize, THEXColor } from '../types/general';
3
3
  export declare class Filter {
4
4
  ctx: CanvasRenderingContext2D;
5
5
  imageSize: IImageSize;
@@ -15,7 +15,7 @@ export declare class Filter {
15
15
  hexBuff: `#${string}`[];
16
16
  buff: TBuff<string>;
17
17
  };
18
- private getBuff;
19
- private getRGBAMatrix;
20
- private getRowRGBABuff;
18
+ getBuff(hexBuff: THEXColor[]): TBuff<string>;
19
+ getRGBAMatrix(rowRGBABuff: TRGBABuff, size?: ISize): TBuff<number[]>;
20
+ getRowRGBABuff(imageData: ImageData): TRGBABuff;
21
21
  }
@@ -54,7 +54,7 @@ class Filter {
54
54
  };
55
55
  }
56
56
  getSizeOfSparseMatrix(RGBAMatrix, tempSize) {
57
- // case 1: Xcanvas -> Ximage && case 3: Ycanvas -> Yimage
57
+ // case 1: Xcanvas -> Ximage && Ycanvas -> Yimage
58
58
  let leftIndex;
59
59
  let upIndex;
60
60
  for (const [iy, row] of RGBAMatrix.entries()) {
@@ -70,9 +70,7 @@ class Filter {
70
70
  break;
71
71
  }
72
72
  }
73
- console.log('case 1: Xcanvas -> Ximage; leftIndex:', leftIndex);
74
- console.log('case 3: Ycanvas -> Yimage; upIndex:', upIndex);
75
- // case 2: Ximage <- Xcanvas && case 4: Yimage <- Ycanvas
73
+ // case 2 reverse matrix: Ximage <- Xcanvas && Yimage <- Ycanvas
76
74
  let rightIndex;
77
75
  let downIndex;
78
76
  for (const [iy, row] of RGBAMatrix.reverse().entries()) {
@@ -88,8 +86,6 @@ class Filter {
88
86
  break;
89
87
  }
90
88
  }
91
- console.log('case 2: Ximage <- Xcanvas; rightIndex:', rightIndex);
92
- console.log('case 4: Yimage <- Ycanvas; downIndex:', downIndex);
93
89
  const reduceWidth = (tempWidth) => tempWidth - (leftIndex + rightIndex);
94
90
  const reduceHeight = (tempHeight) => tempHeight - (upIndex + downIndex);
95
91
  const resultSize = {
@@ -117,7 +113,7 @@ class Filter {
117
113
  });
118
114
  return buff;
119
115
  }
120
- getRGBAMatrix(RGBABuff, size) {
116
+ getRGBAMatrix(rowRGBABuff, size) {
121
117
  const maybeSize = {
122
118
  width: size.width || this.imageSize.width,
123
119
  height: size.height || this.imageSize.height,
@@ -125,7 +121,7 @@ class Filter {
125
121
  const distanceRow = (0, lodash_1.range)(0, maybeSize.height).map((i) => maybeSize.width * i);
126
122
  const buff = [];
127
123
  let indexOfDistance = 0;
128
- RGBABuff.forEach((pxRGBA, pxIndex) => {
124
+ rowRGBABuff.forEach((pxRGBA, pxIndex) => {
129
125
  if (pxIndex >= distanceRow[indexOfDistance + 1]) {
130
126
  indexOfDistance++;
131
127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",