www in docker support

This commit is contained in:
MaddoScientisto 2026-04-22 18:41:37 +02:00
commit c227fce036
2145 changed files with 399596 additions and 58 deletions

View file

@ -0,0 +1,16 @@
package org.jcodec.common.dct;
import org.jcodec.api.NotSupportedException;
public abstract class DCT {
public short[] encode(byte[] orig) {
throw new NotSupportedException("");
}
public abstract int[] decode(int[] paramArrayOfint);
public void decodeAll(int[][] src) {
for (int i = 0; i < src.length; i++)
src[i] = decode(src[i]);
}
}

View file

@ -0,0 +1,53 @@
package org.jcodec.common.dct;
public class DCTRef {
static double[] coefficients = new double[64];
static {
for (int j = 0; j < 8; j++) {
coefficients[j] = Math.sqrt(0.125D);
for (int i = 8; i < 64; i += 8)
coefficients[i + j] = 0.5D * Math.cos((double)i * ((double)j + 0.5D) * Math.PI / 64.0D);
}
}
public static void fdct(int[] block, int off) {
double[] out = new double[64];
for (int i = 0; i < 64; i += 8) {
for (int k = 0; k < 8; k++) {
double tmp = 0.0D;
for (int m = 0; m < 8; m++)
tmp += coefficients[i + m] * (double)block[m * 8 + k + off];
out[i + k] = tmp * 4.0D;
}
}
for (int j = 0; j < 8; j++) {
for (int k = 0; k < 64; k += 8) {
double tmp = 0.0D;
for (int m = 0; m < 8; m++)
tmp += out[k + m] * coefficients[j * 8 + m];
block[k + j + off] = (int)(tmp + 0.499999999999D);
}
}
}
public static void idct(int[] block, int off) {
double[] out = new double[64];
for (int j = 0; j < 64; j += 8) {
for (int k = 0; k < 8; k++) {
double tmp = 0.0D;
for (int m = 0; m < 8; m++)
tmp += (double)block[j + m] * coefficients[m * 8 + k];
out[j + k] = tmp;
}
}
for (int i = 0; i < 8; i++) {
for (int k = 0; k < 8; k++) {
double tmp = 0.0D;
for (int m = 0; m < 64; m += 8)
tmp += coefficients[m + i] * out[m + k];
block[i * 8 + k] = (int)(tmp + 0.5D);
}
}
}
}

View file

@ -0,0 +1,637 @@
package org.jcodec.common.dct;
import java.nio.ShortBuffer;
public class FfmpegIntDct {
private static final int DCTSIZE = 8;
private static final int DCTSIZE_6 = 48;
private static final int DCTSIZE_5 = 40;
private static final int DCTSIZE_4 = 32;
private static final int DCTSIZE_3 = 24;
private static final int DCTSIZE_2 = 16;
private static final int DCTSIZE_1 = 8;
private static final int DCTSIZE_7 = 56;
private static final int DCTSIZE_0 = 0;
private static final int PASS1_BITS = 2;
private static final int CONST_BITS = 13;
private static final int D1 = 11;
private static final int D2 = 18;
private static final int ONEHALF_11 = 1024;
private static final int ONEHALF_18 = 131072;
private static final short FIX_0_211164243 = 1730;
private static final short FIX_0_275899380 = 2260;
private static final short FIX_0_298631336 = 2446;
private static final short FIX_0_390180644 = 3196;
private static final short FIX_0_509795579 = 4176;
private static final short FIX_0_541196100 = 4433;
private static final short FIX_0_601344887 = 4926;
private static final short FIX_0_765366865 = 6270;
private static final short FIX_0_785694958 = 6436;
private static final short FIX_0_899976223 = 7373;
private static final short FIX_1_061594337 = 8697;
private static final short FIX_1_111140466 = 9102;
private static final short FIX_1_175875602 = 9633;
private static final short FIX_1_306562965 = 10703;
private static final short FIX_1_387039845 = 11363;
private static final short FIX_1_451774981 = 11893;
private static final short FIX_1_501321110 = 12299;
private static final short FIX_1_662939225 = 13623;
private static final short FIX_1_847759065 = 15137;
private static final short FIX_1_961570560 = 16069;
private static final short FIX_2_053119869 = 16819;
private static final short FIX_2_172734803 = 17799;
private static final short FIX_2_562915447 = 20995;
private static final short FIX_3_072711026 = 25172;
public short[] decode(short[] orig) {
ShortBuffer data = ShortBuffer.wrap(orig);
pass1(data);
pass2(data);
return orig;
}
private static ShortBuffer advance(ShortBuffer dataptr, int size) {
dataptr.position(dataptr.position() + size);
return dataptr.slice();
}
private static final void pass1(ShortBuffer data) {
ShortBuffer dataptr = data.duplicate();
for (int rowctr = 7; rowctr >= 0; rowctr--) {
int d0 = dataptr.get(0);
int d2 = dataptr.get(1);
int d4 = dataptr.get(2);
int d6 = dataptr.get(3);
int d1 = dataptr.get(4);
int d3 = dataptr.get(5);
int d5 = dataptr.get(6);
int d7 = dataptr.get(7);
if ((d1 | d2 | d3 | d4 | d5 | d6 | d7) == 0) {
if (d0 != 0) {
int dcval = d0 << 2;
for (int i = 0; i < 8; i++)
dataptr.put(i, (short)dcval);
}
dataptr = advance(dataptr, 8);
} else {
int tmp2, tmp3, tmp0, tmp1, tmp10, tmp13, tmp11, tmp12;
if (d6 != 0) {
if (d2 != 0) {
int z1 = MULTIPLY(d2 + d6, (short)4433);
tmp2 = z1 + MULTIPLY(-d6, (short)15137);
tmp3 = z1 + MULTIPLY(d2, (short)6270);
tmp0 = d0 + d4 << 13;
tmp1 = d0 - d4 << 13;
tmp10 = tmp0 + tmp3;
tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2;
} else {
tmp2 = MULTIPLY(-d6, (short)10703);
tmp3 = MULTIPLY(d6, (short)4433);
tmp0 = d0 + d4 << 13;
tmp1 = d0 - d4 << 13;
tmp10 = tmp0 + tmp3;
tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2;
}
} else if (d2 != 0) {
tmp2 = MULTIPLY(d2, (short)4433);
tmp3 = MULTIPLY(d2, (short)10703);
tmp0 = d0 + d4 << 13;
tmp1 = d0 - d4 << 13;
tmp10 = tmp0 + tmp3;
tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2;
} else {
tmp10 = tmp13 = d0 + d4 << 13;
tmp11 = tmp12 = d0 - d4 << 13;
}
if (d7 != 0) {
if (d5 != 0) {
if (d3 != 0) {
if (d1 != 0) {
int z1 = d7 + d1;
int z2 = d5 + d3;
int z3 = d7 + d3;
int z4 = d5 + d1;
int z5 = MULTIPLY(z3 + z4, (short)9633);
tmp0 = MULTIPLY(d7, (short)2446);
tmp1 = MULTIPLY(d5, (short)16819);
tmp2 = MULTIPLY(d3, (short)25172);
tmp3 = MULTIPLY(d1, (short)12299);
z1 = MULTIPLY(-z1, (short)7373);
z2 = MULTIPLY(-z2, (short)20995);
z3 = MULTIPLY(-z3, (short)16069);
z4 = MULTIPLY(-z4, (short)3196);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 += z2 + z4;
tmp2 += z2 + z3;
tmp3 += z1 + z4;
} else {
int z2 = d5 + d3;
int z3 = d7 + d3;
int z5 = MULTIPLY(z3 + d5, (short)9633);
tmp0 = MULTIPLY(d7, (short)2446);
tmp1 = MULTIPLY(d5, (short)16819);
tmp2 = MULTIPLY(d3, (short)25172);
int z1 = MULTIPLY(-d7, (short)7373);
z2 = MULTIPLY(-z2, (short)20995);
z3 = MULTIPLY(-z3, (short)16069);
int z4 = MULTIPLY(-d5, (short)3196);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 += z2 + z4;
tmp2 += z2 + z3;
tmp3 = z1 + z4;
}
} else if (d1 != 0) {
int z1 = d7 + d1;
int z4 = d5 + d1;
int z5 = MULTIPLY(d7 + z4, (short)9633);
tmp0 = MULTIPLY(d7, (short)2446);
tmp1 = MULTIPLY(d5, (short)16819);
tmp3 = MULTIPLY(d1, (short)12299);
z1 = MULTIPLY(-z1, (short)7373);
int z2 = MULTIPLY(-d5, (short)20995);
int z3 = MULTIPLY(-d7, (short)16069);
z4 = MULTIPLY(-z4, (short)3196);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 += z2 + z4;
tmp2 = z2 + z3;
tmp3 += z1 + z4;
} else {
tmp0 = MULTIPLY(-d7, (short)4926);
int z1 = MULTIPLY(-d7, (short)7373);
int z3 = MULTIPLY(-d7, (short)16069);
tmp1 = MULTIPLY(-d5, (short)4176);
int z2 = MULTIPLY(-d5, (short)20995);
int z4 = MULTIPLY(-d5, (short)3196);
int z5 = MULTIPLY(d5 + d7, (short)9633);
z3 += z5;
z4 += z5;
tmp0 += z3;
tmp1 += z4;
tmp2 = z2 + z3;
tmp3 = z1 + z4;
}
} else if (d3 != 0) {
if (d1 != 0) {
int z1 = d7 + d1;
int z3 = d7 + d3;
int z5 = MULTIPLY(z3 + d1, (short)9633);
tmp0 = MULTIPLY(d7, (short)2446);
tmp2 = MULTIPLY(d3, (short)25172);
tmp3 = MULTIPLY(d1, (short)12299);
z1 = MULTIPLY(-z1, (short)7373);
int z2 = MULTIPLY(-d3, (short)20995);
z3 = MULTIPLY(-z3, (short)16069);
int z4 = MULTIPLY(-d1, (short)3196);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 = z2 + z4;
tmp2 += z2 + z3;
tmp3 += z1 + z4;
} else {
int z3 = d7 + d3;
tmp0 = MULTIPLY(-d7, (short)4926);
int z1 = MULTIPLY(-d7, (short)7373);
tmp2 = MULTIPLY(d3, (short)4176);
int z2 = MULTIPLY(-d3, (short)20995);
int z5 = MULTIPLY(z3, (short)9633);
z3 = MULTIPLY(-z3, (short)6436);
tmp0 += z3;
tmp1 = z2 + z5;
tmp2 += z3;
tmp3 = z1 + z5;
}
} else if (d1 != 0) {
int z1 = d7 + d1;
int z5 = MULTIPLY(z1, (short)9633);
z1 = MULTIPLY(z1, (short)2260);
int z3 = MULTIPLY(-d7, (short)16069);
tmp0 = MULTIPLY(-d7, (short)13623);
int z4 = MULTIPLY(-d1, (short)3196);
tmp3 = MULTIPLY(d1, (short)9102);
tmp0 += z1;
tmp1 = z4 + z5;
tmp2 = z3 + z5;
tmp3 += z1;
} else {
tmp0 = MULTIPLY(-d7, (short)11363);
tmp1 = MULTIPLY(d7, (short)9633);
tmp2 = MULTIPLY(-d7, (short)6436);
tmp3 = MULTIPLY(d7, (short)2260);
}
} else if (d5 != 0) {
if (d3 != 0) {
if (d1 != 0) {
int z2 = d5 + d3;
int z4 = d5 + d1;
int z5 = MULTIPLY(d3 + z4, (short)9633);
tmp1 = MULTIPLY(d5, (short)16819);
tmp2 = MULTIPLY(d3, (short)25172);
tmp3 = MULTIPLY(d1, (short)12299);
int z1 = MULTIPLY(-d1, (short)7373);
z2 = MULTIPLY(-z2, (short)20995);
int z3 = MULTIPLY(-d3, (short)16069);
z4 = MULTIPLY(-z4, (short)3196);
z3 += z5;
z4 += z5;
tmp0 = z1 + z3;
tmp1 += z2 + z4;
tmp2 += z2 + z3;
tmp3 += z1 + z4;
} else {
int z2 = d5 + d3;
int z5 = MULTIPLY(z2, (short)9633);
tmp1 = MULTIPLY(d5, (short)13623);
int z4 = MULTIPLY(-d5, (short)3196);
z2 = MULTIPLY(-z2, (short)11363);
tmp2 = MULTIPLY(d3, (short)9102);
int z3 = MULTIPLY(-d3, (short)16069);
tmp0 = z3 + z5;
tmp1 += z2;
tmp2 += z2;
tmp3 = z4 + z5;
}
} else if (d1 != 0) {
int z4 = d5 + d1;
int z5 = MULTIPLY(z4, (short)9633);
int z1 = MULTIPLY(-d1, (short)7373);
tmp3 = MULTIPLY(d1, (short)4926);
tmp1 = MULTIPLY(-d5, (short)4176);
int z2 = MULTIPLY(-d5, (short)20995);
z4 = MULTIPLY(z4, (short)6436);
tmp0 = z1 + z5;
tmp1 += z4;
tmp2 = z2 + z5;
tmp3 += z4;
} else {
tmp0 = MULTIPLY(d5, (short)9633);
tmp1 = MULTIPLY(d5, (short)2260);
tmp2 = MULTIPLY(-d5, (short)11363);
tmp3 = MULTIPLY(d5, (short)6436);
}
} else if (d3 != 0) {
if (d1 != 0) {
int z5 = d1 + d3;
tmp3 = MULTIPLY(d1, (short)1730);
tmp2 = MULTIPLY(-d3, (short)11893);
int z1 = MULTIPLY(d1, (short)8697);
int z2 = MULTIPLY(-d3, (short)17799);
int z4 = MULTIPLY(z5, (short)6436);
z5 = MULTIPLY(z5, (short)9633);
tmp0 = z1 - z4;
tmp1 = z2 + z4;
tmp2 += z5;
tmp3 += z5;
} else {
tmp0 = MULTIPLY(-d3, (short)6436);
tmp1 = MULTIPLY(-d3, (short)11363);
tmp2 = MULTIPLY(-d3, (short)2260);
tmp3 = MULTIPLY(d3, (short)9633);
}
} else if (d1 != 0) {
tmp0 = MULTIPLY(d1, (short)2260);
tmp1 = MULTIPLY(d1, (short)6436);
tmp2 = MULTIPLY(d1, (short)9633);
tmp3 = MULTIPLY(d1, (short)11363);
} else {
tmp0 = tmp1 = tmp2 = tmp3 = 0;
}
dataptr.put(0, DESCALE11(tmp10 + tmp3));
dataptr.put(7, DESCALE11(tmp10 - tmp3));
dataptr.put(1, DESCALE11(tmp11 + tmp2));
dataptr.put(6, DESCALE11(tmp11 - tmp2));
dataptr.put(2, DESCALE11(tmp12 + tmp1));
dataptr.put(5, DESCALE11(tmp12 - tmp1));
dataptr.put(3, DESCALE11(tmp13 + tmp0));
dataptr.put(4, DESCALE11(tmp13 - tmp0));
dataptr = advance(dataptr, 8);
}
}
}
private static int MULTIPLY(int x, short y) {
return y * (short)x;
}
private static final void pass2(ShortBuffer data) {
ShortBuffer dataptr = data.duplicate();
for (int rowctr = 7; rowctr >= 0; rowctr--) {
int tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;
int d0 = dataptr.get(0);
int d1 = dataptr.get(8);
int d2 = dataptr.get(16);
int d3 = dataptr.get(24);
int d4 = dataptr.get(32);
int d5 = dataptr.get(40);
int d6 = dataptr.get(48);
int d7 = dataptr.get(56);
if (d6 != 0) {
if (d2 != 0) {
int z1 = MULTIPLY(d2 + d6, (short)4433);
tmp2 = z1 + MULTIPLY(-d6, (short)15137);
tmp3 = z1 + MULTIPLY(d2, (short)6270);
tmp0 = d0 + d4 << 13;
tmp1 = d0 - d4 << 13;
tmp10 = tmp0 + tmp3;
tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2;
} else {
tmp2 = MULTIPLY(-d6, (short)10703);
tmp3 = MULTIPLY(d6, (short)4433);
tmp0 = d0 + d4 << 13;
tmp1 = d0 - d4 << 13;
tmp10 = tmp0 + tmp3;
tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2;
}
} else if (d2 != 0) {
tmp2 = MULTIPLY(d2, (short)4433);
tmp3 = MULTIPLY(d2, (short)10703);
tmp0 = d0 + d4 << 13;
tmp1 = d0 - d4 << 13;
tmp10 = tmp0 + tmp3;
tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2;
} else {
tmp10 = tmp13 = d0 + d4 << 13;
tmp11 = tmp12 = d0 - d4 << 13;
}
if (d7 != 0) {
if (d5 != 0) {
if (d3 != 0) {
if (d1 != 0) {
int z1 = d7 + d1;
int z2 = d5 + d3;
int z3 = d7 + d3;
int z4 = d5 + d1;
int z5 = MULTIPLY(z3 + z4, (short)9633);
tmp0 = MULTIPLY(d7, (short)2446);
tmp1 = MULTIPLY(d5, (short)16819);
tmp2 = MULTIPLY(d3, (short)25172);
tmp3 = MULTIPLY(d1, (short)12299);
z1 = MULTIPLY(-z1, (short)7373);
z2 = MULTIPLY(-z2, (short)20995);
z3 = MULTIPLY(-z3, (short)16069);
z4 = MULTIPLY(-z4, (short)3196);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 += z2 + z4;
tmp2 += z2 + z3;
tmp3 += z1 + z4;
} else {
int z1 = d7;
int z2 = d5 + d3;
int z3 = d7 + d3;
int z5 = MULTIPLY(z3 + d5, (short)9633);
tmp0 = MULTIPLY(d7, (short)2446);
tmp1 = MULTIPLY(d5, (short)16819);
tmp2 = MULTIPLY(d3, (short)25172);
z1 = MULTIPLY(-d7, (short)7373);
z2 = MULTIPLY(-z2, (short)20995);
z3 = MULTIPLY(-z3, (short)16069);
int z4 = MULTIPLY(-d5, (short)3196);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 += z2 + z4;
tmp2 += z2 + z3;
tmp3 = z1 + z4;
}
} else if (d1 != 0) {
int z1 = d7 + d1;
int z2 = d5;
int z3 = d7;
int z4 = d5 + d1;
int z5 = MULTIPLY(z3 + z4, (short)9633);
tmp0 = MULTIPLY(d7, (short)2446);
tmp1 = MULTIPLY(d5, (short)16819);
tmp3 = MULTIPLY(d1, (short)12299);
z1 = MULTIPLY(-z1, (short)7373);
z2 = MULTIPLY(-d5, (short)20995);
z3 = MULTIPLY(-d7, (short)16069);
z4 = MULTIPLY(-z4, (short)3196);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 += z2 + z4;
tmp2 = z2 + z3;
tmp3 += z1 + z4;
} else {
tmp0 = MULTIPLY(-d7, (short)4926);
int z1 = MULTIPLY(-d7, (short)7373);
int z3 = MULTIPLY(-d7, (short)16069);
tmp1 = MULTIPLY(-d5, (short)4176);
int z2 = MULTIPLY(-d5, (short)20995);
int z4 = MULTIPLY(-d5, (short)3196);
int z5 = MULTIPLY(d5 + d7, (short)9633);
z3 += z5;
z4 += z5;
tmp0 += z3;
tmp1 += z4;
tmp2 = z2 + z3;
tmp3 = z1 + z4;
}
} else if (d3 != 0) {
if (d1 != 0) {
int z1 = d7 + d1;
int z3 = d7 + d3;
int z5 = MULTIPLY(z3 + d1, (short)9633);
tmp0 = MULTIPLY(d7, (short)2446);
tmp2 = MULTIPLY(d3, (short)25172);
tmp3 = MULTIPLY(d1, (short)12299);
z1 = MULTIPLY(-z1, (short)7373);
int z2 = MULTIPLY(-d3, (short)20995);
z3 = MULTIPLY(-z3, (short)16069);
int z4 = MULTIPLY(-d1, (short)3196);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 = z2 + z4;
tmp2 += z2 + z3;
tmp3 += z1 + z4;
} else {
int z3 = d7 + d3;
tmp0 = MULTIPLY(-d7, (short)4926);
int z1 = MULTIPLY(-d7, (short)7373);
tmp2 = MULTIPLY(d3, (short)4176);
int z2 = MULTIPLY(-d3, (short)20995);
int z5 = MULTIPLY(z3, (short)9633);
z3 = MULTIPLY(-z3, (short)6436);
tmp0 += z3;
tmp1 = z2 + z5;
tmp2 += z3;
tmp3 = z1 + z5;
}
} else if (d1 != 0) {
int z1 = d7 + d1;
int z5 = MULTIPLY(z1, (short)9633);
z1 = MULTIPLY(z1, (short)2260);
int z3 = MULTIPLY(-d7, (short)16069);
tmp0 = MULTIPLY(-d7, (short)13623);
int z4 = MULTIPLY(-d1, (short)3196);
tmp3 = MULTIPLY(d1, (short)9102);
tmp0 += z1;
tmp1 = z4 + z5;
tmp2 = z3 + z5;
tmp3 += z1;
} else {
tmp0 = MULTIPLY(-d7, (short)11363);
tmp1 = MULTIPLY(d7, (short)9633);
tmp2 = MULTIPLY(-d7, (short)6436);
tmp3 = MULTIPLY(d7, (short)2260);
}
} else if (d5 != 0) {
if (d3 != 0) {
if (d1 != 0) {
int z2 = d5 + d3;
int z4 = d5 + d1;
int z5 = MULTIPLY(d3 + z4, (short)9633);
tmp1 = MULTIPLY(d5, (short)16819);
tmp2 = MULTIPLY(d3, (short)25172);
tmp3 = MULTIPLY(d1, (short)12299);
int z1 = MULTIPLY(-d1, (short)7373);
z2 = MULTIPLY(-z2, (short)20995);
int z3 = MULTIPLY(-d3, (short)16069);
z4 = MULTIPLY(-z4, (short)3196);
z3 += z5;
z4 += z5;
tmp0 = z1 + z3;
tmp1 += z2 + z4;
tmp2 += z2 + z3;
tmp3 += z1 + z4;
} else {
int z2 = d5 + d3;
int z5 = MULTIPLY(z2, (short)9633);
tmp1 = MULTIPLY(d5, (short)13623);
int z4 = MULTIPLY(-d5, (short)3196);
z2 = MULTIPLY(-z2, (short)11363);
tmp2 = MULTIPLY(d3, (short)9102);
int z3 = MULTIPLY(-d3, (short)16069);
tmp0 = z3 + z5;
tmp1 += z2;
tmp2 += z2;
tmp3 = z4 + z5;
}
} else if (d1 != 0) {
int z4 = d5 + d1;
int z5 = MULTIPLY(z4, (short)9633);
int z1 = MULTIPLY(-d1, (short)7373);
tmp3 = MULTIPLY(d1, (short)4926);
tmp1 = MULTIPLY(-d5, (short)4176);
int z2 = MULTIPLY(-d5, (short)20995);
z4 = MULTIPLY(z4, (short)6436);
tmp0 = z1 + z5;
tmp1 += z4;
tmp2 = z2 + z5;
tmp3 += z4;
} else {
tmp0 = MULTIPLY(d5, (short)9633);
tmp1 = MULTIPLY(d5, (short)2260);
tmp2 = MULTIPLY(-d5, (short)11363);
tmp3 = MULTIPLY(d5, (short)6436);
}
} else if (d3 != 0) {
if (d1 != 0) {
int z5 = d1 + d3;
tmp3 = MULTIPLY(d1, (short)1730);
tmp2 = MULTIPLY(-d3, (short)11893);
int z1 = MULTIPLY(d1, (short)8697);
int z2 = MULTIPLY(-d3, (short)17799);
int z4 = MULTIPLY(z5, (short)6436);
z5 = MULTIPLY(z5, (short)9633);
tmp0 = z1 - z4;
tmp1 = z2 + z4;
tmp2 += z5;
tmp3 += z5;
} else {
tmp0 = MULTIPLY(-d3, (short)6436);
tmp1 = MULTIPLY(-d3, (short)11363);
tmp2 = MULTIPLY(-d3, (short)2260);
tmp3 = MULTIPLY(d3, (short)9633);
}
} else if (d1 != 0) {
tmp0 = MULTIPLY(d1, (short)2260);
tmp1 = MULTIPLY(d1, (short)6436);
tmp2 = MULTIPLY(d1, (short)9633);
tmp3 = MULTIPLY(d1, (short)11363);
} else {
tmp0 = tmp1 = tmp2 = tmp3 = 0;
}
dataptr.put(0, DESCALE18(tmp10 + tmp3));
dataptr.put(56, DESCALE18(tmp10 - tmp3));
dataptr.put(8, DESCALE18(tmp11 + tmp2));
dataptr.put(48, DESCALE18(tmp11 - tmp2));
dataptr.put(16, DESCALE18(tmp12 + tmp1));
dataptr.put(40, DESCALE18(tmp12 - tmp1));
dataptr.put(24, DESCALE18(tmp13 + tmp0));
dataptr.put(32, DESCALE18(tmp13 - tmp0));
dataptr = advance(dataptr, 1);
}
}
private static final int DESCALE(int x, int n) {
return x + (1 << n - 1) >> n;
}
private static final short DESCALE11(int x) {
return (short)(x + 1024 >> 11);
}
private static final short DESCALE18(int x) {
return (short)(x + 131072 >> 18);
}
}

View file

@ -0,0 +1,15 @@
package org.jcodec.common.dct;
public class IDCT2x2 {
public static void idct(int[] blk, int off) {
int x0 = blk[off], x1 = blk[off + 1], x2 = blk[off + 2], x3 = blk[off + 3];
int t0 = x0 + x2;
int t2 = x0 - x2;
int t1 = x1 + x3;
int t3 = x1 - x3;
blk[off] = t0 + t1 >> 3;
blk[off + 1] = t0 - t1 >> 3;
blk[off + 2] = t2 + t3 >> 3;
blk[off + 3] = t2 - t3 >> 3;
}
}

View file

@ -0,0 +1,68 @@
package org.jcodec.common.dct;
public class IDCT4x4 {
public static final int CN_SHIFT = 12;
public static void idct(int[] blk, int off) {
for (int j = 0; j < 4; j++)
idct4row(blk, off + (j << 2));
for (int i = 0; i < 4; i++)
idct4col_add(blk, off + i);
}
public static final int C_FIX(double x) {
return (int)(x * 1.414213562D * 4096.0D + 0.5D);
}
public static final int C1 = C_FIX(0.6532814824D);
public static final int C2 = C_FIX(0.2705980501D);
public static final int C3 = C_FIX(0.5D);
public static final int C_SHIFT = 18;
public static final int RN_SHIFT = 15;
private static void idct4col_add(int[] blk, int off) {
int a0 = blk[off];
int a1 = blk[off + 4];
int a2 = blk[off + 8];
int a3 = blk[off + 12];
int c0 = (a0 + a2) * C3 + 131072;
int c2 = (a0 - a2) * C3 + 131072;
int c1 = a1 * C1 + a3 * C2;
int c3 = a1 * C2 - a3 * C1;
blk[off] = c0 + c1 >> 18;
blk[off + 4] = c2 + c3 >> 18;
blk[off + 8] = c2 - c3 >> 18;
blk[off + 12] = c0 - c1 >> 18;
}
public static final int R_FIX(double x) {
return (int)(x * 1.414213562D * 32768.0D + 0.5D);
}
public static final int R1 = R_FIX(0.6532814824D);
public static final int R2 = R_FIX(0.2705980501D);
public static final int R3 = R_FIX(0.5D);
public static final int R_SHIFT = 11;
private static void idct4row(int[] blk, int off) {
int a0 = blk[off];
int a1 = blk[off + 1];
int a2 = blk[off + 2];
int a3 = blk[off + 3];
int c0 = (a0 + a2) * R3 + 1024;
int c2 = (a0 - a2) * R3 + 1024;
int c1 = a1 * R1 + a3 * R2;
int c3 = a1 * R2 - a3 * R1;
blk[off] = c0 + c1 >> 11;
blk[off + 1] = c2 + c3 >> 11;
blk[off + 2] = c2 - c3 >> 11;
blk[off + 3] = c0 - c1 >> 11;
}
}

View file

@ -0,0 +1,234 @@
package org.jcodec.common.dct;
import java.nio.IntBuffer;
public class IntDCT extends DCT {
public static final IntDCT INSTANCE = new IntDCT();
private static final int DCTSIZE = 8;
private static final int PASS1_BITS = 2;
private static final int MAXJSAMPLE = 255;
private static final int CENTERJSAMPLE = 128;
private static final int RANGE_MASK = 1023;
public int[] decode(int[] orig) {
IntBuffer inptr = IntBuffer.wrap(orig);
IntBuffer workspace = IntBuffer.allocate(64);
IntBuffer outptr = IntBuffer.allocate(64);
doDecode(inptr, workspace, outptr);
return outptr.array();
}
protected static IntBuffer doDecode(IntBuffer inptr, IntBuffer workspace, IntBuffer outptr) {
pass1(inptr, workspace.duplicate());
pass2(outptr, workspace.duplicate());
return outptr;
}
private static void pass2(IntBuffer outptr, IntBuffer wsptr) {
for (int ctr = 0; ctr < 8; ctr++) {
int z2 = wsptr.get(2);
int z3 = wsptr.get(6);
int z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
int tmp2 = z1 + MULTIPLY(z3, -FIX_1_847759065);
int tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
int tmp0 = wsptr.get(0) + wsptr.get(4) << 13;
int tmp1 = wsptr.get(0) - wsptr.get(4) << 13;
int tmp10 = tmp0 + tmp3;
int tmp13 = tmp0 - tmp3;
int tmp11 = tmp1 + tmp2;
int tmp12 = tmp1 - tmp2;
tmp0 = wsptr.get(7);
tmp1 = wsptr.get(5);
tmp2 = wsptr.get(3);
tmp3 = wsptr.get(1);
z1 = tmp0 + tmp3;
z2 = tmp1 + tmp2;
z3 = tmp0 + tmp2;
int z4 = tmp1 + tmp3;
int z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
tmp0 = MULTIPLY(tmp0, FIX_0_298631336);
tmp1 = MULTIPLY(tmp1, FIX_2_053119869);
tmp2 = MULTIPLY(tmp2, FIX_3_072711026);
tmp3 = MULTIPLY(tmp3, FIX_1_501321110);
z1 = MULTIPLY(z1, -FIX_0_899976223);
z2 = MULTIPLY(z2, -FIX_2_562915447);
z3 = MULTIPLY(z3, -FIX_1_961570560);
z4 = MULTIPLY(z4, -FIX_0_390180644);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 += z2 + z4;
tmp2 += z2 + z3;
tmp3 += z1 + z4;
int D = 18;
outptr.put(range_limit(DESCALE(tmp10 + tmp3, D) & 0x3FF));
outptr.put(range_limit(DESCALE(tmp11 + tmp2, D) & 0x3FF));
outptr.put(range_limit(DESCALE(tmp12 + tmp1, D) & 0x3FF));
outptr.put(range_limit(DESCALE(tmp13 + tmp0, D) & 0x3FF));
outptr.put(range_limit(DESCALE(tmp13 - tmp0, D) & 0x3FF));
outptr.put(range_limit(DESCALE(tmp12 - tmp1, D) & 0x3FF));
outptr.put(range_limit(DESCALE(tmp11 - tmp2, D) & 0x3FF));
outptr.put(range_limit(DESCALE(tmp10 - tmp3, D) & 0x3FF));
wsptr = doAdvance(wsptr, 8);
}
}
public static int range_limit(int i) {
return idct_sample_range_limit.get(i + 256);
}
private static final IntBuffer sample_range_limit = IntBuffer.allocate(1408);
private static final IntBuffer idct_sample_range_limit = IntBuffer.allocate(sample_range_limit.capacity() - 128);
private static final int CONST_BITS = 13;
private static final int ONE_HALF = 4096;
static {
prepare_range_limit_table();
}
private static void prepare_range_limit_table() {
sample_range_limit.position(256);
for (int i1 = 0; i1 < 128; i1++)
sample_range_limit.put(i1);
for (int n = -128; n < 0; n++)
sample_range_limit.put(n);
for (int m = 0; m < 384; m++)
sample_range_limit.put(-1);
for (int k = 0; k < 384; k++)
sample_range_limit.put(0);
for (int j = 0; j < 128; j++)
sample_range_limit.put(j);
for (int i = 0; i < idct_sample_range_limit.capacity(); i++)
idct_sample_range_limit.put(sample_range_limit.get(i + 128) & 0xFF);
}
private static boolean shortcut(IntBuffer inptr, IntBuffer wsptr) {
if (inptr.get(8) == 0 && inptr.get(16) == 0 &&
inptr.get(24) == 0 && inptr.get(32) == 0 &&
inptr.get(40) == 0 && inptr.get(48) == 0 &&
inptr.get(56) == 0) {
int dcval = inptr.get(0) << 2;
wsptr.put(0, dcval);
wsptr.put(8, dcval);
wsptr.put(16, dcval);
wsptr.put(24, dcval);
wsptr.put(32, dcval);
wsptr.put(40, dcval);
wsptr.put(48, dcval);
wsptr.put(56, dcval);
inptr = advance(inptr);
wsptr = advance(wsptr);
return true;
}
return false;
}
private static void pass1(IntBuffer inptr, IntBuffer wsptr) {
for (int ctr = 8; ctr > 0; ctr--) {
int z2 = inptr.get(16);
int z3 = inptr.get(48);
int z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
int tmp2 = z1 + MULTIPLY(z3, -FIX_1_847759065);
int tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
z2 = inptr.get(0);
z3 = inptr.get(32);
int tmp0 = z2 + z3 << 13;
int tmp1 = z2 - z3 << 13;
int tmp10 = tmp0 + tmp3;
int tmp13 = tmp0 - tmp3;
int tmp11 = tmp1 + tmp2;
int tmp12 = tmp1 - tmp2;
tmp0 = inptr.get(56);
tmp1 = inptr.get(40);
tmp2 = inptr.get(24);
tmp3 = inptr.get(8);
z1 = tmp0 + tmp3;
z2 = tmp1 + tmp2;
z3 = tmp0 + tmp2;
int z4 = tmp1 + tmp3;
int z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
tmp0 = MULTIPLY(tmp0, FIX_0_298631336);
tmp1 = MULTIPLY(tmp1, FIX_2_053119869);
tmp2 = MULTIPLY(tmp2, FIX_3_072711026);
tmp3 = MULTIPLY(tmp3, FIX_1_501321110);
z1 = MULTIPLY(z1, -FIX_0_899976223);
z2 = MULTIPLY(z2, -FIX_2_562915447);
z3 = MULTIPLY(z3, -FIX_1_961570560);
z4 = MULTIPLY(z4, -FIX_0_390180644);
z3 += z5;
z4 += z5;
tmp0 += z1 + z3;
tmp1 += z2 + z4;
tmp2 += z2 + z3;
tmp3 += z1 + z4;
int D = 11;
wsptr.put(0, DESCALE(tmp10 + tmp3, D));
wsptr.put(56, DESCALE(tmp10 - tmp3, D));
wsptr.put(8, DESCALE(tmp11 + tmp2, D));
wsptr.put(48, DESCALE(tmp11 - tmp2, D));
wsptr.put(16, DESCALE(tmp12 + tmp1, D));
wsptr.put(40, DESCALE(tmp12 - tmp1, D));
wsptr.put(24, DESCALE(tmp13 + tmp0, D));
wsptr.put(32, DESCALE(tmp13 - tmp0, D));
inptr = advance(inptr);
wsptr = advance(wsptr);
}
}
private static IntBuffer advance(IntBuffer ptr) {
return doAdvance(ptr, 1);
}
private static IntBuffer doAdvance(IntBuffer ptr, int size) {
ptr.position(ptr.position() + size);
return ptr.slice();
}
static int DESCALE(int x, int n) {
return RIGHT_SHIFT(x + (1 << n - 1), n);
}
private static int RIGHT_SHIFT(int x, int shft) {
return x >> shft;
}
private static int MULTIPLY(int i, int j) {
return i * j;
}
private static int FIX(double x) {
return (int)(x * 8192.0D + 0.5D);
}
private static final int FIX_0_298631336 = FIX(0.298631336D);
private static final int FIX_0_390180644 = FIX(0.390180644D);
private static final int FIX_0_541196100 = FIX(0.5411961D);
private static final int FIX_0_765366865 = FIX(0.765366865D);
private static final int FIX_0_899976223 = FIX(0.899976223D);
private static final int FIX_1_175875602 = FIX(1.175875602D);
private static final int FIX_1_501321110 = FIX(1.50132111D);
private static final int FIX_1_847759065 = FIX(1.847759065D);
private static final int FIX_1_961570560 = FIX(1.96157056D);
private static final int FIX_2_053119869 = FIX(2.053119869D);
private static final int FIX_2_562915447 = FIX(2.562915447D);
private static final int FIX_3_072711026 = FIX(3.072711026D);
}

View file

@ -0,0 +1,203 @@
package org.jcodec.common.dct;
public class SimpleIDCT10Bit {
private static final int ROUND_COL = 8192;
private static final int ROUND_ROW = 32768;
private static final int SHIFT_COL = 14;
private static final int SHIFT_ROW = 16;
public static final int C0 = 23170;
public static final int C1 = 32138;
public static final int C2 = 27246;
public static final int C3 = 18205;
public static final int C4 = 6393;
public static final int C5 = 30274;
public static final int C6 = 12540;
public static int W1 = 90901;
public static int W2 = 85627;
public static int W3 = 77062;
public static int W4 = 65535;
public static int W5 = 51491;
public static int W6 = 35468;
public static int W7 = 18081;
public static int ROW_SHIFT = 15;
public static int COL_SHIFT = 20;
public static final void idct10(int[] buf, int off) {
for (int j = 0; j < 8; j++)
idctRow(buf, off + (j << 3));
for (int i = 0; i < 8; i++)
idctCol(buf, off + i);
}
private static final void idctCol(int[] buf, int off) {
int a0 = W4 * (buf[off + 0] + (1 << COL_SHIFT - 1) / W4);
int a1 = a0;
int a2 = a0;
int a3 = a0;
a0 += W2 * buf[off + 16];
a1 += W6 * buf[off + 16];
a2 += -W6 * buf[off + 16];
a3 += -W2 * buf[off + 16];
int b0 = W1 * buf[off + 8];
int b1 = W3 * buf[off + 8];
int b2 = W5 * buf[off + 8];
int b3 = W7 * buf[off + 8];
b0 += W3 * buf[off + 24];
b1 += -W7 * buf[off + 24];
b2 += -W1 * buf[off + 24];
b3 += -W5 * buf[off + 24];
if (buf[off + 32] != 0) {
a0 += W4 * buf[off + 32];
a1 += -W4 * buf[off + 32];
a2 += -W4 * buf[off + 32];
a3 += W4 * buf[off + 32];
}
if (buf[off + 40] != 0) {
b0 += W5 * buf[off + 40];
b1 += -W1 * buf[off + 40];
b2 += W7 * buf[off + 40];
b3 += W3 * buf[off + 40];
}
if (buf[off + 48] != 0) {
a0 += W6 * buf[off + 48];
a1 += -W2 * buf[off + 48];
a2 += W2 * buf[off + 48];
a3 += -W6 * buf[off + 48];
}
if (buf[off + 56] != 0) {
b0 += W7 * buf[off + 56];
b1 += -W5 * buf[off + 56];
b2 += W3 * buf[off + 56];
b3 += -W1 * buf[off + 56];
}
buf[off] = a0 + b0 >> COL_SHIFT;
buf[off + 8] = a1 + b1 >> COL_SHIFT;
buf[off + 16] = a2 + b2 >> COL_SHIFT;
buf[off + 24] = a3 + b3 >> COL_SHIFT;
buf[off + 32] = a3 - b3 >> COL_SHIFT;
buf[off + 40] = a2 - b2 >> COL_SHIFT;
buf[off + 48] = a1 - b1 >> COL_SHIFT;
buf[off + 56] = a0 - b0 >> COL_SHIFT;
}
private static final void idctRow(int[] buf, int off) {
int a0 = W4 * buf[off] + (1 << ROW_SHIFT - 1);
int a1 = a0;
int a2 = a0;
int a3 = a0;
a0 += W2 * buf[off + 2];
a1 += W6 * buf[off + 2];
a2 -= W6 * buf[off + 2];
a3 -= W2 * buf[off + 2];
int b0 = W1 * buf[off + 1];
b0 += W3 * buf[off + 3];
int b1 = W3 * buf[off + 1];
b1 += -W7 * buf[off + 3];
int b2 = W5 * buf[off + 1];
b2 += -W1 * buf[off + 3];
int b3 = W7 * buf[off + 1];
b3 += -W5 * buf[off + 3];
if (buf[off + 4] != 0 || buf[off + 5] != 0 || buf[off + 6] != 0 || buf[off + 7] != 0) {
a0 += W4 * buf[off + 4] + W6 * buf[off + 6];
a1 += -W4 * buf[off + 4] - W2 * buf[off + 6];
a2 += -W4 * buf[off + 4] + W2 * buf[off + 6];
a3 += W4 * buf[off + 4] - W6 * buf[off + 6];
b0 += W5 * buf[off + 5];
b0 += W7 * buf[off + 7];
b1 += -W1 * buf[off + 5];
b1 += -W5 * buf[off + 7];
b2 += W7 * buf[off + 5];
b2 += W3 * buf[off + 7];
b3 += W3 * buf[off + 5];
b3 += -W1 * buf[off + 7];
}
buf[off + 0] = a0 + b0 >> ROW_SHIFT;
buf[off + 7] = a0 - b0 >> ROW_SHIFT;
buf[off + 1] = a1 + b1 >> ROW_SHIFT;
buf[off + 6] = a1 - b1 >> ROW_SHIFT;
buf[off + 2] = a2 + b2 >> ROW_SHIFT;
buf[off + 5] = a2 - b2 >> ROW_SHIFT;
buf[off + 3] = a3 + b3 >> ROW_SHIFT;
buf[off + 4] = a3 - b3 >> ROW_SHIFT;
}
public static void fdctProres10(int[] block, int off) {
for (int j = 0; j < 8; j++)
fdctCol(block, off + j);
for (int i = 0; i < 64; i += 8)
fdctRow(block, off + i);
}
private static void fdctRow(int[] block, int off) {
int z0 = block[off + 0] - block[off + 7];
int z1 = block[off + 1] - block[off + 6];
int z2 = block[off + 2] - block[off + 5];
int z3 = block[off + 3] - block[off + 4];
int z4 = block[off + 0] + block[off + 7];
int z5 = block[off + 3] + block[off + 4];
int z6 = block[off + 1] + block[off + 6];
int z7 = block[off + 2] + block[off + 5];
int u0 = z4 - z5;
int u1 = z6 - z7;
int c0 = (z4 + z5) * 23170;
int c1 = (z6 + z7) * 23170;
int c2 = u0 * 30274;
int c3 = u1 * 12540;
int c4 = u0 * 12540;
int c5 = u1 * 30274;
block[1 + off] = z0 * 32138 + z1 * 27246 + z2 * 18205 + z3 * 6393 + 32768 >> 16;
block[3 + off] = z0 * 27246 - z1 * 6393 - z2 * 32138 - z3 * 18205 + 32768 >> 16;
block[5 + off] = z0 * 18205 - z1 * 32138 + z2 * 6393 + z3 * 27246 + 32768 >> 16;
block[7 + off] = z0 * 6393 - z1 * 18205 + z2 * 27246 - z3 * 32138 + 32768 >> 16;
block[0 + off] = c0 + c1 + 32768 >> 16;
block[2 + off] = c2 + c3 + 32768 >> 16;
block[4 + off] = c0 - c1 + 32768 >> 16;
block[6 + off] = c4 - c5 + 32768 >> 16;
}
private static void fdctCol(int[] block, int off) {
int z0 = block[off + 0] - block[off + 56];
int z1 = block[off + 8] - block[off + 48];
int z2 = block[off + 16] - block[off + 40];
int z3 = block[off + 24] - block[off + 32];
int z4 = block[off + 0] + block[off + 56];
int z5 = block[off + 24] + block[off + 32];
int z6 = block[off + 8] + block[off + 48];
int z7 = block[off + 16] + block[off + 40];
int u0 = z4 - z5;
int u1 = z6 - z7;
int c0 = (z4 + z5) * 23170;
int c1 = (z6 + z7) * 23170;
int c2 = u0 * 30274;
int c3 = u1 * 12540;
int c4 = u0 * 12540;
int c5 = u1 * 30274;
block[8 + off] = z0 * 32138 + z1 * 27246 + z2 * 18205 + z3 * 6393 + 8192 >> 14;
block[24 + off] = z0 * 27246 - z1 * 6393 - z2 * 32138 - z3 * 18205 + 8192 >> 14;
block[40 + off] = z0 * 18205 - z1 * 32138 + z2 * 6393 + z3 * 27246 + 8192 >> 14;
block[56 + off] = z0 * 6393 - z1 * 18205 + z2 * 27246 - z3 * 32138 + 8192 >> 14;
block[0 + off] = c0 + c1 + 8192 >> 14;
block[16 + off] = c2 + c3 + 8192 >> 14;
block[32 + off] = c0 - c1 + 8192 >> 14;
block[48 + off] = c4 - c5 + 8192 >> 14;
}
}

View file

@ -0,0 +1,59 @@
package org.jcodec.common.dct;
import org.jcodec.scale.ImageConvert;
public class SlowDCT extends DCT {
public static final SlowDCT INSTANCE = new SlowDCT();
private static final double rSqrt2 = 1.0D / Math.sqrt(2.0D);
public short[] encode(byte[] orig) {
short[] result = new short[64];
for (int u = 0; u < 8; u++) {
for (int v = 0; v < 8; v++) {
float sum = 0.0F;
for (int j = 0; j < 8; j++) {
for (int k = 0; k < 8; k++)
sum = (float)((double)sum + (double)(float)orig[j * 8 + k] * Math.cos(0.39269908169872414D * ((double)j + 0.5D) * (double)u) * Math.cos(0.39269908169872414D * ((double)k + 0.5D) * (double)v));
}
result[u * 8 + v] = (short)(byte)(int)sum;
}
}
result[0] = (short)(byte)(int)((float)result[0] / 8.0F);
double sqrt2 = Math.sqrt(2.0D);
for (int i = 1; i < 8; i++) {
result[i] = (short)(byte)(int)((double)(float)result[0] * sqrt2 / 8.0D);
result[i * 8] = (short)(byte)(int)((double)(float)result[0] * sqrt2 / 8.0D);
for (int j = 1; j < 8; j++)
result[i * 8 + j] = (short)(byte)(int)((float)result[0] / 4.0F);
}
return result;
}
public int[] decode(int[] orig) {
int[] res = new int[64];
int i = 0;
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
double sum = 0.0D;
int pixOffset = 0;
for (int u = 0; u < 8; u++) {
double cu = (u == 0) ? rSqrt2 : 1.0D;
for (int v = 0; v < 8; v++) {
double cv = (v == 0) ? rSqrt2 : 1.0D;
double svu = (double)orig[pixOffset];
double c1 = (double)((2 * x + 1) * v) * Math.PI / 16.0D;
double c2 = (double)((2 * y + 1) * u) * Math.PI / 16.0D;
sum += cu * cv * svu * Math.cos(c1) * Math.cos(c2);
pixOffset++;
}
}
sum *= 0.25D;
sum = (double)Math.round(sum + 128.0D);
int isum = (int)sum;
res[i++] = ImageConvert.icrop(isum);
}
}
return res;
}
}

View file

@ -0,0 +1,56 @@
package org.jcodec.common.dct;
import java.util.Arrays;
public class SparseIDCT {
public static final int[][] COEFF = new int[64][];
public static final int PRECISION = 13;
public static final int DC_SHIFT = 10;
static {
COEFF[0] = new int[64];
Arrays.fill(COEFF[0], 1024);
int ac = 8192;
for (int i = 1; i < 64; i++) {
COEFF[i] = new int[64];
COEFF[i][i] = ac;
SimpleIDCT10Bit.idct10(COEFF[i], 0);
}
}
public static final void start(int[] block, int dc) {
dc <<= 10;
for (int i = 0; i < 64; i += 4) {
block[i + 0] = dc;
block[i + 1] = dc;
block[i + 2] = dc;
block[i + 3] = dc;
}
}
public static final void coeff(int[] block, int ind, int level) {
for (int i = 0; i < 64; i += 4) {
block[i] = block[i] + COEFF[ind][i] * level;
block[i + 1] = block[i + 1] + COEFF[ind][i + 1] * level;
block[i + 2] = block[i + 2] + COEFF[ind][i + 2] * level;
block[i + 3] = block[i + 3] + COEFF[ind][i + 3] * level;
}
}
public static final void finish(int[] block) {
for (int i = 0; i < 64; i += 4) {
block[i] = div(block[i]);
block[i + 1] = div(block[i + 1]);
block[i + 2] = div(block[i + 2]);
block[i + 3] = div(block[i + 3]);
}
}
private static final int div(int x) {
int m = x >> 31;
int n = x >>> 31;
return ((x ^ m) + n >> 13 ^ m) + n;
}
}