diff --git a/backend/src/main/java/pdl/backend/Controller/AlgorithmController.java b/backend/src/main/java/pdl/backend/Controller/AlgorithmController.java index dcbf169..73fddee 100644 --- a/backend/src/main/java/pdl/backend/Controller/AlgorithmController.java +++ b/backend/src/main/java/pdl/backend/Controller/AlgorithmController.java @@ -29,7 +29,7 @@ public class AlgorithmController { private ObjectMapper mapper; public static List algorithmList() { - final String[] borderTypes = { "SKIP", "ZERO", "NORMALIZED", "REFLECT", "EXTEND", "WRAP" }; + final String[] borderTypes = { "SKIP", "ZERO", "NORMALIZED", "REFLECT", "EXTENDED", "WRAP" }; ArrayList algorithms = new ArrayList(); algorithms.add(new Algorithm("Changement de luminosité", "changeLuminosity", Arrays.asList(new IntegerParameter("delta", "delta", -255, 255, 1)), diff --git a/backend/src/main/java/pdl/backend/Controller/ImageController.java b/backend/src/main/java/pdl/backend/Controller/ImageController.java index 38fd6d3..4121894 100644 --- a/backend/src/main/java/pdl/backend/Controller/ImageController.java +++ b/backend/src/main/java/pdl/backend/Controller/ImageController.java @@ -202,9 +202,17 @@ public class ImageController { if (!parameters.containsKey(p.getName())) { return JSONError("Parameter '" + p.getName() + "' is missing", HttpStatus.BAD_REQUEST); } - p.setValue(parameters.get(p.getName())); + try { + p.setValue(parameters.get(p.getName())); + } catch (Exception e) { + return JSONError("Parameter '" + p.getName() + "' is invalid", HttpStatus.BAD_REQUEST); + } + } + try { + a.apply(input); + } catch (Exception e) { + return JSONError("There was an internal server error", HttpStatus.INTERNAL_SERVER_ERROR); } - a.apply(input); break; } } diff --git a/backend/src/main/java/pdl/backend/Image/ImageProcessing.java b/backend/src/main/java/pdl/backend/Image/ImageProcessing.java index 1abada9..0a8f610 100644 --- a/backend/src/main/java/pdl/backend/Image/ImageProcessing.java +++ b/backend/src/main/java/pdl/backend/Image/ImageProcessing.java @@ -295,7 +295,6 @@ public final class ImageProcessing { * @param borderType type de bord à utiliser pour la convolution */ public static void meanFilter(Planar input, int size, BorderType borderType) { - Planar output = input.createSameShape(); // Vérification que la taille est impaire if (size % 2 == 0 || size < 0) { throw new IllegalArgumentException( @@ -308,12 +307,6 @@ public final class ImageProcessing { } } convolution(input, kernel, borderType); - for (int i = 0; i < input.width; i++) { - for (int j = 0; j < input.height; j++) { - int[] rgb = getRGBValue(output, i, j); - setRGBValue(input, i, j, rgb); - } - } } /** @@ -327,7 +320,6 @@ public final class ImageProcessing { * @param borderType Le type de bord à utiliser pour la convolution */ public static void gaussienFilter(Planar input, int size, double sigma, BorderType borderType) { - Planar output = input.createSameShape(); if (size % 2 == 0 || size < 0 || sigma <= 0) { throw new IllegalArgumentException( "La taille doit être impaire et positive et sigma doit être strictement positif"); @@ -364,13 +356,6 @@ public final class ImageProcessing { } } convolution(input, kernelInt, borderType); - // copy all output pixels to input - for (int i = 0; i < input.width; i++) { - for (int j = 0; j < input.height; j++) { - int[] rgb = getRGBValue(output, i, j); - setRGBValue(input, i, j, rgb); - } - } } /** @@ -383,7 +368,7 @@ public final class ImageProcessing { * @param borderType Le type de bord à utiliser pour la convolution */ public static void convolution(Planar input, int[][] kernel, BorderType borderType) { - Planar output = input.createSameShape(); + Planar copy = input.clone(); int size = kernel.length; int half = kernel.length / 2; int coefs = 0; @@ -401,9 +386,9 @@ public final class ImageProcessing { if (y < half || x < half || y >= input.height - half || x >= input.width - half) { if (borderType == BorderType.SKIP) { - setRGBValue(output, x, y, getRGBValue(input, x, y)); + setRGBValue(input, x, y, getRGBValue(copy, x, y)); } else if (borderType == BorderType.ZERO) { - setRGBValue(output, x, y, new int[] { 0, 0, 0 }); + setRGBValue(input, x, y, new int[] { 0, 0, 0 }); } else { int totalValue[] = new int[3]; int coefsUsed = 0; @@ -434,8 +419,7 @@ public final class ImageProcessing { } } for (int k = 0; k < totalValue.length; k++) { - totalValue[k] += input.getBand(k).get(tmpi, tmpj) - * kernel[tmpi][tmpj]; + totalValue[k] += copy.getBand(k).get(tmpi, tmpj) * kernel[tmpi][tmpj]; } coefsUsed += kernel[tmpi][tmpj]; } @@ -454,7 +438,7 @@ public final class ImageProcessing { for (int j = y - half; j <= y + half; j++) { for (int i = x - half; i <= x + half; i++) { for (int k = 0; k < totalValue.length; k++) { - totalValue[k] += input.getBand(k).get(i, j) * kernel[currentJ][currentI]; + totalValue[k] += copy.getBand(k).get(i, j) * kernel[currentJ][currentI]; } currentI++; } @@ -464,14 +448,8 @@ public final class ImageProcessing { for (int k = 0; k < totalValue.length; k++) { totalValue[k] /= totalCoefs; } - setRGBValue(output, x, y, totalValue); + setRGBValue(input, x, y, totalValue); } }); - for (int i = 0; i < input.width; i++) { - for (int j = 0; j < input.height; j++) { - int[] rgb = getRGBValue(output, i, j); - setRGBValue(input, i, j, rgb); - } - } } } diff --git a/frontend/src/components/Home.vue b/frontend/src/components/Home.vue index 4e1c6a7..49d40ad 100644 --- a/frontend/src/components/Home.vue +++ b/frontend/src/components/Home.vue @@ -112,10 +112,8 @@ html { } :deep(.imageContainer) { - max-width: 60%; - width: auto; - height: auto; - max-height: 60vh; + max-width: min(60vh, 60vw); + max-height: min(60vh, 60vw); transform: none; } diff --git a/frontend/src/components/HomeEditor.vue b/frontend/src/components/HomeEditor.vue index 502e24f..09ce47e 100644 --- a/frontend/src/components/HomeEditor.vue +++ b/frontend/src/components/HomeEditor.vue @@ -29,11 +29,11 @@ export default defineComponent({ for (const arg of filter.parameters) { if (arg.type === FilterType.range) { const range = arg as RangeParameters; - range.value = (range.max - Math.abs(range.min)) / 2; + range.value = range.min; } else if (arg.type === FilterType.select) { const select = arg as SelectParameters; - select.value = 0; + select.value = select.options[0]; } } } @@ -94,12 +94,13 @@ export default defineComponent({ :step="(parameter as RangeParameters).step" v-model.number="parameter.value" :id="parameter.name" /> + :step="(parameter as RangeParameters).step" v-model.number="(parameter as RangeParameters).value" />
- +