@@ -424,41 +424,41 @@ void oilpaint(int height, int width, RGBTRIPLE image[height][width]){
424424 free (copy );
425425}
426426
427- // Pixelate filter
428- void pixelate (int height , int width , RGBTRIPLE image [height ][width ]){
429- int blockSize = 8 ;
430- if (width > 1000 || height > 1000 ) {
431- blockSize = 16 ;
432- } else if (width > 500 || height > 500 ) {
433- blockSize = 12 ;
434- }
435- for (int blockY = 0 ; blockY < height ; blockY += blockSize ){
436- for (int blockX = 0 ; blockX < width ; blockX += blockSize ){
437- int blockEndY = min (blockY + blockSize , height );
438- int blockEndX = min (blockX + blockSize , width );
439-
440- long sumRed = 0 , sumGreen = 0 , sumBlue = 0 ;
441- int pixelCount = 0 ;
442-
443- for (int y = blockY ; y < blockEndY ; y ++ ){
444- for (int x = blockX ; x < blockEndX ; x ++ ){
445- sumRed += image [y ][x ].rgbtRed ;
446- sumGreen += image [y ][x ].rgbtGreen ;
447- sumBlue += image [y ][x ].rgbtBlue ;
448- pixelCount ++ ;
449- }
427+
428+ void spiral (int height , int width , RGBTRIPLE image [height ][width ])
429+ {
430+ RGBTRIPLE (* output )[width ] = calloc (height , width * sizeof (RGBTRIPLE ));
431+ double cx = width / 2.0 ;
432+ double cy = height / 2.0 ;
433+ double max_r = sqrt (cx * cx + cy * cy );
434+ double k = 4.0 ;
435+ for (int y = 0 ;y < height ;y ++ )
436+ {
437+ for (int x = 0 ;x < width ;x ++ )
438+ {
439+ double dx = x - cx ;
440+ double dy = y - cy ;
441+ double r = sqrt (dx * dx + dy * dy );
442+ double theta = atan2 (dy ,dx );
443+ double factor = (max_r - r )/max_r ;
444+ double theta_new = theta + k * factor ;
445+
446+ double x_new = cx + r * cos (theta_new );
447+ double y_new = cy + r * sin (theta_new );
448+
449+ if (x_new >=0 && x_new < width && y_new >=0 && y_new < height )
450+ {
451+ output [y ][x ]= image [(int )y_new ][(int )x_new ];
450452 }
451- uint8_t avgRed = (uint8_t )(sumRed / pixelCount );
452- uint8_t avgGreen = (uint8_t )(sumGreen / pixelCount );
453- uint8_t avgBlue = (uint8_t )(sumBlue / pixelCount );
454-
455- for (int y = blockY ; y < blockEndY ; y ++ ){
456- for (int x = blockX ; x < blockEndX ; x ++ ){
457- image [y ][x ].rgbtRed = avgRed ;
458- image [y ][x ].rgbtGreen = avgGreen ;
459- image [y ][x ].rgbtBlue = avgBlue ;
460- }
453+ else
454+ {
455+ output [y ][x ]= (RGBTRIPLE ){0 , 0 , 0 };
461456 }
462457 }
463458 }
464- }
459+ for (int y = 0 ;y < height ;y ++ )
460+ for (int x = 0 ; x < width ; x ++ )
461+ image [y ][x ] = output [y ][x ];
462+
463+ free (output );
464+ }
0 commit comments