-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDEV-5286 add function ImageGetPoint
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
source/java/src/org/lucee/extension/image/functions/ImageGetPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.lucee.extension.image.functions; | ||
|
||
import java.awt.Color; | ||
import java.awt.image.BufferedImage; | ||
|
||
import lucee.runtime.PageContext; | ||
import lucee.runtime.exp.PageException; | ||
import lucee.runtime.type.Struct; | ||
|
||
import org.lucee.extension.image.Image; | ||
|
||
public class ImageGetPoint extends FunctionSupport { | ||
|
||
public static Struct call(PageContext pc, Object name, double x, double y) throws PageException { | ||
Image img = Image.toImage(pc,name); | ||
BufferedImage bi = img.getBufferedImage(); | ||
|
||
Struct pixel = eng.getCreationUtil().createStruct(); | ||
Color color = new Color( bi.getRGB( (int)x, (int)y ) ); | ||
pixel.setEL("x", x); | ||
pixel.setEL("y", y); | ||
pixel.setEL("red", color.getRed()); | ||
pixel.setEL("blue", color.getBlue()); | ||
pixel.setEL("green", color.getGreen()); | ||
pixel.setEL("alpha", color.getAlpha()); | ||
pixel.setEL("hex", "#"+Integer.toHexString(color.getRGB()).substring(2)); | ||
return pixel; | ||
} | ||
|
||
@Override | ||
public Object invoke(PageContext pc, Object[] args) throws PageException { | ||
if(args.length==3) return call(pc, args[0],cast.toDoubleValue(args[1]),cast.toDoubleValue(args[2])); | ||
throw exp.createFunctionException(pc, "ImageGetPoint", 3, 3, args.length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
component extends="org.lucee.cfml.test.LuceeTestCase" labels="image2" { | ||
|
||
function run( testResults, testBox ){ | ||
describe( "test case for ImageDrawPoint", function() { | ||
|
||
it(title = "Checking with ImageDrawOval", body = function( currentSpec ){ | ||
var img = imageNew("",200,200,"rgb","red"); | ||
imageSetDrawingColor(img, "white"); | ||
checkPoint( img, 90, 90, "red" ); | ||
|
||
imageDrawPoint( img, 90, 90 ); | ||
checkPoint( img, 90, 90, "white" ); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
private function checkPoint( img, x, y, color ){ | ||
var pixel = img.getPoint( x, y ); | ||
var pixel2 = ImageGetPoint( img, x, y ); | ||
|
||
structEach( pixel, function( k, v ) { | ||
expect( pixel[ k ] ).toBe( pixel2[ k ] ); | ||
}); | ||
|
||
if (color eq "white"){ | ||
expect( pixel.red ).toBe( 255 ); | ||
expect( pixel.blue ).toBe( 255 ); | ||
expect( pixel.green ).toBe( 255 ); | ||
expect( pixel.hex ).toBe( "##ffffff" ); | ||
} else { | ||
expect( pixel.red ).toBe( 255 ); | ||
expect( pixel.blue ).toBe( 0 ); | ||
expect( pixel.green ).toBe( 0 ); | ||
expect( pixel.hex ).toBe( "##ff0000" ); | ||
} | ||
} | ||
|
||
} | ||
|