Skip to content

Commit

Permalink
Premultiply Alpha in BufferedImageTextureHolder
Browse files Browse the repository at this point in the history
Initialize texture with premultiplied alpha, as expected by shader.
  • Loading branch information
matzf committed Feb 7, 2025
1 parent 45ffb0f commit 8d499ba
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.openmobilemaps.mapscore.graphics.util.GlTextureHelper;
import io.openmobilemaps.mapscore.shared.graphics.objects.TextureHolderInterface;

import org.jetbrains.annotations.NotNull;

import java.awt.image.BufferedImage;

/** Implementation of the TextureHolderInterface for BufferedImage and OpenGL. */
Expand All @@ -11,7 +13,18 @@ public class BufferedImageTextureHolder extends TextureHolderInterface {
protected int usageCounter;
protected int textureId;

public BufferedImageTextureHolder(BufferedImage image) {
/**
* Construct a BufferedImageTextureHolder.
*
* <p>NOTE: this may modify the image by calling {@link BufferedImage#coerceData} to ensure that
* we have premultiplied alpha image data.
*
* @param image Image, may be modified during the constructor
*/
public BufferedImageTextureHolder(@NotNull BufferedImage image) {
// premultiply alpha
image.coerceData(true);

this.image = image;
this.usageCounter = 0;
}
Expand Down

0 comments on commit 8d499ba

Please sign in to comment.