├── README.md ├── car.jpg ├── car2.jpeg ├── src ├── main │ └── java │ │ └── org │ │ └── rinmakh │ │ ├── byteshift │ │ └── ByteMaskRun.java │ │ ├── paralel │ │ └── imegefilter │ │ │ ├── WriteImage.java │ │ │ ├── ReadImage.java │ │ │ ├── HorizontalWorkStream.java │ │ │ ├── ARGB.java │ │ │ ├── PixelWork.java │ │ │ └── Application.java │ │ └── simplservice │ │ └── ServiceMain.java └── test │ └── java │ └── SimpleTest.java └── pom.xml /README.md: -------------------------------------------------------------------------------- 1 | # ImageFilter 2 | simple project for testing various tools 3 | -------------------------------------------------------------------------------- /car.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stalk/ImageFilter/master/car.jpg -------------------------------------------------------------------------------- /car2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stalk/ImageFilter/master/car2.jpeg -------------------------------------------------------------------------------- /src/main/java/org/rinmakh/byteshift/ByteMaskRun.java: -------------------------------------------------------------------------------- 1 | package org.rinmakh.byteshift; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * @author Rinat_Makhmutov 7 | */ 8 | public class ByteMaskRun { 9 | 10 | public static void main(String[] args) throws CloneNotSupportedException { 11 | 12 | 13 | 14 | 15 | } 16 | 17 | 18 | 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/org/rinmakh/paralel/imegefilter/WriteImage.java: -------------------------------------------------------------------------------- 1 | package org.rinmakh.paralel.imegefilter; 2 | 3 | import javax.imageio.ImageIO; 4 | import java.awt.image.BufferedImage; 5 | import java.io.File; 6 | import java.io.IOException; 7 | 8 | /** 9 | * @author Rinat_Makhmutov 10 | */ 11 | public class WriteImage { 12 | 13 | public static void save(BufferedImage image) throws IOException { 14 | File out = new File("D:\\Projects\\ImageFilter\\carResult.jpg"); 15 | ImageIO.write(image,"jpg",out); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/rinmakh/paralel/imegefilter/ReadImage.java: -------------------------------------------------------------------------------- 1 | package org.rinmakh.paralel.imegefilter; 2 | 3 | 4 | import javax.imageio.ImageIO; 5 | import java.awt.image.BufferedImage; 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | /** 10 | * @author Rinat_Makhmutov 11 | */ 12 | public class ReadImage { 13 | 14 | public static BufferedImage read(String path) throws IOException { 15 | File f = new File(path); 16 | BufferedImage bi = ImageIO.read(f); 17 | return bi; 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/SimpleTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertFalse; 5 | import static org.junit.Assert.assertNotEquals; 6 | 7 | /** 8 | * @author Rinat_Makhmutov 9 | */ 10 | 11 | 12 | public class SimpleTest { 13 | 14 | @Test 15 | public void test1(){ 16 | assertEquals(true,true); 17 | } 18 | 19 | @Test 20 | public void test2(){ 21 | assertNotEquals(true,false); 22 | } 23 | 24 | @Test 25 | public void test3(){ 26 | assertFalse("It must be false!", false); 27 | } 28 | 29 | @Test 30 | public void test4() {} 31 | 32 | @Test 33 | public void test5() {} 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/rinmakh/paralel/imegefilter/HorizontalWorkStream.java: -------------------------------------------------------------------------------- 1 | package org.rinmakh.paralel.imegefilter; 2 | 3 | import java.awt.image.BufferedImage; 4 | 5 | /** 6 | * @author Rinat_Makhmutov 7 | */ 8 | public class HorizontalWorkStream implements Runnable { 9 | 10 | private int Y_LINE; 11 | private BufferedImage result; 12 | private BufferedImage source; 13 | 14 | public HorizontalWorkStream(int y_LINE, BufferedImage source, BufferedImage result) { 15 | Y_LINE = y_LINE; 16 | this.result = result; 17 | this.source = source; 18 | } 19 | 20 | public void run() { 21 | for(int x = 0; x 2 | 5 | 4.0.0 6 | 7 | org.rinmakh.paralel 8 | image-filter 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | 15 | org.springframework 16 | spring-context 17 | 4.3.6.RELEASE 18 | 19 | 20 | 21 | junit 22 | junit 23 | 4.12 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/org/rinmakh/paralel/imegefilter/ARGB.java: -------------------------------------------------------------------------------- 1 | package org.rinmakh.paralel.imegefilter; 2 | 3 | /** 4 | * @author Rinat_Makhmutov 5 | */ 6 | public class ARGB { 7 | 8 | int a, r, g, b; 9 | 10 | public ARGB(int p) { 11 | a = (p >> 24) & 0xff; 12 | r = (p >> 16) & 0xff; 13 | g = (p >> 8) & 0xff; 14 | b = (p & 0xff); 15 | } 16 | 17 | public ARGB() { 18 | a = b = r = g = 0; 19 | } 20 | 21 | public int pixel() { 22 | return ((a << 24) | (r << 16) | (g << 8) | (b << 0)); 23 | } 24 | 25 | public void summarize(ARGB pixel) { 26 | // a = (a + pixel.a); 27 | r = (r + pixel.r); 28 | g = (g + pixel.g); 29 | b = (b + pixel.b); 30 | } 31 | 32 | public void average(int devisor) { 33 | // a = a / devisor; 34 | r = r / devisor; 35 | g = g / devisor; 36 | b = b / devisor; 37 | r = (r > 255) ? 255 : r; 38 | g = (g > 255) ? 255 : g; 39 | b = (b > 255) ? 255 : b; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/rinmakh/paralel/imegefilter/PixelWork.java: -------------------------------------------------------------------------------- 1 | package org.rinmakh.paralel.imegefilter; 2 | 3 | import java.awt.image.BufferedImage; 4 | 5 | /** 6 | * @author Rinat_Makhmutov 7 | */ 8 | public class PixelWork { 9 | 10 | public static int MAX_X; 11 | public static int MAX_Y; 12 | 13 | public static int calculatePixel(int x, int y, int radius, BufferedImage bi) { 14 | ARGB rezult = new ARGB(bi.getRGB(x, y)); 15 | int count = 0; 16 | 17 | ARGB tp; 18 | 19 | for (int xt = x - radius; xt < x + radius; xt++) { 20 | if (xt >= 0 && xt < MAX_X && xt != x) { 21 | for (int yt = y - radius; yt < y + radius; yt++) { 22 | if (yt >= 0 && yt < MAX_Y && yt != y) { 23 | tp = new ARGB(bi.getRGB(xt, yt)); 24 | rezult.summarize(tp); 25 | count++; 26 | } 27 | } 28 | } 29 | } 30 | 31 | rezult.average(count); 32 | return rezult.pixel(); 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/rinmakh/paralel/imegefilter/Application.java: -------------------------------------------------------------------------------- 1 | package org.rinmakh.paralel.imegefilter; 2 | 3 | 4 | import java.awt.image.BufferedImage; 5 | import java.io.IOException; 6 | import java.util.concurrent.ExecutorService; 7 | import java.util.concurrent.Executors; 8 | 9 | /** 10 | * @author Rinat_Makhmutov 11 | */ 12 | public class Application { 13 | 14 | private static String PATH = "D:\\Projects\\ImageFilter\\car2.jpeg"; 15 | 16 | public static void main(String[] args) throws IOException, InterruptedException { 17 | 18 | System.out.println("Start!!!!"); 19 | 20 | BufferedImage bi = ReadImage.read(PATH); 21 | PixelWork.MAX_X = bi.getWidth(); 22 | PixelWork.MAX_Y = bi.getHeight(); 23 | BufferedImage result = new BufferedImage(PixelWork.MAX_X,PixelWork.MAX_Y, bi.getType()); 24 | 25 | ExecutorService executors = Executors.newFixedThreadPool(100); 26 | for(int y=0; y< PixelWork.MAX_Y; y++){ 27 | executors.submit(new HorizontalWorkStream(y,bi,result)); 28 | } 29 | 30 | executors.shutdown(); 31 | while ( !executors.isTerminated()){ 32 | Thread.sleep(1000); 33 | } 34 | 35 | WriteImage.save(result); 36 | 37 | 38 | System.out.println("END!!!!"); 39 | 40 | 41 | } 42 | } 43 | --------------------------------------------------------------------------------