Skip to content

Commit

Permalink
Optimized memory usage, batch export and conversion, multi resolution…
Browse files Browse the repository at this point in the history
… export, new standalone executable for windows and linux.
  • Loading branch information
riccardobl committed Jul 7, 2018
1 parent 97d04f0 commit 0d9a704
Show file tree
Hide file tree
Showing 35 changed files with 1,062 additions and 244 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
*.so
*.dll
*.dylib
**/hs_err_pid*.log
**/hs_err_pid*.log
**/.vscode
.classpath
.settings
.project
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,15 @@ os:
- linux
notifications:
email: true
env:
- LINUX=1
- WINDOWS=1
script:
- ./gradlew build
- ./build.sh travis
deploy:
provider: releases
api_key: ""
file: "build/libs/dist/*"
skip_cleanup: true
on:
tags: true
12 changes: 6 additions & 6 deletions Tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
dependencies {
compileOnly "${jme_group}:jme3-core:${jme_version}"

testCompile project(':dds_writer__cli')
testCompile project(':dds_writer__s3tc_lwjgl2_delegate')
testCompile project(':dds_writer__rgtc_lwjgl2_delegate')
testCompile project(':dds_writer__lwjgl2_blockcompression_delegate')
compile project(':dds_writer__cli')
compile project(':dds_writer__s3tc_lwjgl2_delegate')
compile project(':dds_writer__rgtc_lwjgl2_delegate')
compile project(':dds_writer__lwjgl2_blockcompression_delegate')

testCompile "${jme_group}:jme3-core:${jme_version}"
testCompile "${jme_group}:jme3-desktop:${jme_version}"
compile "${jme_group}:jme3-core:${jme_version}"
compile "${jme_group}:jme3-desktop:${jme_version}"


testCompile 'junit:junit:4.12'
Expand Down
7 changes: 6 additions & 1 deletion Tests/src/test/java/tests/InteractiveCLI.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package tests;
import ddswriter.cli.CLI109;
import ddswriter.delegates.lwjgl2_s3tc.S3tcCLI109Module;

public class InteractiveCLI{
public static void main(String[] args) throws Exception {
CLI109.main(new String[]{"--debug","--use_lwjgl","--interactive"});
// S3tcCLI109Module.class.newInstance();
CLI109.main(new String[]{"--debug","--interactive","--use-lwjgl"});
// CLI109.main(new String[]{"--debug","--in","D:\\Assets\\AGEN\\thelab_map\\textures\\Ramp_BaseColorMap.png","--out","C:\\Users\\Win7rb\\AppData\\Local\\Temp\\test.dds","--use-opengl",
// "--format","S3TC_DXT1","--gen-mipmaps"
// });
}
}
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ allprojects {


group="com.github.riccardobl.DDSWriter"

version= project.hasProperty('in_version') ? project.getProperty('in_version') : '-SNAPSHOT'

if (project.hasProperty("DEV_INSTALL")){
version="dev"
Expand All @@ -17,6 +19,17 @@ allprojects {
}


task buildBundle( type: Jar, dependsOn: subprojects.tasks["build"] ) {
baseName = project.name +'-bundle'
manifest {
attributes 'Main-Class': "ddswriter.cli.CLI109"
}
subprojects.each { subproject ->
from subproject.configurations.archives.allArtifacts.files.collect {
zipTree(it)
}
}
}

subprojects {
apply plugin: 'maven'
Expand Down
29 changes: 29 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
./gradlew clean

if [ "$1" = "travis" ];
then
if [ "$TRAVIS_TAG" != "" ];
then
args="-Pin_version=$TRAVIS_TAG"
else
args="-Pin_version=$TRAVIS_COMMIT"
fi
else
args=$@
fi

./gradlew build buildBundle $args
cd build/libs
cp -Rvf ../../res/* .
chmod +x *.sh
rm -Rvf dist
if [ "$LINUX" != "" ];
then
./make-linux-bundle.sh
fi
if [ "$WINDOWS" != "" ];
then
./make-windows-bundle.sh
fi
./make-generic-bundle.sh
9 changes: 8 additions & 1 deletion dds_writer/src/main/java/ddswriter/DDSDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,12 @@ and associated documentation files (the "Software"), to deal in the Software wit
*/
public interface DDSDelegate{
public void body(Texture tx,Map<String,String> options, DDS_HEADER header,DDS_BODY body)throws Exception ;
public void header(Texture tx,Map<String,String> options,DDS_HEADER header)throws Exception ;

public void header(Texture tx, Map<String,String> options, DDS_HEADER header) throws Exception;

/**
* Since the same delegate can be used multiple times, this method is called after every succesful export and should
* reset the delegate to its original state.
*/
public void end();
}
13 changes: 9 additions & 4 deletions dds_writer/src/main/java/ddswriter/DDSSlicedDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public void skip() {
SKIP=true;
}

@Override
public void end() {
SKIP=false;
}

public abstract void body(Texture tx, Texel ir, int mipmap, int slice, Map<String,String> options, DDS_HEADER header, DDS_BODY body) throws Exception;

public abstract void header(Texture tx, Texel ir, int mipmap, int slice, Map<String,String> options, DDS_HEADER header) throws Exception;
Expand All @@ -64,8 +69,8 @@ public void process_slice(Texture tx, Texel ir, int mipmap, int slice, Map<Strin
if(is_header){
header(tx,ir,mipmap,slice,options,header);

}else{
body(tx,ir,mipmap,slice,options,header,body);
} else {
body(tx, ir, mipmap, slice, options, header, body);
}

}
Expand All @@ -74,12 +79,12 @@ private void slice(Texture tx, Map<String,String> options, DDS_HEADER header, DD

int mipmaps=!tx.getImage().hasMipmaps()?1:tx.getImage().getMipMapSizes().length;
// boolean is_header=body==null;

if(tx instanceof Texture2D){
for(int mipmap=0;mipmap<mipmaps;mipmap++){
ImageRaster irr=ImageRaster.create(tx.getImage(),0,mipmap,false);
Texel ir=Texel.fromImageRaster(irr,new Vector2f(0,0),new Vector2f(irr.getWidth(),irr.getHeight()));
process_slice(tx,ir,mipmap,0,options,header,body);
process_slice(tx,ir,mipmap,0,options,header,body);

}
}else if(tx instanceof TextureCubeMap){
for(int slice=0;slice<6;slice++){
Expand Down
4 changes: 4 additions & 0 deletions dds_writer/src/main/java/ddswriter/DDSWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public static void write(Texture tx, Map<String,String> options,Collection<DDSDe

body.flush();
os.close();

for(DDSDelegate delegate:delegates){
delegate.end();
}
}


Expand Down
155 changes: 155 additions & 0 deletions dds_writer/src/main/java/ddswriter/Pixel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package ddswriter;

import com.jme3.math.Vector4f;

import ddswriter.Texel.PixelFormat;

/**
* Pixel
*/
public class Pixel{
Vector4f PIXEL=new Vector4f();
PixelFormat FORMAT;

public Pixel(PixelFormat format,float r,float g,float b,float a){
this(format,null);
PIXEL.set(r,g,b,a);
}

public Pixel(PixelFormat format,Vector4f px){
if(px!=null)PIXEL.set(px);
FORMAT=format;
}

public Vector4f getRawPixel() {
return PIXEL;
}

public float r(PixelFormat toformat) {
return get(toformat,0);
}

public float g(PixelFormat toformat) {
return get(toformat,1);
}

public float b(PixelFormat toformat) {
return get(toformat,2);
}

public float a(PixelFormat toformat) {
return get(toformat,3);
}

protected float get(PixelFormat to, int p) {
PixelFormat from=FORMAT;
if(from==to) return get(p);
if(from==PixelFormat.FLOAT_NORMALIZED_RGBA){
switch(to){
case INT_RGBA:{
return get(p)*255f;
// Vector4f out = c.clone();
// out.x = (int) (c.x * 255f);
// out.y = (int) (c.y * 255f);
// out.z = (int) (c.z * 255f);
// out.w = (int) (c.w * 255f);
// return out;
}
case PACKED_ARGB:{
int x=(int)(get(0)*255f);
int y=(int)(get(1)*255f);
int z=(int)(get(2)*255f);
int w=(int)(get(3)*255f);

int packed=(int)w<<24|(int)x<<16|(int)y<<8|(int)z;

// Vector4f out = convert(PixelFormat.FLOAT_NORMALIZED_RGBA, PixelFormat.INT_RGBA, c);
// out = convert(PixelFormat.INT_RGBA, PixelFormat.PACKED_ARGB, out);
return packed;
}
}
}else if(from==PixelFormat.INT_RGBA){
switch(to){
case FLOAT_NORMALIZED_RGBA:{
return get(p)/255f;
}
case PACKED_ARGB:{
int x=(int)(get(0));
int y=(int)(get(1));
int z=(int)(get(2));
int w=(int)(get(3));

int packed=(int)w<<24|(int)x<<16|(int)y<<8|(int)z;
return packed;
// Vector4f out = new Vector4f();
// int p = (int) c.w << 24 | (int) c.x << 16 | (int) c.y << 8 | (int) c.z;
// out.x = p;
// return out;
}
}
}
throw new UnsupportedOperationException();

}

protected float get(int p) {
switch(p){
case 0:
return PIXEL.x;
case 1:
return PIXEL.y;
case 2:
return PIXEL.z;
case 3:
return PIXEL.w;
}
throw new UnsupportedOperationException();
}

// protected Vector4f convert(PixelFormat from, PixelFormat to, Vector4f c) {
// if(from==to) return c;
// if(from==PixelFormat.FLOAT_NORMALIZED_RGBA){
// switch(to){
// case INT_RGBA:{
// Vector4f out=c.clone();
// out.x=(int)(c.x*255f);
// out.y=(int)(c.y*255f);
// out.z=(int)(c.z*255f);
// out.w=(int)(c.w*255f);
// return out;
// }
// case PACKED_ARGB:{
// Vector4f out=convert(PixelFormat.FLOAT_NORMALIZED_RGBA,PixelFormat.INT_RGBA,c);
// out=convert(PixelFormat.INT_RGBA,PixelFormat.PACKED_ARGB,out);
// return out;
// }
// }
// }else if(from==PixelFormat.INT_RGBA){
// switch(to){
// case FLOAT_NORMALIZED_RGBA:{
// Vector4f out=c.clone();
// out.x=(c.x/255f);
// out.y=(c.y/255f);
// out.z=(c.z/255f);
// out.w=(c.w/255f);
// return out;
// }
// case PACKED_ARGB:{
// Vector4f out=new Vector4f();
// int p=(int)c.w<<24|(int)c.x<<16|(int)c.y<<8|(int)c.z;
// out.x=p;
// return out;
// }
// }
// }
// return null;
// }

public Vector4f toVector4f(PixelFormat format) {
return new Vector4f(r(format),g(format),b(format),a(format));
}
public Vector4f toVector4f(PixelFormat format,Vector4f v) {
v.set(r(format),g(format),b(format),a(format));
return v;
}
}
Loading

0 comments on commit 0d9a704

Please sign in to comment.