import{ImageFilter}from"./image-filter.mjs";function performPixelize(image){const topLeftY=this.thread.y-this.thread.y%this.constants.size;const topLeftX=this.thread.x-this.thread.x%this.constants.size;let pixel=[0,0,0];let sampleCount=1;for(let i=0;i<this.constants.size;i++){for(let j=0;j<this.constants.size;j++){const sampleY=topLeftY+i;const sampleX=topLeftX+j;if(sampleY>=this.constants.height||sampleX>=this.constants.width){continue}const pixelValue=image[sampleY][sampleX];pixel[0]=pixel[0]+pixelValue[0];pixel[1]=pixel[1]+pixelValue[1];pixel[2]=pixel[2]+pixelValue[2];sampleCount=sampleCount+1}}pixel[0]=pixel[0]/sampleCount;pixel[1]=pixel[1]/sampleCount;pixel[2]=pixel[2]/sampleCount;this.color(pixel[0],pixel[1],pixel[2],1)}class ImagePixelizeFilter extends ImageFilter{static filterFunction=performPixelize;reset(execute=true){super.reset(false);this.constants.size=3;if(execute){this.execute()}}setConstants(constants,execute=true){this.constants.size=parseInt(constants.size===undefined?this.constants.size:constants.size);if(execute){this.execute()}}set size(newSize){this.constants.size=parseInt(newSize);this.execute()}}export{ImagePixelizeFilter};
