From bdcf7bf13db6fea867d5a40478f7435e8862d9e0 Mon Sep 17 00:00:00 2001 From: darkress <30271678+DarkressX@users.noreply.github.com> Date: Sun, 11 Jun 2023 03:44:10 +0200 Subject: [PATCH] Working slicing --- de/darkress/pixelfood/Main.java | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/de/darkress/pixelfood/Main.java b/de/darkress/pixelfood/Main.java index d5706bb..682d229 100644 --- a/de/darkress/pixelfood/Main.java +++ b/de/darkress/pixelfood/Main.java @@ -57,7 +57,7 @@ class Main return null; } - private static String[] prepareArray(BufferedImage image, int xOffset, int yOffset) { + private static ArrayList prepareArray(BufferedImage image, int xOffset, int yOffset) { int width = image.getWidth(); int height = image.getHeight(); @@ -79,13 +79,26 @@ class Main } } } - String[] payloadArray = new String[pixelArray.size()]; + /*String[] payloadArray = new String[pixelArray.size()]; for(int i = 0; i < payloadArray.length; i++) { payloadArray[i] = pixelArray.get(i); } - return payloadArray; + return payloadArray;*/ + return pixelArray; + } + + public static String[] prepareThreadArray(ArrayList fullArray, int threadNumber, int threadCount) + { + String[] threadArray = new String[fullArray.size()/threadCount]; + int count = 0; + for(int i = (threadNumber*fullArray.size())/threadCount; i < ((threadNumber+1)*fullArray.size())/threadCount; i++) + { + threadArray[count] = fullArray.get(i); + count++; + } + return threadArray; } //Syntax blabla.jar x y Hostname Port Image.png @@ -99,12 +112,13 @@ class Main // Read the PNG file BufferedImage image = processImage(imageName); - String[] pixelArray = prepareArray(image, xOffset, yOffset); + ArrayList fullArray = prepareArray(image, xOffset, yOffset); ArrayList workerList = new ArrayList<>(); for(int i = 0; i < threadCount; i++) { - workerList.add(new Worker(HOSTNAME, PORT, pixelArray)); + String[] threadArray = prepareThreadArray(fullArray, i, threadCount); + workerList.add(new Worker(HOSTNAME, PORT, threadArray)); } for(int i = 0; i < threadCount; i++)