FXGL icon indicating copy to clipboard operation
FXGL copied to clipboard

Images.kt map() does not check sizes of given images

Open AlmasB opened this issue 5 years ago • 1 comments

In Images.kt file, fun Image.map(overlay: Image, f: (Pixel, Pixel) -> Pixel): Image combines overlay and this to produce a new Image using the function f to map pixels from the two images. The call, as of now, will fail if overlay width or height is smaller than this.

I'm not sure what the expected (most intuitive?) behaviour should be. It appears we have the following options:

  1. Resize overlay to match this
  2. Use overlay "as is", then the returned image size has the highest width / height of the two (e.g. max(this.width, overlay.width)). Non-existent pixels are substituted with transparent color pixels.

Suggestions are welcome.

AlmasB avatar Dec 29 '19 13:12 AlmasB

I think, another option it is to add to map function third parameter (let's say mapType enum), which will define the type of mapping: STRICT - as it is; CENTER - overlay will be applied to center of the image; HORIZONTAL_FILL - overlay will be resized without change of proportions to match width of the image; VERTICAL_FILL - same as horizontal, though with height matching; STRETCH - resize overlay to fully fit the image; STRETCH_PROPORTINAL - resize to fully fit the image, saving proprtions; TILE - tile overlay over image;

well, maybe it is better to have them as different functions.

AahzBrut avatar Aug 03 '20 10:08 AahzBrut