From 00c7b27f54e568ad75910fa827ad8126f31ab284 Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Tue, 3 Sep 2024 15:37:27 +0700 Subject: [PATCH] Fix for #176 by adding a % for brightening images The Image Manipulation models has also been adapted to use it. --- .../Images/models/Image Manipulation.gaml | 4 +-- .../gama/extension/image/ImageOperators.java | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/gama.extension.image/models/Images/models/Image Manipulation.gaml b/gama.extension.image/models/Images/models/Image Manipulation.gaml index cacf49d13c..5961b95009 100644 --- a/gama.extension.image/models/Images/models/Image Manipulation.gaml +++ b/gama.extension.image/models/Images/models/Image Manipulation.gaml @@ -25,8 +25,8 @@ global { do create_agent(((im1 * 0.1) * 10), "(Size / 10) * 10"); do create_agent((im1 rotated_by 90) * 0.5, "Rotation 90° / 2"); do create_agent((im1 rotated_by -33) * 0.7, "Rotation -33° * 0.7"); - do create_agent(darker(darker(im1)), "2 x darker"); - do create_agent(brighter(brighter(im1)), "2 x brighter"); + do create_agent(darker(im1,0.5), "50% darker"); + do create_agent(brighter(im1, 0.5), "50% brighter"); do create_agent((im1 * #lightgreen), "Light green tint"); do create_agent((im1 * #lightskyblue), "Light blue tint"); do create_agent(im1 tinted_with (#red, 0.15), "15% red tint"); diff --git a/gama.extension.image/src/gama/extension/image/ImageOperators.java b/gama.extension.image/src/gama/extension/image/ImageOperators.java index 159d48fb42..36a815e4e8 100644 --- a/gama.extension.image/src/gama/extension/image/ImageOperators.java +++ b/gama.extension.image/src/gama/extension/image/ImageOperators.java @@ -1,7 +1,7 @@ /******************************************************************************************************* * - * ImageOperators.java, in gama.extension.image, is part of the source code of the GAMA modeling and simulation - * platform . + * ImageOperators.java, in gama.extension.image, is part of the source code of the GAMA modeling and simulation platform + * . * * (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU) * @@ -24,13 +24,14 @@ import java.awt.image.RescaleOp; import java.awt.image.WritableRaster; -import gama.annotations.precompiler.IConcept; -import gama.annotations.precompiler.IOperatorCategory; import gama.annotations.precompiler.GamlAnnotations.doc; import gama.annotations.precompiler.GamlAnnotations.example; import gama.annotations.precompiler.GamlAnnotations.no_test; import gama.annotations.precompiler.GamlAnnotations.operator; +import gama.annotations.precompiler.IConcept; +import gama.annotations.precompiler.IOperatorCategory; import gama.core.common.interfaces.IDisplaySurface; +import gama.core.common.interfaces.IKeyword; import gama.core.kernel.experiment.ITopLevelAgent; import gama.core.metamodel.agent.IAgent; import gama.core.metamodel.shape.GamaPoint; @@ -186,7 +187,7 @@ public static GamaImage grayscale(final IScope scope, final GamaImage image) { * the image * @return the gama image */ - @operator ("darker") + @operator (IKeyword.DARKER) @doc ("Used to return an image 10% darker. This operation can be applied multiple times in a row if greater than 10% changes in brightness are desired.") @no_test public static GamaImage darker(final IScope scope, final GamaImage image) { @@ -210,8 +211,8 @@ public static GamaImage darker(final IScope scope, final GamaImage image) { * @return the gama image * @date 15 sept. 2023 */ - @operator ("darker") - @doc ("Used to return an image darker by a percentage (between 0 - no change - and 1 - 100% darker). If the percentage is below zero or abovde 1, returns the image untouched") + @operator (IKeyword.DARKER) + @doc ("Used to return an image darker by a percentage (between 0 - no change - and 1 - 100% darker). If the percentage is below zero or above 1, returns the image untouched") @no_test public static GamaImage darker(final IScope scope, final GamaImage image, final double percentage) { try { @@ -232,7 +233,7 @@ public static GamaImage darker(final IScope scope, final GamaImage image, final * the image * @return the gama image */ - @operator ("brighter") + @operator (IKeyword.BRIGHTER) @doc ("Used to return an image 10% brigther. This operation can be applied multiple times in a row if greater than 10% changes in brightness are desired.") @no_test public static GamaImage brigther(final IScope scope, final GamaImage image) { @@ -243,6 +244,19 @@ public static GamaImage brigther(final IScope scope, final GamaImage image) { } } + @operator (IKeyword.BRIGHTER) + @doc ("Used to return an image brighter by a percentage (between 0 - no change - and 1 - 100% brighter). If the percentage is below zero or above 1, returns the image untouched") + @no_test + public static GamaImage brigther(final IScope scope, final GamaImage image, final double percentage) { + try { + if (percentage < 0 || percentage > 1) return image; + float scale = (float) percentage; + return apply(image, new RescaleOp(1f + scale, 0, HINTS)); + } catch (Exception e) { + return image; + } + } + /** * Antialiased. *