Skip to content

Commit

Permalink
Merge pull request #311 from gama-platform/Addresses-#176
Browse files Browse the repository at this point in the history
  • Loading branch information
lesquoyb committed Sep 5, 2024
2 parents 771e2cd + 00c7b27 commit 3e1d3d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
30 changes: 22 additions & 8 deletions gama.extension.image/src/gama/extension/image/ImageOperators.java
Original file line number Diff line number Diff line change
@@ -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)
*
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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.
*
Expand Down

0 comments on commit 3e1d3d0

Please sign in to comment.