Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Problems with nearest-neighbor scaling?

A topic by Robot Face created Jul 18, 2024 Views: 209 Replies: 5
Viewing posts 1 to 3
(2 edits)

I'm trying to make a tool to create custom trading cards from a template. I'm pretty much done, but when exporting a card, I'd like to scale it by 3x to make it a more useful size. When I do this (a simple a.scale[3]), the whole image itself is the correct size, but it doesn't scale evenly. Some columns and rows are 4 pixels wide and some are 2. It looks ugly. 

Also, this isn't nearly as important and is probably actually intended behavior: if there are patterns besides 0/32 and 1 in the art field, they export at their original resolution when scaled up, i.e. their pixels are 1/3 the size of the rest of the card's pixels.

Developer(+1)

I'm not observing the problem you describe with `canvas.scale[]`; Are you using native-decker, or web-decker? Can you provide a minimal example which reproduces the issue?

The 1-bit patterns are "logical colors" and are intended to remain the same when images are stretched/rotated/translated. If you have an image with these patterns on a Canvas widget and you wish to "flatten" them to patterns 0/1, you can use `canvas.invert[]`. Note that this is much more complicated if an image also contains animated patterns and/or color: see the implementation of the pdf module for a more complete solution: https://github.com/JohnEarnest/Decker/blob/main/examples/decks/pdf.deck#L186-L198

It happens on native-decker for windows and on web-decker. I'm not at my computer right now, I can strip my project down to a minimal example later today. It's not a canvas which I'm scaling, it's an image interface created by app.render[], if that's relevant.

Actually, the version I have up on itch already is pretty minimal if you ignore everything except the "Save card as image" button. If you want to look at it it's https://robotface.itch.io/btcg-card-maker , I set it so you can see it with the password "decker"

Check the v character in the "Level" label in the top left of the card, for example

If you still want a minimal example I can provide that later today

Okay, I uploaded a minimal example as "example.deck" at the link I gave you, and I think I also figured out maybe why you weren't seeing it: the artifacts appear at some resolutions and not others. I tried reproducing it with a small canvas, but it worked fine until I made the canvas the same size as my card template.

Developer(+2)

I've managed to reproduce several specimens of the problem, and I've made tweaks to Decker's image scaling algorithm to avoid distortion with integral upscales. These changes will be incorporated into the next release; probably next Friday.