Skip to content

Commit

Permalink
Offer easy access to a texture's aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
tordanik committed Nov 14, 2024
1 parent d4ae59d commit 96cd670
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public final class BlankTexture extends RuntimeTexture {

public static final BlankTexture INSTANCE = new BlankTexture();
private static final Resolution RESOLUTION = new Resolution(128, 128);

private BlankTexture(TextureDataDimensions dimensions) {
super(dimensions, Wrap.REPEAT, NamedTexCoordFunction.GLOBAL_X_Z);
Expand All @@ -25,7 +26,12 @@ protected BufferedImage createBufferedImage(Resolution resolution) {

@Override
protected BufferedImage createBufferedImage() {
return getBufferedImage(new Resolution(128, 128));
return getBufferedImage(RESOLUTION);
}

@Override
public float getAspectRatio() {
return RESOLUTION.getAspectRatio();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public TextureAtlas(List<TextureData> textures) {
@Override
protected BufferedImage createBufferedImage() {

BufferedImage result = new BufferedImage(numTexturesX * TEXTURE_RESOLUTION.width,
numTexturesZ * TEXTURE_RESOLUTION.height, BufferedImage.TYPE_INT_ARGB);
BufferedImage result = new BufferedImage(getResolution().width, getResolution().height, BufferedImage.TYPE_INT_ARGB);

Graphics2D g2d = result.createGraphics();

Expand Down Expand Up @@ -98,6 +97,16 @@ VectorXZ mapTexCoord(TextureData texture, VectorXZ texCoord) {

}

private Resolution getResolution() {
return new Resolution(numTexturesX * TEXTURE_RESOLUTION.width,
numTexturesZ * TEXTURE_RESOLUTION.height);
}

@Override
public float getAspectRatio() {
return getResolution().getAspectRatio();
}

@Override
public String toString() {
return "TextureAtlas " + textures;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ public void writeRasterImageToStream(OutputStream stream) throws IOException {
writeRasterImageToStream(stream, 0.75f);
}

/** returns this texture's aspect ratio (same definition as {@link Resolution#getAspectRatio()}) */
public float getAspectRatio() {
return Resolution.of(getBufferedImage()).getAspectRatio();
}

/** averages the color values (in linear color space) */
public LColor getAverageColor() {

Expand Down

0 comments on commit 96cd670

Please sign in to comment.