www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -0,0 +1,78 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jcodec.common.model.ColorSpace;
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class ColorUtilHiBD {
|
||||
private static Map<ColorSpace, Map<ColorSpace, TransformHiBD>> map = new HashMap<>();
|
||||
|
||||
static {
|
||||
Map<ColorSpace, TransformHiBD> rgb = new HashMap<>();
|
||||
rgb.put(ColorSpace.RGB, new Idential());
|
||||
rgb.put(ColorSpace.YUV420, new RgbToYuv420pHiBD(0, 0));
|
||||
rgb.put(ColorSpace.YUV420J, new RgbToYuv420jHiBD());
|
||||
rgb.put(ColorSpace.YUV422, new RgbToYuv422pHiBD(0, 0));
|
||||
rgb.put(ColorSpace.YUV422_10, new RgbToYuv422pHiBD(2, 0));
|
||||
map.put(ColorSpace.RGB, rgb);
|
||||
Map<ColorSpace, TransformHiBD> yuv420 = new HashMap<>();
|
||||
yuv420.put(ColorSpace.YUV420, new Idential());
|
||||
yuv420.put(ColorSpace.RGB, new Yuv420pToRgbHiBD(0, 0));
|
||||
yuv420.put(ColorSpace.YUV422, new Yuv420pToYuv422pHiBD(0, 0));
|
||||
yuv420.put(ColorSpace.YUV422_10, new Yuv420pToYuv422pHiBD(0, 2));
|
||||
map.put(ColorSpace.YUV420, yuv420);
|
||||
Map<ColorSpace, TransformHiBD> yuv422 = new HashMap<>();
|
||||
yuv422.put(ColorSpace.YUV422, new Idential());
|
||||
yuv422.put(ColorSpace.RGB, new Yuv422pToRgbHiBD(0, 0));
|
||||
yuv422.put(ColorSpace.YUV420, new Yuv422pToYuv420pHiBD(0, 0));
|
||||
yuv422.put(ColorSpace.YUV420J, new Yuv422pToYuv420jHiBD(0, 0));
|
||||
map.put(ColorSpace.YUV422, yuv422);
|
||||
Map<ColorSpace, TransformHiBD> yuv422_10 = new HashMap<>();
|
||||
yuv422_10.put(ColorSpace.YUV422_10, new Idential());
|
||||
yuv422_10.put(ColorSpace.RGB, new Yuv422pToRgbHiBD(2, 0));
|
||||
yuv422_10.put(ColorSpace.YUV420, new Yuv422pToYuv420pHiBD(0, 2));
|
||||
yuv422_10.put(ColorSpace.YUV420J, new Yuv422pToYuv420jHiBD(0, 2));
|
||||
map.put(ColorSpace.YUV422_10, yuv422_10);
|
||||
Map<ColorSpace, TransformHiBD> yuv444 = new HashMap<>();
|
||||
yuv444.put(ColorSpace.YUV444, new Idential());
|
||||
yuv444.put(ColorSpace.RGB, new Yuv444pToRgb(0, 0));
|
||||
yuv444.put(ColorSpace.YUV420, new Yuv444pToYuv420pHiBD(0, 0));
|
||||
map.put(ColorSpace.YUV444, yuv444);
|
||||
Map<ColorSpace, TransformHiBD> yuv444_10 = new HashMap<>();
|
||||
yuv444_10.put(ColorSpace.YUV444_10, new Idential());
|
||||
yuv444_10.put(ColorSpace.RGB, new Yuv444pToRgb(2, 0));
|
||||
yuv444_10.put(ColorSpace.YUV420, new Yuv444pToYuv420pHiBD(0, 2));
|
||||
map.put(ColorSpace.YUV444_10, yuv444_10);
|
||||
Map<ColorSpace, TransformHiBD> yuv420j = new HashMap<>();
|
||||
yuv420j.put(ColorSpace.YUV420J, new Idential());
|
||||
yuv420j.put(ColorSpace.RGB, new Yuv420jToRgbHiBD());
|
||||
yuv420j.put(ColorSpace.YUV420, new Yuv420jToYuv420HiBD());
|
||||
map.put(ColorSpace.YUV420J, yuv420j);
|
||||
Map<ColorSpace, TransformHiBD> yuv422j = new HashMap<>();
|
||||
yuv422j.put(ColorSpace.YUV422J, new Idential());
|
||||
yuv422j.put(ColorSpace.RGB, new Yuv422jToRgbHiBD());
|
||||
yuv422j.put(ColorSpace.YUV420, new Yuv422jToYuv420pHiBD());
|
||||
yuv422j.put(ColorSpace.YUV420J, new Yuv422pToYuv420pHiBD(0, 0));
|
||||
map.put(ColorSpace.YUV422J, yuv422j);
|
||||
Map<ColorSpace, TransformHiBD> yuv444j = new HashMap<>();
|
||||
yuv444j.put(ColorSpace.YUV444J, new Idential());
|
||||
yuv444j.put(ColorSpace.RGB, new Yuv444jToRgbHiBD());
|
||||
yuv444j.put(ColorSpace.YUV420, new Yuv444jToYuv420pHiBD());
|
||||
yuv444j.put(ColorSpace.YUV420J, new Yuv444pToYuv420pHiBD(0, 0));
|
||||
map.put(ColorSpace.YUV444J, yuv444j);
|
||||
}
|
||||
|
||||
public static TransformHiBD getTransform(ColorSpace from, ColorSpace to) {
|
||||
Map<ColorSpace, TransformHiBD> map2 = map.get(from);
|
||||
return (map2 == null) ? null : map2.get(to);
|
||||
}
|
||||
|
||||
public static class Idential implements TransformHiBD {
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
for (int i = 0; i < 3; i++)
|
||||
System.arraycopy(src.getPlaneData(i), 0, dst.getPlaneData(i), 0, Math.min(
|
||||
src.getPlaneWidth(i) * src.getPlaneHeight(i), dst.getPlaneWidth(i) * dst.getPlaneHeight(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.api.NotSupportedException;
|
||||
import org.jcodec.common.model.ColorSpace;
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
@Deprecated
|
||||
public class RgbToBgrHiBD implements TransformHiBD {
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
if ((src.getColor() != ColorSpace.RGB && src.getColor() != ColorSpace.BGR) || (
|
||||
dst.getColor() != ColorSpace.RGB && dst.getColor() != ColorSpace.BGR))
|
||||
throw new IllegalArgumentException("Expected RGB or BGR inputs, was: " +
|
||||
String.valueOf(src.getColor()) + ", " + String.valueOf(dst.getColor()));
|
||||
if (src.getCrop() != null || dst.getCrop() != null)
|
||||
throw new NotSupportedException("Cropped images not supported");
|
||||
int[] dataSrc = src.getPlaneData(0);
|
||||
int[] dataDst = dst.getPlaneData(0);
|
||||
for (int i = 0; i < dataSrc.length; i += 3) {
|
||||
int tmp = dataSrc[i + 2];
|
||||
dataDst[i + 2] = dataSrc[i];
|
||||
dataDst[i] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class RgbToYuv420jHiBD implements TransformHiBD {
|
||||
public void transform(PictureHiBD img, PictureHiBD dst) {
|
||||
int[] y = img.getData()[0];
|
||||
int[][] dstData = dst.getData();
|
||||
int offChr = 0, offLuma = 0, offSrc = 0, strideSrc = img.getWidth() * 3, strideDst = dst.getWidth();
|
||||
for (int i = 0; i < img.getHeight() >> 1; i++) {
|
||||
for (int j = 0; j < img.getWidth() >> 1; j++) {
|
||||
dstData[1][offChr] = 0;
|
||||
dstData[2][offChr] = 0;
|
||||
rgb2yuv(y[offSrc], y[offSrc + 1], y[offSrc + 2], dstData[0], offLuma, dstData[1], offChr, dstData[2], offChr);
|
||||
dstData[0][offLuma] = dstData[0][offLuma];
|
||||
rgb2yuv(y[offSrc + strideSrc], y[offSrc + strideSrc + 1], y[offSrc + strideSrc + 2], dstData[0], offLuma + strideDst, dstData[1], offChr, dstData[2], offChr);
|
||||
dstData[0][offLuma + strideDst] = dstData[0][offLuma + strideDst];
|
||||
offLuma++;
|
||||
rgb2yuv(y[offSrc + 3], y[offSrc + 4], y[offSrc + 5], dstData[0], offLuma, dstData[1], offChr, dstData[2], offChr);
|
||||
dstData[0][offLuma] = dstData[0][offLuma];
|
||||
rgb2yuv(y[offSrc + strideSrc + 3], y[offSrc + strideSrc + 4], y[offSrc + strideSrc + 5], dstData[0], offLuma + strideDst, dstData[1], offChr, dstData[2], offChr);
|
||||
dstData[0][offLuma + strideDst] = dstData[0][offLuma + strideDst];
|
||||
offLuma++;
|
||||
dstData[1][offChr] = dstData[1][offChr] >> 2;
|
||||
dstData[2][offChr] = dstData[2][offChr] >> 2;
|
||||
offChr++;
|
||||
offSrc += 6;
|
||||
}
|
||||
offLuma += strideDst;
|
||||
offSrc += strideSrc;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void rgb2yuv(int r, int g, int b, int[] Y, int offY, int[] U, int offU, int[] V, int offV) {
|
||||
int y = 77 * r + 150 * g + 15 * b;
|
||||
int u = -43 * r - 85 * g + 128 * b;
|
||||
int v = 128 * r - 107 * g - 21 * b;
|
||||
y = y + 128 >> 8;
|
||||
u = u + 128 >> 8;
|
||||
v = v + 128 >> 8;
|
||||
Y[offY] = clip(y);
|
||||
U[offU] = U[offU] + clip(u + 128);
|
||||
V[offV] = V[offV] + clip(v + 128);
|
||||
}
|
||||
|
||||
private static final int clip(int val) {
|
||||
return (val < 0) ? 0 : ((val > 255) ? 255 : val);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class RgbToYuv420pHiBD implements TransformHiBD {
|
||||
private int upShift;
|
||||
|
||||
private int downShift;
|
||||
|
||||
private int downShiftChr;
|
||||
|
||||
public RgbToYuv420pHiBD(int upShift, int downShift) {
|
||||
this.upShift = upShift;
|
||||
this.downShift = downShift;
|
||||
this.downShiftChr = downShift + 2;
|
||||
}
|
||||
|
||||
public void transform(PictureHiBD img, PictureHiBD dst) {
|
||||
int[] y = img.getData()[0];
|
||||
int[][] dstData = dst.getData();
|
||||
int offChr = 0, offLuma = 0, offSrc = 0, strideSrc = img.getWidth() * 3, strideDst = dst.getWidth();
|
||||
for (int i = 0; i < img.getHeight() >> 1; i++) {
|
||||
for (int j = 0; j < img.getWidth() >> 1; j++) {
|
||||
dstData[1][offChr] = 0;
|
||||
dstData[2][offChr] = 0;
|
||||
rgb2yuv(y[offSrc], y[offSrc + 1], y[offSrc + 2], dstData[0], offLuma, dstData[1], offChr, dstData[2], offChr);
|
||||
dstData[0][offLuma] = dstData[0][offLuma] << this.upShift >> this.downShift;
|
||||
rgb2yuv(y[offSrc + strideSrc], y[offSrc + strideSrc + 1], y[offSrc + strideSrc + 2], dstData[0], offLuma + strideDst, dstData[1], offChr, dstData[2], offChr);
|
||||
dstData[0][offLuma + strideDst] = dstData[0][offLuma + strideDst] << this.upShift >> this.downShift;
|
||||
offLuma++;
|
||||
rgb2yuv(y[offSrc + 3], y[offSrc + 4], y[offSrc + 5], dstData[0], offLuma, dstData[1], offChr, dstData[2], offChr);
|
||||
dstData[0][offLuma] = dstData[0][offLuma] << this.upShift >> this.downShift;
|
||||
rgb2yuv(y[offSrc + strideSrc + 3], y[offSrc + strideSrc + 4], y[offSrc + strideSrc + 5], dstData[0], offLuma + strideDst, dstData[1], offChr, dstData[2], offChr);
|
||||
dstData[0][offLuma + strideDst] = dstData[0][offLuma + strideDst] << this.upShift >> this.downShift;
|
||||
offLuma++;
|
||||
dstData[1][offChr] = dstData[1][offChr] << this.upShift >> this.downShiftChr;
|
||||
dstData[2][offChr] = dstData[2][offChr] << this.upShift >> this.downShiftChr;
|
||||
offChr++;
|
||||
offSrc += 6;
|
||||
}
|
||||
offLuma += strideDst;
|
||||
offSrc += strideSrc;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void rgb2yuv(int r, int g, int b, int[] Y, int offY, int[] U, int offU, int[] V, int offV) {
|
||||
int y = 66 * r + 129 * g + 25 * b;
|
||||
int u = -38 * r - 74 * g + 112 * b;
|
||||
int v = 112 * r - 94 * g - 18 * b;
|
||||
y = y + 128 >> 8;
|
||||
u = u + 128 >> 8;
|
||||
v = v + 128 >> 8;
|
||||
Y[offY] = clip(y + 16);
|
||||
U[offU] = U[offU] + clip(u + 128);
|
||||
V[offV] = V[offV] + clip(v + 128);
|
||||
}
|
||||
|
||||
private static final int clip(int val) {
|
||||
return (val < 0) ? 0 : ((val > 255) ? 255 : val);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class RgbToYuv422pHiBD implements TransformHiBD {
|
||||
private int upShift;
|
||||
|
||||
private int downShift;
|
||||
|
||||
private int downShiftChr;
|
||||
|
||||
public RgbToYuv422pHiBD(int upShift, int downShift) {
|
||||
this.upShift = upShift;
|
||||
this.downShift = downShift;
|
||||
this.downShiftChr = downShift + 1;
|
||||
}
|
||||
|
||||
public void transform(PictureHiBD img, PictureHiBD dst) {
|
||||
int[] y = img.getData()[0];
|
||||
int[][] dstData = dst.getData();
|
||||
int off = 0, offSrc = 0;
|
||||
for (int i = 0; i < img.getHeight(); i++) {
|
||||
for (int j = 0; j < img.getWidth() >> 1; j++) {
|
||||
dstData[1][off] = 0;
|
||||
dstData[2][off] = 0;
|
||||
int offY = off << 1;
|
||||
RgbToYuv420pHiBD.rgb2yuv(y[offSrc++], y[offSrc++], y[offSrc++], dstData[0], offY, dstData[1], off, dstData[2], off);
|
||||
dstData[0][offY] = dstData[0][offY] << this.upShift >> this.downShift;
|
||||
RgbToYuv420pHiBD.rgb2yuv(y[offSrc++], y[offSrc++], y[offSrc++], dstData[0], offY + 1, dstData[1], off, dstData[2], off);
|
||||
dstData[0][offY + 1] = dstData[0][offY + 1] << this.upShift >> this.downShift;
|
||||
dstData[1][off] = dstData[1][off] << this.upShift >> this.downShiftChr;
|
||||
dstData[2][off] = dstData[2][off] << this.upShift >> this.downShiftChr;
|
||||
off++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public interface TransformHiBD {
|
||||
void transform(PictureHiBD paramPictureHiBD1, PictureHiBD paramPictureHiBD2);
|
||||
|
||||
public enum Levels {
|
||||
STUDIO, PC;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
import org.jcodec.common.tools.MathUtil;
|
||||
|
||||
public class Yuv420jToRgbHiBD implements TransformHiBD {
|
||||
private static final int SCALEBITS = 10;
|
||||
|
||||
private static final int ONE_HALF = 512;
|
||||
|
||||
public final void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] y = src.getPlaneData(0);
|
||||
int[] u = src.getPlaneData(1);
|
||||
int[] v = src.getPlaneData(2);
|
||||
int[] data = dst.getPlaneData(0);
|
||||
int offLuma = 0, offChroma = 0;
|
||||
int stride = dst.getWidth();
|
||||
for (int i = 0; i < dst.getHeight() >> 1; i++) {
|
||||
for (int k = 0; k < dst.getWidth() >> 1; k++) {
|
||||
int j = k << 1;
|
||||
YUVJtoRGB(y[offLuma + j], u[offChroma], v[offChroma], data, (offLuma + j) * 3);
|
||||
YUVJtoRGB(y[offLuma + j + 1], u[offChroma], v[offChroma], data, (offLuma + j + 1) * 3);
|
||||
YUVJtoRGB(y[offLuma + j + stride], u[offChroma], v[offChroma], data, (offLuma + j + stride) * 3);
|
||||
YUVJtoRGB(y[offLuma + j + stride + 1], u[offChroma], v[offChroma], data, (offLuma + j + stride + 1) * 3);
|
||||
offChroma++;
|
||||
}
|
||||
if ((dst.getWidth() & 0x1) != 0) {
|
||||
int j = dst.getWidth() - 1;
|
||||
YUVJtoRGB(y[offLuma + j], u[offChroma], v[offChroma], data, (offLuma + j) * 3);
|
||||
YUVJtoRGB(y[offLuma + j + stride], u[offChroma], v[offChroma], data, (offLuma + j + stride) * 3);
|
||||
offChroma++;
|
||||
}
|
||||
offLuma += 2 * stride;
|
||||
}
|
||||
if ((dst.getHeight() & 0x1) != 0) {
|
||||
for (int k = 0; k < dst.getWidth() >> 1; k++) {
|
||||
int j = k << 1;
|
||||
YUVJtoRGB(y[offLuma + j], u[offChroma], v[offChroma], data, (offLuma + j) * 3);
|
||||
YUVJtoRGB(y[offLuma + j + 1], u[offChroma], v[offChroma], data, (offLuma + j + 1) * 3);
|
||||
offChroma++;
|
||||
}
|
||||
if ((dst.getWidth() & 0x1) != 0) {
|
||||
int j = dst.getWidth() - 1;
|
||||
YUVJtoRGB(y[offLuma + j], u[offChroma], v[offChroma], data, (offLuma + j) * 3);
|
||||
offChroma++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final int FIX(double x) {
|
||||
return (int)(x * 1024.0D + 0.5D);
|
||||
}
|
||||
|
||||
private static final int FIX_0_71414 = FIX(0.71414D);
|
||||
|
||||
private static final int FIX_1_772 = FIX(1.772D);
|
||||
|
||||
private static final int _FIX_0_34414 = -FIX(0.34414D);
|
||||
|
||||
private static final int FIX_1_402 = FIX(1.402D);
|
||||
|
||||
public static final void YUVJtoRGB(int y, int cb, int cr, int[] data, int off) {
|
||||
y <<= 10;
|
||||
cb -= 128;
|
||||
cr -= 128;
|
||||
int add_r = FIX_1_402 * cr + 512;
|
||||
int add_g = _FIX_0_34414 * cb - FIX_0_71414 * cr + 512;
|
||||
int add_b = FIX_1_772 * cb + 512;
|
||||
int r = y + add_r >> 10;
|
||||
int g = y + add_g >> 10;
|
||||
int b = y + add_b >> 10;
|
||||
data[off] = MathUtil.clip(r, 0, 255);
|
||||
data[off + 1] = MathUtil.clip(g, 0, 255);
|
||||
data[off + 2] = MathUtil.clip(b, 0, 255);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv420jToYuv420HiBD implements TransformHiBD {
|
||||
public static int Y_COEFF = 7168;
|
||||
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] sy = src.getPlaneData(0);
|
||||
int[] dy = dst.getPlaneData(0);
|
||||
for (int i = 0; i < src.getPlaneWidth(0) * src.getPlaneHeight(0); i++)
|
||||
dy[i] = (sy[i] * Y_COEFF >> 13) + 16;
|
||||
int[] su = src.getPlaneData(1);
|
||||
int[] du = dst.getPlaneData(1);
|
||||
for (int j = 0; j < src.getPlaneWidth(1) * src.getPlaneHeight(1); j++)
|
||||
du[j] = ((su[j] - 128) * Y_COEFF >> 13) + 128;
|
||||
int[] sv = src.getPlaneData(2);
|
||||
int[] dv = dst.getPlaneData(2);
|
||||
for (int k = 0; k < src.getPlaneWidth(2) * src.getPlaneHeight(2); k++)
|
||||
dv[k] = ((sv[k] - 128) * Y_COEFF >> 13) + 128;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv420pToRgbHiBD implements TransformHiBD {
|
||||
private final int downShift;
|
||||
|
||||
private final int upShift;
|
||||
|
||||
public Yuv420pToRgbHiBD(int upShift, int downShift) {
|
||||
this.upShift = upShift;
|
||||
this.downShift = downShift;
|
||||
}
|
||||
|
||||
public final void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] y = src.getPlaneData(0);
|
||||
int[] u = src.getPlaneData(1);
|
||||
int[] v = src.getPlaneData(2);
|
||||
int[] data = dst.getPlaneData(0);
|
||||
int offLuma = 0, offChroma = 0;
|
||||
int stride = dst.getWidth();
|
||||
for (int i = 0; i < dst.getHeight() >> 1; i++) {
|
||||
for (int k = 0; k < dst.getWidth() >> 1; k++) {
|
||||
int j = k << 1;
|
||||
Yuv422pToRgbHiBD.YUV444toRGB888(y[offLuma + j] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + j) * 3);
|
||||
Yuv422pToRgbHiBD.YUV444toRGB888(y[offLuma + j + 1] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + j + 1) * 3);
|
||||
Yuv422pToRgbHiBD.YUV444toRGB888(y[offLuma + j + stride] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + j + stride) * 3);
|
||||
Yuv422pToRgbHiBD.YUV444toRGB888(y[offLuma + j + stride + 1] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + j + stride + 1) * 3);
|
||||
offChroma++;
|
||||
}
|
||||
if ((dst.getWidth() & 0x1) != 0) {
|
||||
int j = dst.getWidth() - 1;
|
||||
Yuv422pToRgbHiBD.YUV444toRGB888(y[offLuma + j] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + j) * 3);
|
||||
Yuv422pToRgbHiBD.YUV444toRGB888(y[offLuma + j + stride] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + j + stride) * 3);
|
||||
offChroma++;
|
||||
}
|
||||
offLuma += 2 * stride;
|
||||
}
|
||||
if ((dst.getHeight() & 0x1) != 0) {
|
||||
for (int k = 0; k < dst.getWidth() >> 1; k++) {
|
||||
int j = k << 1;
|
||||
Yuv422pToRgbHiBD.YUV444toRGB888(y[offLuma + j] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + j) * 3);
|
||||
Yuv422pToRgbHiBD.YUV444toRGB888(y[offLuma + j + 1] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + j + 1) * 3);
|
||||
offChroma++;
|
||||
}
|
||||
if ((dst.getWidth() & 0x1) != 0) {
|
||||
int j = dst.getWidth() - 1;
|
||||
Yuv422pToRgbHiBD.YUV444toRGB888(y[offLuma + j] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + j) * 3);
|
||||
offChroma++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv420pToYuv422pHiBD implements TransformHiBD {
|
||||
private int shiftUp;
|
||||
|
||||
private int shiftDown;
|
||||
|
||||
public Yuv420pToYuv422pHiBD(int shiftUp, int shiftDown) {
|
||||
this.shiftUp = shiftUp;
|
||||
this.shiftDown = shiftDown;
|
||||
}
|
||||
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
copy(src.getPlaneData(0), dst.getPlaneData(0), src.getWidth(), dst.getWidth(), dst.getHeight(), this.shiftUp, this.shiftDown);
|
||||
_copy(src.getPlaneData(1), dst.getPlaneData(1), 0, 0, 1, 2, src.getWidth() >> 1, dst.getWidth() >> 1,
|
||||
src.getHeight() >> 1, dst.getHeight(), this.shiftUp, this.shiftDown);
|
||||
_copy(src.getPlaneData(1), dst.getPlaneData(1), 0, 1, 1, 2, src.getWidth() >> 1, dst.getWidth() >> 1,
|
||||
src.getHeight() >> 1, dst.getHeight(), this.shiftUp, this.shiftDown);
|
||||
_copy(src.getPlaneData(2), dst.getPlaneData(2), 0, 0, 1, 2, src.getWidth() >> 1, dst.getWidth() >> 1,
|
||||
src.getHeight() >> 1, dst.getHeight(), this.shiftUp, this.shiftDown);
|
||||
_copy(src.getPlaneData(2), dst.getPlaneData(2), 0, 1, 1, 2, src.getWidth() >> 1, dst.getWidth() >> 1,
|
||||
src.getHeight() >> 1, dst.getHeight(), this.shiftUp, this.shiftDown);
|
||||
}
|
||||
|
||||
private static final void _copy(int[] src, int[] dest, int offX, int offY, int stepX, int stepY, int strideSrc, int strideDest, int heightSrc, int heightDst, int upShift, int downShift) {
|
||||
int offD = offX + offY * strideDest, srcOff = 0;
|
||||
for (int i = 0; i < heightSrc; i++) {
|
||||
for (int k = 0; k < strideSrc; k++) {
|
||||
dest[offD] = (src[srcOff++] & 0xFF) << 2;
|
||||
offD += stepX;
|
||||
}
|
||||
int lastOff = offD - stepX;
|
||||
for (int m = strideSrc * stepX; m < strideDest; m += stepX) {
|
||||
dest[offD] = dest[lastOff];
|
||||
offD += stepX;
|
||||
}
|
||||
offD += (stepY - 1) * strideDest;
|
||||
}
|
||||
int lastLine = offD - stepY * strideDest;
|
||||
for (int j = heightSrc * stepY; j < heightDst; j += stepY) {
|
||||
for (int k = 0; k < strideDest; k += stepX) {
|
||||
dest[offD] = dest[lastLine + k];
|
||||
offD += stepX;
|
||||
}
|
||||
offD += (stepY - 1) * strideDest;
|
||||
}
|
||||
}
|
||||
|
||||
private static void copy(int[] src, int[] dest, int srcWidth, int dstWidth, int dstHeight, int shiftUp, int shiftDown) {
|
||||
int height = src.length / srcWidth;
|
||||
int dstOff = 0, srcOff = 0;
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int m = 0; m < srcWidth; m++)
|
||||
dest[dstOff++] = (src[srcOff++] & 0xFF) << 2;
|
||||
for (int k = srcWidth; k < dstWidth; k++)
|
||||
dest[dstOff++] = dest[srcWidth - 1];
|
||||
}
|
||||
int lastLine = (height - 1) * dstWidth;
|
||||
for (int j = height; j < dstHeight; j++) {
|
||||
for (int k = 0; k < dstWidth; k++)
|
||||
dest[dstOff++] = dest[lastLine + k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv422jToRgbHiBD implements TransformHiBD {
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] y = src.getPlaneData(0);
|
||||
int[] u = src.getPlaneData(1);
|
||||
int[] v = src.getPlaneData(2);
|
||||
int[] data = dst.getPlaneData(0);
|
||||
int offLuma = 0, offChroma = 0;
|
||||
for (int i = 0; i < dst.getHeight(); i++) {
|
||||
for (int j = 0; j < dst.getWidth(); j += 2) {
|
||||
Yuv420jToRgbHiBD.YUVJtoRGB(y[offLuma], u[offChroma], v[offChroma], data, offLuma * 3);
|
||||
Yuv420jToRgbHiBD.YUVJtoRGB(y[offLuma + 1], u[offChroma], v[offChroma], data, (offLuma + 1) * 3);
|
||||
offLuma += 2;
|
||||
offChroma++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv422jToYuv420pHiBD implements TransformHiBD {
|
||||
public static int Y_COEFF = 7168;
|
||||
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] sy = src.getPlaneData(0);
|
||||
int[] dy = dst.getPlaneData(0);
|
||||
for (int i = 0; i < src.getPlaneWidth(0) * src.getPlaneHeight(0); i++)
|
||||
dy[i] = (sy[i] * Y_COEFF >> 13) + 16;
|
||||
copyAvg(src.getPlaneData(1), dst.getPlaneData(1), src.getPlaneWidth(1), src.getPlaneHeight(1));
|
||||
copyAvg(src.getPlaneData(2), dst.getPlaneData(2), src.getPlaneWidth(2), src.getPlaneHeight(2));
|
||||
}
|
||||
|
||||
private void copyAvg(int[] src, int[] dst, int width, int height) {
|
||||
int offSrc = 0, offDst = 0;
|
||||
for (int y = 0; y < height / 2; y++) {
|
||||
for (int x = 0; x < width; x++, offDst++, offSrc++) {
|
||||
int a = ((src[offSrc] - 128) * Y_COEFF >> 13) + 128;
|
||||
int b = ((src[offSrc + width] - 128) * Y_COEFF >> 13) + 128;
|
||||
dst[offDst] = a + b + 1 >> 1;
|
||||
}
|
||||
offSrc += width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv422pToRgbHiBD implements TransformHiBD {
|
||||
private int downShift;
|
||||
|
||||
private int upShift;
|
||||
|
||||
public Yuv422pToRgbHiBD(int downShift, int upShift) {
|
||||
this.downShift = downShift;
|
||||
this.upShift = upShift;
|
||||
}
|
||||
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] y = src.getPlaneData(0);
|
||||
int[] u = src.getPlaneData(1);
|
||||
int[] v = src.getPlaneData(2);
|
||||
int[] data = dst.getPlaneData(0);
|
||||
int offLuma = 0, offChroma = 0;
|
||||
for (int i = 0; i < dst.getHeight(); i++) {
|
||||
for (int j = 0; j < dst.getWidth(); j += 2) {
|
||||
YUV444toRGB888(y[offLuma] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, offLuma * 3);
|
||||
YUV444toRGB888(y[offLuma + 1] << this.upShift >> this.downShift, u[offChroma] << this.upShift >> this.downShift, v[offChroma] << this.upShift >> this.downShift, data, (offLuma + 1) * 3);
|
||||
offLuma += 2;
|
||||
offChroma++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final void YUV444toRGB888(int y, int u, int v, int[] data, int off) {
|
||||
int c = y - 16;
|
||||
int d = u - 128;
|
||||
int e = v - 128;
|
||||
int r = 298 * c + 409 * e + 128 >> 8;
|
||||
int g = 298 * c - 100 * d - 208 * e + 128 >> 8;
|
||||
int b = 298 * c + 516 * d + 128 >> 8;
|
||||
data[off] = crop(r);
|
||||
data[off + 1] = crop(g);
|
||||
data[off + 2] = crop(b);
|
||||
}
|
||||
|
||||
private static int crop(int val) {
|
||||
return (val < 0) ? 0 : ((val > 255) ? 255 : val);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv422pToYuv420jHiBD implements TransformHiBD {
|
||||
public static int COEFF = 9362;
|
||||
|
||||
private int shift;
|
||||
|
||||
private int halfSrc;
|
||||
|
||||
private int halfDst;
|
||||
|
||||
public Yuv422pToYuv420jHiBD(int upshift, int downshift) {
|
||||
this.shift = downshift + 13 - upshift;
|
||||
if (this.shift < 0)
|
||||
throw new IllegalArgumentException("Maximum upshift allowed: " + downshift + 13);
|
||||
this.halfSrc = 128 << Math.max(downshift - upshift, 0);
|
||||
this.halfDst = 128 << Math.max(upshift - downshift, 0);
|
||||
}
|
||||
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] sy = src.getPlaneData(0);
|
||||
int[] dy = dst.getPlaneData(0);
|
||||
for (int i = 0; i < src.getPlaneWidth(0) * src.getPlaneHeight(0); i++)
|
||||
dy[i] = (sy[i] - 16) * COEFF >> this.shift;
|
||||
copyAvg(src.getPlaneData(1), dst.getPlaneData(1), src.getPlaneWidth(1), src.getPlaneHeight(1));
|
||||
copyAvg(src.getPlaneData(2), dst.getPlaneData(2), src.getPlaneWidth(2), src.getPlaneHeight(2));
|
||||
}
|
||||
|
||||
private void copyAvg(int[] src, int[] dst, int width, int height) {
|
||||
int offSrc = 0, offDst = 0;
|
||||
for (int y = 0; y < height / 2; y++) {
|
||||
for (int x = 0; x < width; x++, offDst++, offSrc++) {
|
||||
int a = ((src[offSrc] - this.halfSrc) * COEFF >> this.shift) + this.halfDst;
|
||||
int b = ((src[offSrc + width] - this.halfSrc) * COEFF >> this.shift) + this.halfDst;
|
||||
dst[offDst] = a + b + 1 >> 1;
|
||||
}
|
||||
offSrc += width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv422pToYuv420pHiBD implements TransformHiBD {
|
||||
private int shiftUp;
|
||||
|
||||
private int shiftDown;
|
||||
|
||||
public Yuv422pToYuv420pHiBD(int shiftUp, int shiftDown) {
|
||||
this.shiftUp = shiftUp;
|
||||
this.shiftDown = shiftDown;
|
||||
}
|
||||
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int lumaSize = src.getWidth() * src.getHeight();
|
||||
System.arraycopy(src.getPlaneData(0), 0, dst.getPlaneData(0), 0, lumaSize);
|
||||
copyAvg(src.getPlaneData(1), dst.getPlaneData(1), src.getPlaneWidth(1), src.getPlaneHeight(1));
|
||||
copyAvg(src.getPlaneData(2), dst.getPlaneData(2), src.getPlaneWidth(2), src.getPlaneHeight(2));
|
||||
if (this.shiftUp > this.shiftDown) {
|
||||
up(dst.getPlaneData(0), this.shiftUp - this.shiftDown);
|
||||
up(dst.getPlaneData(1), this.shiftUp - this.shiftDown);
|
||||
up(dst.getPlaneData(2), this.shiftUp - this.shiftDown);
|
||||
} else if (this.shiftDown > this.shiftUp) {
|
||||
down(dst.getPlaneData(0), this.shiftDown - this.shiftUp);
|
||||
down(dst.getPlaneData(1), this.shiftDown - this.shiftUp);
|
||||
down(dst.getPlaneData(2), this.shiftDown - this.shiftUp);
|
||||
}
|
||||
}
|
||||
|
||||
private void down(int[] dst, int down) {
|
||||
for (int i = 0; i < dst.length; i++)
|
||||
dst[i] = dst[i] >> down;
|
||||
}
|
||||
|
||||
private void up(int[] dst, int up) {
|
||||
for (int i = 0; i < dst.length; i++)
|
||||
dst[i] = dst[i] << up;
|
||||
}
|
||||
|
||||
private void copyAvg(int[] src, int[] dst, int width, int height) {
|
||||
int offSrc = 0, offDst = 0;
|
||||
for (int y = 0; y < height / 2; y++) {
|
||||
for (int x = 0; x < width; x++, offDst++, offSrc++)
|
||||
dst[offDst] = src[offSrc] + src[offSrc + width] + 1 >> 1;
|
||||
offSrc += width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv444jToRgbHiBD implements TransformHiBD {
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] y = src.getPlaneData(0);
|
||||
int[] u = src.getPlaneData(1);
|
||||
int[] v = src.getPlaneData(2);
|
||||
int[] data = dst.getPlaneData(0);
|
||||
for (int i = 0, srcOff = 0, dstOff = 0; i < dst.getHeight(); i++) {
|
||||
for (int j = 0; j < dst.getWidth(); j++, srcOff++, dstOff += 3)
|
||||
Yuv420jToRgbHiBD.YUVJtoRGB(y[srcOff], u[srcOff], v[srcOff], data, dstOff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv444jToYuv420pHiBD implements TransformHiBD {
|
||||
public static int Y_COEFF = 7168;
|
||||
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] sy = src.getPlaneData(0);
|
||||
int[] dy = dst.getPlaneData(0);
|
||||
for (int i = 0; i < src.getPlaneWidth(0) * src.getPlaneHeight(0); i++)
|
||||
dy[i] = (sy[i] * Y_COEFF >> 13) + 16;
|
||||
copyAvg(src.getPlaneData(1), dst.getPlaneData(1), src.getPlaneWidth(1), src.getPlaneHeight(1));
|
||||
copyAvg(src.getPlaneData(2), dst.getPlaneData(2), src.getPlaneWidth(2), src.getPlaneHeight(2));
|
||||
}
|
||||
|
||||
private void copyAvg(int[] src, int[] dst, int width, int height) {
|
||||
int offSrc = 0, offDst = 0;
|
||||
for (int y = 0; y < height >> 1; y++) {
|
||||
for (int x = 0; x < width; x += 2, offDst++, offSrc += 2) {
|
||||
int a = ((src[offSrc] - 128) * Y_COEFF >> 13) + 128;
|
||||
int b = ((src[offSrc + 1] - 128) * Y_COEFF >> 13) + 128;
|
||||
int c = ((src[offSrc + width] - 128) * Y_COEFF >> 13) + 128;
|
||||
int d = ((src[offSrc + width + 1] - 128) * Y_COEFF >> 13) + 128;
|
||||
dst[offDst] = a + b + c + d + 2 >> 2;
|
||||
}
|
||||
offSrc += width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv444pToRgb implements TransformHiBD {
|
||||
private int downShift;
|
||||
|
||||
private int upShift;
|
||||
|
||||
public Yuv444pToRgb(int downShift, int upShift) {
|
||||
this.downShift = downShift;
|
||||
this.upShift = upShift;
|
||||
}
|
||||
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int[] y = src.getPlaneData(0);
|
||||
int[] u = src.getPlaneData(1);
|
||||
int[] v = src.getPlaneData(2);
|
||||
int[] data = dst.getPlaneData(0);
|
||||
for (int i = 0, srcOff = 0, dstOff = 0; i < dst.getHeight(); i++) {
|
||||
for (int j = 0; j < dst.getWidth(); j++, srcOff++, dstOff += 3)
|
||||
YUV444toRGB888(y[srcOff] << this.upShift >> this.downShift, u[srcOff] << this.upShift >> this.downShift, v[srcOff] << this.upShift >> this.downShift, data, dstOff);
|
||||
}
|
||||
}
|
||||
|
||||
public static final void YUV444toRGB888(int y, int u, int v, int[] data, int off) {
|
||||
int c = y - 16;
|
||||
int d = u - 128;
|
||||
int e = v - 128;
|
||||
int r = 298 * c + 409 * e + 128 >> 8;
|
||||
int g = 298 * c - 100 * d - 208 * e + 128 >> 8;
|
||||
int b = 298 * c + 516 * d + 128 >> 8;
|
||||
data[off] = crop(r);
|
||||
data[off + 1] = crop(g);
|
||||
data[off + 2] = crop(b);
|
||||
}
|
||||
|
||||
private static int crop(int val) {
|
||||
return (val < 0) ? 0 : ((val > 255) ? 255 : val);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package org.jcodec.scale.highbd;
|
||||
|
||||
import org.jcodec.common.model.PictureHiBD;
|
||||
|
||||
public class Yuv444pToYuv420pHiBD implements TransformHiBD {
|
||||
private int shiftUp;
|
||||
|
||||
private int shiftDown;
|
||||
|
||||
public Yuv444pToYuv420pHiBD(int shiftUp, int shiftDown) {
|
||||
this.shiftUp = shiftUp;
|
||||
this.shiftDown = shiftDown;
|
||||
}
|
||||
|
||||
public void transform(PictureHiBD src, PictureHiBD dst) {
|
||||
int lumaSize = src.getWidth() * src.getHeight();
|
||||
System.arraycopy(src.getPlaneData(0), 0, dst.getPlaneData(0), 0, lumaSize);
|
||||
copyAvg(src.getPlaneData(1), dst.getPlaneData(1), src.getPlaneWidth(1), src.getPlaneHeight(1));
|
||||
copyAvg(src.getPlaneData(2), dst.getPlaneData(2), src.getPlaneWidth(2), src.getPlaneHeight(2));
|
||||
if (this.shiftUp > this.shiftDown) {
|
||||
up(dst.getPlaneData(0), this.shiftUp - this.shiftDown);
|
||||
up(dst.getPlaneData(1), this.shiftUp - this.shiftDown);
|
||||
up(dst.getPlaneData(2), this.shiftUp - this.shiftDown);
|
||||
} else if (this.shiftDown > this.shiftUp) {
|
||||
down(dst.getPlaneData(0), this.shiftDown - this.shiftUp);
|
||||
down(dst.getPlaneData(1), this.shiftDown - this.shiftUp);
|
||||
down(dst.getPlaneData(2), this.shiftDown - this.shiftUp);
|
||||
}
|
||||
}
|
||||
|
||||
private void down(int[] dst, int down) {
|
||||
for (int i = 0; i < dst.length; i++)
|
||||
dst[i] = dst[i] >> down;
|
||||
}
|
||||
|
||||
private void up(int[] dst, int up) {
|
||||
for (int i = 0; i < dst.length; i++)
|
||||
dst[i] = dst[i] << up;
|
||||
}
|
||||
|
||||
private void copyAvg(int[] src, int[] dst, int width, int height) {
|
||||
int offSrc = 0, offDst = 0;
|
||||
for (int y = 0; y < height >> 1; y++) {
|
||||
for (int x = 0; x < width; x += 2, offDst++, offSrc += 2)
|
||||
dst[offDst] = src[offSrc] + src[offSrc + 1] + src[offSrc + width] + src[offSrc + width + 1] + 2 >> 2;
|
||||
offSrc += width;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue