-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modifies DXT code to allow for concurrent calls
All static variables/arrays have been converted to member variables of corresponding compressor objects.
- Loading branch information
Showing
15 changed files
with
284 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name := "jsquish" | ||
|
||
organization := "com.github.memo33" | ||
|
||
version := "2.0.0-SNAPSHOT" | ||
|
||
scalaVersion := "2.11.8" | ||
|
||
javacOptions in (Compile, compile) ++= Seq( | ||
"-source", "1.6", | ||
"-target", "1.6", | ||
"-encoding", "UTF-8") | ||
|
||
crossPaths := false | ||
|
||
autoScalaLibrary := false | ||
|
||
|
||
libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.5" % "test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* ----------------------------------------------------------------------------- | ||
Copyright (c) 2006 Simon Brown [email protected] | ||
Copyright (c) 2016 memo | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
|
@@ -32,13 +33,11 @@ a copy of this software and associated documentation files (the | |
|
||
final class ColourBlock { | ||
|
||
private static final int[] remapped = new int[16]; | ||
private final int[] remapped = new int[16]; | ||
private final int[] indices = new int[16]; | ||
private final int[] codes = new int[16]; | ||
|
||
private static final int[] indices = new int[16]; | ||
|
||
private static final int[] codes = new int[16]; | ||
|
||
private ColourBlock() {} | ||
ColourBlock() {} | ||
|
||
static int gammaColour(final float colour, final float scale) { | ||
//return round(scale * (float)Math.pow(colour, 1.0 / 2.2)); | ||
|
@@ -69,7 +68,7 @@ private static void writeColourBlock(final int a, final int b, final int[] indic | |
} | ||
} | ||
|
||
static void writeColourBlock3(final Vec start, final Vec end, final int[] indices, final byte[] block, final int offset) { | ||
void writeColourBlock3(final Vec start, final Vec end, final int[] indices, final byte[] block, final int offset) { | ||
// get the packed values | ||
int a = floatTo565(start); | ||
int b = floatTo565(end); | ||
|
@@ -97,7 +96,7 @@ else if ( indices[i] == 1 ) | |
writeColourBlock(a, b, remapped, block, offset); | ||
} | ||
|
||
static void writeColourBlock4(final Vec start, final Vec end, final int[] indices, final byte[] block, final int offset) { | ||
void writeColourBlock4(final Vec start, final Vec end, final int[] indices, final byte[] block, final int offset) { | ||
// get the packed values | ||
int a = floatTo565(start); | ||
int b = floatTo565(end); | ||
|
@@ -123,10 +122,8 @@ static void writeColourBlock4(final Vec start, final Vec end, final int[] indice | |
writeColourBlock(a, b, remapped, block, offset); | ||
} | ||
|
||
static void decompressColour(final byte[] rgba, final byte[] block, final int offset, final boolean isDXT1) { | ||
void decompressColour(final byte[] rgba, final byte[] block, final int offset, final boolean isDXT1) { | ||
// unpack the endpoints | ||
final int[] codes = ColourBlock.codes; | ||
|
||
final int a = unpack565(block, offset, codes, 0); | ||
final int b = unpack565(block, offset + 2, codes, 4); | ||
|
||
|
@@ -149,8 +146,6 @@ static void decompressColour(final byte[] rgba, final byte[] block, final int of | |
codes[12 + 3] = (isDXT1 && a <= b) ? 0 : 255; | ||
|
||
// unpack the indices | ||
final int[] indices = ColourBlock.indices; | ||
|
||
for ( int i = 0; i < 4; ++i ) { | ||
final int index = 4 * i; | ||
final int packed = (block[offset + 4 + i] & 0xFF); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* ----------------------------------------------------------------------------- | ||
Copyright (c) 2006 Simon Brown [email protected] | ||
Copyright (c) 2016 memo | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* ----------------------------------------------------------------------------- | ||
Copyright (c) 2006 Simon Brown [email protected] | ||
Copyright (c) 2016 memo | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
|
@@ -29,20 +30,20 @@ a copy of this software and associated documentation files (the | |
|
||
final class CompressorAlpha { | ||
|
||
private static final int[] swapped = new int[16]; | ||
private final int[] swapped = new int[16]; | ||
|
||
private static final int[] codes5 = new int[8]; | ||
private static final int[] codes7 = new int[8]; | ||
private final int[] codes5 = new int[8]; | ||
private final int[] codes7 = new int[8]; | ||
|
||
private static final int[] indices5 = new int[16]; | ||
private static final int[] indices7 = new int[16]; | ||
private final int[] indices5 = new int[16]; | ||
private final int[] indices7 = new int[16]; | ||
|
||
private static final int[] codes = new int[8]; | ||
private static final int[] indices = new int[16]; | ||
private final int[] codes = new int[8]; | ||
private final int[] indices = new int[16]; | ||
|
||
private CompressorAlpha() {} | ||
CompressorAlpha() {} | ||
|
||
static void compressAlphaDxt3(final byte[] rgba, final int mask, final byte[] block, final int offset) { | ||
void compressAlphaDxt3(final byte[] rgba, final int mask, final byte[] block, final int offset) { | ||
// quantise and pack the alpha values pairwise | ||
for ( int i = 0; i < 8; ++i ) { | ||
// quantise down to 4 bits | ||
|
@@ -64,7 +65,7 @@ static void compressAlphaDxt3(final byte[] rgba, final int mask, final byte[] bl | |
} | ||
} | ||
|
||
static void decompressAlphaDxt3(final byte[] rgba, final byte[] block, final int offset) { | ||
void decompressAlphaDxt3(final byte[] rgba, final byte[] block, final int offset) { | ||
// unpack the alpha values pairwise | ||
for ( int i = 0; i < 8; ++i ) { | ||
// quantise down to 4 bits | ||
|
@@ -80,7 +81,7 @@ static void decompressAlphaDxt3(final byte[] rgba, final byte[] block, final int | |
} | ||
} | ||
|
||
private static int fitCodes(final byte[] rgba, final int mask, final int[] codes, final int[] indices) { | ||
private int fitCodes(final byte[] rgba, final int mask, final int[] codes, final int[] indices) { | ||
// fit each alpha value to the codebook | ||
int err = 0; | ||
for ( int i = 0; i < 16; ++i ) { | ||
|
@@ -117,7 +118,7 @@ private static int fitCodes(final byte[] rgba, final int mask, final int[] codes | |
return err; | ||
} | ||
|
||
private static void writeAlphaBlock(final int alpha0, final int alpha1, final int[] indices, final byte[] block, final int offset) { | ||
private void writeAlphaBlock(final int alpha0, final int alpha1, final int[] indices, final byte[] block, final int offset) { | ||
// write the first two bytes | ||
block[offset + 0] = (byte)alpha0; | ||
block[offset + 1] = (byte)alpha1; | ||
|
@@ -139,10 +140,8 @@ private static void writeAlphaBlock(final int alpha0, final int alpha1, final in | |
} | ||
} | ||
|
||
private static void writeAlphaBlock5(final int alpha0, final int alpha1, final int[] indices, final byte[] block, final int offset) { | ||
private void writeAlphaBlock5(final int alpha0, final int alpha1, final int[] indices, final byte[] block, final int offset) { | ||
// check the relative values of the endpoints | ||
final int[] swapped = CompressorAlpha.swapped; | ||
|
||
if ( alpha0 > alpha1 ) { | ||
// swap the indices | ||
for ( int i = 0; i < 16; ++i ) { | ||
|
@@ -165,10 +164,8 @@ else if ( index <= 5 ) | |
} | ||
} | ||
|
||
private static void writeAlphaBlock7(final int alpha0, final int alpha1, final int[] indices, final byte[] block, final int offset) { | ||
private void writeAlphaBlock7(final int alpha0, final int alpha1, final int[] indices, final byte[] block, final int offset) { | ||
// check the relative values of the endpoints | ||
final int[] swapped = CompressorAlpha.swapped; | ||
|
||
if ( alpha0 < alpha1 ) { | ||
// swap the indices | ||
for ( int i = 0; i < 16; ++i ) { | ||
|
@@ -189,7 +186,7 @@ else if ( index == 1 ) | |
} | ||
} | ||
|
||
static void compressAlphaDxt5(final byte[] rgba, final int mask, final byte[] block, final int offset) { | ||
void compressAlphaDxt5(final byte[] rgba, final int mask, final byte[] block, final int offset) { | ||
// get the range for 5-alpha and 7-alpha interpolation | ||
int min5 = 255; | ||
int max5 = 0; | ||
|
@@ -231,8 +228,6 @@ static void compressAlphaDxt5(final byte[] rgba, final int mask, final byte[] bl | |
min7 = max(0, max7 - 7); | ||
|
||
// set up the 5-alpha code book | ||
final int[] codes5 = CompressorAlpha.codes5; | ||
|
||
codes5[0] = min5; | ||
codes5[1] = max5; | ||
for ( int i = 1; i < 5; ++i ) | ||
|
@@ -241,8 +236,6 @@ static void compressAlphaDxt5(final byte[] rgba, final int mask, final byte[] bl | |
codes5[7] = 255; | ||
|
||
// set up the 7-alpha code book | ||
final int[] codes7 = CompressorAlpha.codes7; | ||
|
||
codes7[0] = min7; | ||
codes7[1] = max7; | ||
for ( int i = 1; i < 7; ++i ) | ||
|
@@ -259,14 +252,12 @@ static void compressAlphaDxt5(final byte[] rgba, final int mask, final byte[] bl | |
writeAlphaBlock7(min7, max7, indices7, block, offset); | ||
} | ||
|
||
static void decompressAlphaDxt5(final byte[] rgba, final byte[] block, final int offset) { | ||
void decompressAlphaDxt5(final byte[] rgba, final byte[] block, final int offset) { | ||
// get the two alpha values | ||
final int alpha0 = (block[offset + 0] & 0xFF); | ||
final int alpha1 = (block[offset + 1] & 0xFF); | ||
|
||
// compare the values to build the codebook | ||
final int[] codes = CompressorAlpha.codes; | ||
|
||
codes[0] = alpha0; | ||
codes[1] = alpha1; | ||
if ( alpha0 <= alpha1 ) { | ||
|
@@ -282,8 +273,6 @@ static void decompressAlphaDxt5(final byte[] rgba, final byte[] block, final int | |
} | ||
|
||
// decode the indices | ||
final int[] indices = CompressorAlpha.indices; | ||
|
||
int src = 2; | ||
int dest = 0; | ||
for ( int i = 0; i < 2; ++i ) { | ||
|
Oops, something went wrong.