[libbluray-devel] BDGraphics: avoid creating tmp images when scaling
hpi1
git at videolan.org
Sat Apr 12 18:11:33 CEST 2014
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Apr 11 14:02:54 2014 +0300| [43e2de8370bc4f51b5659de8242958df7d6c422e] | committer: hpi1
BDGraphics: avoid creating tmp images when scaling
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=43e2de8370bc4f51b5659de8242958df7d6c422e
---
.../bdj/java/java/awt/BDGraphicsBase.java | 44 +++++++++++++-------
1 file changed, 28 insertions(+), 16 deletions(-)
diff --git a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
index 7717c04..e8ddb7b 100644
--- a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
+++ b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
@@ -1045,19 +1045,18 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
bgColor = bg.getRGB();
}
- // resize if needed
- if (dw != sw || dh != sh) {
- rgbArray = resizeBilinear(rgbArray, (sy * stride) + sx, stride, sw, sh, dw, dh);
- sx = 0;
- sy = 0;
- stride = dw;
- }
-
// draw background colour
for (int i = 0; i < dh && bg != null; i++) {
drawSpan(dx, dy + i, dw, bgColor);
}
+ // resize if needed
+ if (dw != sw || dh != sh) {
+ drawResizeBilinear(rgbArray, (sy * stride) + sx, stride, sw, sh,
+ dx, dy, dw, dh, flipX, flipY);
+ return true;
+ }
+
// draw actual colour array
if (flipY) {
for (int i = 0; i < dh; i++) {
@@ -1082,13 +1081,14 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
* @param dh New height.
* @return New array with size dw * dh.
*/
- private int[] resizeBilinear(int[] pixels, int offset, int scansize, int sw, int sh, int dw, int dh) {
-
- int[] outImage = new int[dw * dh];
+ private int[] tmpLine = null;
+ private void drawResizeBilinear(int[] pixels, int offset, int scansize, int sw, int sh,
+ int dx, int dy, int dw, int dh, boolean flipX, boolean flipY) {
if (sw == 1 && sh == 1) {
- Arrays.fill(outImage, pixels[offset]);
- return outImage;
+ for (int Y = dy; Y < (dy + dh); Y++)
+ drawSpan(dx, Y, dw, pixels[offset]);
+ return;
}
// a quick hack for 1D arrays, stretch them to make them 2D
@@ -1117,6 +1117,10 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
sh = 2;
}
+ if (tmpLine == null || tmpLine.length < dw + 1) {
+ tmpLine = new int[Math.max(1920, dw + 1)];
+ }
+
int a, b, c, d, x, y, index;
float x_ratio = ((float)(sw - 1)) / dw;
float y_ratio = ((float)(sh - 1)) / dh;
@@ -1142,7 +1146,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
int dA = d >>> 24;
if (aA + bA + cA + dA < 1) {
- outImage[position++] = 0;
+ tmpLine[position++] = 0;
continue;
}
@@ -1181,14 +1185,21 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
green /= alpha;
red /= alpha;
- outImage[position++] =
+ tmpLine[position++] =
((((int)alpha) << 24) & 0xff000000) |
((((int)red ) << 16) & 0x00ff0000) |
((((int)green) << 8 ) & 0x0000ff00) |
((((int)blue ) ) & 0x000000ff);
}
+
+ if (flipY) {
+ drawSpan(dx, dy + dh - 1 - i, dw, tmpLine, 0, flipX);
+ } else {
+ drawSpan(dx, dy + i, dw, tmpLine, 0, flipX);
+ }
+
+ position = 0;
}
- return outImage;
}
public Stroke getStroke() {
@@ -1201,6 +1212,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
}
public void dispose() {
+ tmpLine = null;
}
public String toString() {
More information about the libbluray-devel
mailing list