Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode dds as ARGB instead of ABGR #423

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions shared/src/main/java/com/faforever/neroxis/util/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,19 @@ public static void writeRawDDS(BufferedImage image, Path path) throws IOExceptio
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
int[] values = imageRaster.getPixel(x, y, new int[4]);
for (int val : values) {
imageBytes.put((byte) val);
}
imageBytes.put((byte) values[2]);
imageBytes.put((byte) values[1]);
imageBytes.put((byte) values[0]);
imageBytes.put((byte) values[3]);
}
}
DDSHeader ddsHeader = new DDSHeader();
ddsHeader.setWidth(size);
ddsHeader.setHeight(size);
ddsHeader.setRGBBitCount(32);
ddsHeader.setRBitMask(0x000000FF);
ddsHeader.setBBitMask(0x000000FF);
ddsHeader.setGBitMask(0x0000FF00);
ddsHeader.setBBitMask(0x00FF0000);
ddsHeader.setRBitMask(0x00FF0000);
ddsHeader.setABitMask(0xFF000000);

// If we don't do this we get weird results when the file already exists
Expand Down Expand Up @@ -288,25 +289,6 @@ private static byte[] getCompressedDDSImageBytes(int size, ByteBuffer imageByteB
return allBytes;
}

private static byte[] getRawDDSImageBytes(int size, ByteBuffer imageByteBuffer) {
DDSHeader ddsHeader = new DDSHeader();
ddsHeader.setWidth(size);
ddsHeader.setHeight(size);
ddsHeader.setRGBBitCount(32);
ddsHeader.setRBitMask(0x000000FF);
ddsHeader.setGBitMask(0x0000FF00);
ddsHeader.setBBitMask(0x00FF0000);
ddsHeader.setABitMask(0xFF000000);
ddsHeader.toBytes();
byte[] headerBytes = ddsHeader.toBytes();
byte[] imageBytes = imageByteBuffer.array();
int headerLength = headerBytes.length;
int imageLength = size * size * 4;
byte[] allBytes = Arrays.copyOf(headerBytes, headerLength + imageLength);
System.arraycopy(imageBytes, 0, allBytes, headerLength, imageLength);
return allBytes;
}
Comment on lines -291 to -308
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this method deleted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unused.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this also uses ABGR order. So instead of thinking a lot about if I need to change the byte order there as well I deleted it. Without the method being used I can't really decide which order is appropriate and I didn't want anyone to use it in the future, expecting it to behave similar to writeRawDDS


public static void writeAutoScaledPNGFromMasks(FloatMask redMask, FloatMask greenMask, FloatMask blueMask,
Path path) throws IOException {
float scaleMultiplier = 255 / StrictMath.max(StrictMath.max(redMask.getMax(), greenMask.getMax()),
Expand Down
Loading