|
|
@ -242,19 +242,28 @@ public class TextureHelper extends AbstractBlenderHelper { |
|
|
|
depth = 1; |
|
|
|
depth = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(depth); |
|
|
|
ArrayList<ByteBuffer> dataArray = new ArrayList<ByteBuffer>(depth); |
|
|
|
TexturePixel[] colors = new TexturePixel[] { new TexturePixel(), new TexturePixel(), new TexturePixel(), new TexturePixel() }; |
|
|
|
int[] sizes = image.getMipMapSizes() != null ? image.getMipMapSizes() : new int[1]; |
|
|
|
|
|
|
|
int[] newMipmapSizes = image.getMipMapSizes() != null ? new int[image.getMipMapSizes().length] : null; |
|
|
|
|
|
|
|
|
|
|
|
for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) { |
|
|
|
for (int dataLayerIndex = 0; dataLayerIndex < depth; ++dataLayerIndex) { |
|
|
|
ByteBuffer data = image.getData(dataLayerIndex); |
|
|
|
ByteBuffer data = image.getData(dataLayerIndex); |
|
|
|
data.rewind(); |
|
|
|
data.rewind(); |
|
|
|
|
|
|
|
if(sizes.length == 1) { |
|
|
|
|
|
|
|
sizes[0] = data.remaining(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
float widthToHeightRatio = image.getWidth() / image.getHeight();//this should always be constant for each mipmap
|
|
|
|
|
|
|
|
List<DDSTexelData> texelDataList = new ArrayList<DDSTexelData>(sizes.length); |
|
|
|
|
|
|
|
int maxPosition = 0, resultSize = 0; |
|
|
|
|
|
|
|
|
|
|
|
byte[] bytes = new byte[image.getWidth() * image.getHeight() << 2]; |
|
|
|
for(int sizeIndex=0;sizeIndex<sizes.length;++sizeIndex) { |
|
|
|
DDSTexelData texelData = new DDSTexelData(data.remaining() * 8/format.getBitsPerPixel()/16/*data.remaining() / (format.getBitsPerPixel() << 1)*/, |
|
|
|
maxPosition += sizes[sizeIndex]; |
|
|
|
image.getWidth(), image.getHeight(), format != Format.DXT1); |
|
|
|
DDSTexelData texelData = new DDSTexelData(sizes[sizeIndex], widthToHeightRatio, format); |
|
|
|
|
|
|
|
texelDataList.add(texelData); |
|
|
|
switch (format) { |
|
|
|
switch (format) { |
|
|
|
case DXT1:// BC1
|
|
|
|
case DXT1:// BC1
|
|
|
|
case DXT1A: |
|
|
|
case DXT1A: |
|
|
|
while (data.hasRemaining()) { |
|
|
|
while (data.position() < maxPosition) { |
|
|
|
|
|
|
|
TexturePixel[] colors = new TexturePixel[] { new TexturePixel(), new TexturePixel(), new TexturePixel(), new TexturePixel() }; |
|
|
|
short c0 = data.getShort(); |
|
|
|
short c0 = data.getShort(); |
|
|
|
short c1 = data.getShort(); |
|
|
|
short c1 = data.getShort(); |
|
|
|
int col0 = RGB565.RGB565_to_ARGB8(c0); |
|
|
|
int col0 = RGB565.RGB565_to_ARGB8(c0); |
|
|
@ -287,7 +296,8 @@ public class TextureHelper extends AbstractBlenderHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DXT3:// BC2
|
|
|
|
case DXT3:// BC2
|
|
|
|
while (data.hasRemaining()) { |
|
|
|
while (data.position() < maxPosition) { |
|
|
|
|
|
|
|
TexturePixel[] colors = new TexturePixel[] { new TexturePixel(), new TexturePixel(), new TexturePixel(), new TexturePixel() }; |
|
|
|
long alpha = data.getLong(); |
|
|
|
long alpha = data.getLong(); |
|
|
|
float[] alphas = new float[16]; |
|
|
|
float[] alphas = new float[16]; |
|
|
|
long alphasIndex = 0; |
|
|
|
long alphasIndex = 0; |
|
|
@ -322,7 +332,8 @@ public class TextureHelper extends AbstractBlenderHelper { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DXT5:// BC3
|
|
|
|
case DXT5:// BC3
|
|
|
|
float[] alphas = new float[8]; |
|
|
|
float[] alphas = new float[8]; |
|
|
|
while (data.hasRemaining()) { |
|
|
|
while (data.position() < maxPosition) { |
|
|
|
|
|
|
|
TexturePixel[] colors = new TexturePixel[] { new TexturePixel(), new TexturePixel(), new TexturePixel(), new TexturePixel() }; |
|
|
|
alphas[0] = data.get() * 255.0f; |
|
|
|
alphas[0] = data.get() * 255.0f; |
|
|
|
alphas[1] = data.get() * 255.0f; |
|
|
|
alphas[1] = data.get() * 255.0f; |
|
|
|
long alphaIndices = data.get() | data.get() << 8 | data.get() << 16 | data.get() << 24 | data.get() << 32 | data.get() << 40; |
|
|
|
long alphaIndices = data.get() | data.get() << 8 | data.get() << 16 | data.get() << 24 | data.get() << 32 | data.get() << 40; |
|
|
@ -368,24 +379,34 @@ public class TextureHelper extends AbstractBlenderHelper { |
|
|
|
default: |
|
|
|
default: |
|
|
|
throw new IllegalStateException("Unknown compressed format: " + format); |
|
|
|
throw new IllegalStateException("Unknown compressed format: " + format); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
newMipmapSizes[sizeIndex] = texelData.getSizeInBytes(); |
|
|
|
|
|
|
|
resultSize += texelData.getSizeInBytes(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
byte[] bytes = new byte[resultSize]; |
|
|
|
|
|
|
|
int offset = 0; |
|
|
|
byte[] pixelBytes = new byte[4]; |
|
|
|
byte[] pixelBytes = new byte[4]; |
|
|
|
for (int i = 0; i < image.getWidth(); ++i) { |
|
|
|
for(DDSTexelData texelData : texelDataList) { |
|
|
|
for (int j = 0; j < image.getHeight(); ++j) { |
|
|
|
for (int i = 0; i < texelData.getPixelWidth(); ++i) { |
|
|
|
texelData.getRGBA8(i, j, pixelBytes); |
|
|
|
for (int j = 0; j < texelData.getPixelHeight(); ++j) { |
|
|
|
bytes[(j * image.getWidth() + i) * 4] = pixelBytes[0]; |
|
|
|
if(texelData.getRGBA8(i, j, pixelBytes)) { |
|
|
|
bytes[(j * image.getWidth() + i) * 4 + 1] = pixelBytes[1]; |
|
|
|
bytes[offset + (j * texelData.getPixelWidth() + i) * 4] = pixelBytes[0]; |
|
|
|
bytes[(j * image.getWidth() + i) * 4 + 2] = pixelBytes[2]; |
|
|
|
bytes[offset + (j * texelData.getPixelWidth() + i) * 4 + 1] = pixelBytes[1]; |
|
|
|
bytes[(j * image.getWidth() + i) * 4 + 3] = pixelBytes[3]; |
|
|
|
bytes[offset + (j * texelData.getPixelWidth() + i) * 4 + 2] = pixelBytes[2]; |
|
|
|
|
|
|
|
bytes[offset + (j * texelData.getPixelWidth() + i) * 4 + 3] = pixelBytes[3]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
offset += texelData.getSizeInBytes(); |
|
|
|
|
|
|
|
} |
|
|
|
dataArray.add(BufferUtils.createByteBuffer(bytes)); |
|
|
|
dataArray.add(BufferUtils.createByteBuffer(bytes)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Image result = depth > 1 ? new Image(Format.RGBA8, image.getWidth(), image.getHeight(), depth, dataArray) : |
|
|
|
Image result = depth > 1 ? new Image(Format.RGBA8, image.getWidth(), image.getHeight(), depth, dataArray) : |
|
|
|
new Image(Format.RGBA8, image.getWidth(), image.getHeight(), dataArray.get(0)); |
|
|
|
new Image(Format.RGBA8, image.getWidth(), image.getHeight(), dataArray.get(0)); |
|
|
|
if(image.getMipMapSizes() != null) { |
|
|
|
if(newMipmapSizes != null) { |
|
|
|
result.setMipMapSizes(image.getMipMapSizes().clone()); |
|
|
|
result.setMipMapSizes(newMipmapSizes); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
@ -500,13 +521,15 @@ public class TextureHelper extends AbstractBlenderHelper { |
|
|
|
float gfac = ((Number) tex.getFieldValue("gfac")).floatValue(); |
|
|
|
float gfac = ((Number) tex.getFieldValue("gfac")).floatValue(); |
|
|
|
float bfac = ((Number) tex.getFieldValue("bfac")).floatValue(); |
|
|
|
float bfac = ((Number) tex.getFieldValue("bfac")).floatValue(); |
|
|
|
float[][] colorBand = new ColorBand(tex, blenderContext).computeValues(); |
|
|
|
float[][] colorBand = new ColorBand(tex, blenderContext).computeValues(); |
|
|
|
|
|
|
|
int depth = image.getDepth() == 0 ? 1 : image.getDepth(); |
|
|
|
|
|
|
|
|
|
|
|
if (colorBand != null) { |
|
|
|
if (colorBand != null) { |
|
|
|
TexturePixel pixel = new TexturePixel(); |
|
|
|
TexturePixel pixel = new TexturePixel(); |
|
|
|
PixelInputOutput imageIO = PixelIOFactory.getPixelIO(image.getFormat()); |
|
|
|
PixelInputOutput imageIO = PixelIOFactory.getPixelIO(image.getFormat()); |
|
|
|
|
|
|
|
for (int layerIndex = 0; layerIndex < depth; ++layerIndex) { |
|
|
|
for (int x = 0; x < image.getWidth(); ++x) { |
|
|
|
for (int x = 0; x < image.getWidth(); ++x) { |
|
|
|
for (int y = 0; y < image.getHeight(); ++y) { |
|
|
|
for (int y = 0; y < image.getHeight(); ++y) { |
|
|
|
imageIO.read(image, pixel, x, y); |
|
|
|
imageIO.read(image, layerIndex, pixel, x, y); |
|
|
|
|
|
|
|
|
|
|
|
int colorbandIndex = (int) (pixel.alpha * 1000.0f); |
|
|
|
int colorbandIndex = (int) (pixel.alpha * 1000.0f); |
|
|
|
pixel.red = colorBand[colorbandIndex][0] * rfac; |
|
|
|
pixel.red = colorBand[colorbandIndex][0] * rfac; |
|
|
@ -514,21 +537,24 @@ public class TextureHelper extends AbstractBlenderHelper { |
|
|
|
pixel.blue = colorBand[colorbandIndex][2] * bfac; |
|
|
|
pixel.blue = colorBand[colorbandIndex][2] * bfac; |
|
|
|
pixel.alpha = colorBand[colorbandIndex][3]; |
|
|
|
pixel.alpha = colorBand[colorbandIndex][3]; |
|
|
|
|
|
|
|
|
|
|
|
imageIO.write(image, pixel, x, y); |
|
|
|
imageIO.write(image, layerIndex, pixel, x, y); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (rfac != 1.0f || gfac != 1.0f || bfac != 1.0f) { |
|
|
|
} else if (rfac != 1.0f || gfac != 1.0f || bfac != 1.0f) { |
|
|
|
TexturePixel pixel = new TexturePixel(); |
|
|
|
TexturePixel pixel = new TexturePixel(); |
|
|
|
PixelInputOutput imageIO = PixelIOFactory.getPixelIO(image.getFormat()); |
|
|
|
PixelInputOutput imageIO = PixelIOFactory.getPixelIO(image.getFormat()); |
|
|
|
|
|
|
|
for (int layerIndex = 0; layerIndex < depth; ++layerIndex) { |
|
|
|
for (int x = 0; x < image.getWidth(); ++x) { |
|
|
|
for (int x = 0; x < image.getWidth(); ++x) { |
|
|
|
for (int y = 0; y < image.getHeight(); ++y) { |
|
|
|
for (int y = 0; y < image.getHeight(); ++y) { |
|
|
|
imageIO.read(image, pixel, x, y); |
|
|
|
imageIO.read(image, layerIndex, pixel, x, y); |
|
|
|
|
|
|
|
|
|
|
|
pixel.red *= rfac; |
|
|
|
pixel.red *= rfac; |
|
|
|
pixel.green *= gfac; |
|
|
|
pixel.green *= gfac; |
|
|
|
pixel.blue *= bfac; |
|
|
|
pixel.blue *= bfac; |
|
|
|
|
|
|
|
|
|
|
|
imageIO.write(image, pixel, x, y); |
|
|
|
imageIO.write(image, layerIndex, pixel, x, y); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|