[libbluray-devel] BDGraphics: support image flipping in drawImage()
Ian Curtis
git at videolan.org
Thu Apr 3 11:27:53 CEST 2014
libbluray | branch: master | Ian Curtis <i.curtis at gmail.com> | Thu Apr 3 09:44:02 2014 +0300| [1cc12cf45dd2a90728073cfd2bdea8b2b67db2cc] | committer: hpi1
BDGraphics: support image flipping in drawImage()
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=1cc12cf45dd2a90728073cfd2bdea8b2b67db2cc
---
.../bdj/java/java/awt/BDGraphicsBase.java | 69 +++++++++++++++-----
.../bdj/java/java/awt/BDWindowGraphics.java | 2 +
2 files changed, 55 insertions(+), 16 deletions(-)
diff --git a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
index 31a091d..8303e18 100644
--- a/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
+++ b/src/libbluray/bdj/java/java/awt/BDGraphicsBase.java
@@ -334,7 +334,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
dirty.add(rect);
}
- private void drawSpanN(int x, int y, int length, int src[], int srcOffset) {
+ private void drawSpanN(int x, int y, int length, int src[], int srcOffset, boolean flipX) {
Rectangle rect = new Rectangle(x, y, length, 1);
rect = actualClip.intersection(rect);
@@ -343,13 +343,23 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
return;
}
+ int dstOffset;
+
srcOffset += rect.x - x;
x = rect.x;
length = rect.width;
+ dstOffset = y * width + x;
if (xorColor != null) {
- for (int i = 0; i < length; i++) {
- backBuffer[y * width + x + i] ^= xorColor.getRGB() ^ src[srcOffset + i];
+
+ if (flipX) {
+ for (int i = 0; i < length; i++) {
+ backBuffer[dstOffset + length -1 - i] ^= xorColor.getRGB() ^ src[srcOffset + i];
+ }
+ } else {
+ for (int i = 0; i < length; i++) {
+ backBuffer[dstOffset + i] ^= xorColor.getRGB() ^ src[srcOffset + i];
+ }
}
dirty.add(rect);
@@ -359,17 +369,29 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
switch (composite.getRule()) {
case AlphaComposite.CLEAR:
for (int i = 0; i < length; i++) {
- backBuffer[y * width + x + i] = 0;
+ backBuffer[dstOffset + i] = 0;
}
break;
case AlphaComposite.SRC:
- for (int i = 0; i < length; i++) {
- backBuffer[y * width + x + i] = applyComposite(src[srcOffset + i]);
+ if (flipX) {
+ for (int i = 0; i < length; i++) {
+ backBuffer[dstOffset + length -1 - i] = applyComposite(src[srcOffset + i]);
+ }
+ } else {
+ for (int i = 0; i < length; i++) {
+ backBuffer[dstOffset + i] = applyComposite(src[srcOffset + i]);
+ }
}
break;
case AlphaComposite.SRC_OVER:
- for (int i = 0; i < length; i++) {
- backBuffer[y * width + x + i] = alphaBlend(backBuffer[y * width + x + i], applyComposite(src[srcOffset + i]));
+ if (flipX) {
+ for (int i = 0; i < length; i++) {
+ backBuffer[dstOffset + length -1 - i] = alphaBlend(backBuffer[dstOffset + length -1 - i], applyComposite(src[srcOffset + i]));
+ }
+ } else {
+ for (int i = 0; i < length; i++) {
+ backBuffer[dstOffset + i] = alphaBlend(backBuffer[dstOffset + i], applyComposite(src[srcOffset + i]));
+ }
}
break;
}
@@ -383,10 +405,10 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
drawSpanN(x, y, length, rgb);
}
- private void drawSpan(int x, int y, int length, int src[], int srcOffset) {
+ private void drawSpan(int x, int y, int length, int src[], int srcOffset, boolean flipX) {
x += originX;
y += originY;
- drawSpanN(x, y, length, src, srcOffset);
+ drawSpanN(x, y, length, src, srcOffset, flipX);
}
private void drawPointN(int x, int y, int rgb) {
@@ -543,7 +565,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
// draw sub image
for (int i = 0; i < h; i++) {
- drawSpanN(x + dx, y + i + dy, w, subImage, w * i);
+ drawSpanN(x + dx, y + i + dy, w, subImage, w * i, false);
}
}
@@ -899,7 +921,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
*/
public boolean drawImage(Image img, int x, int y, Color bg,
ImageObserver observer) {
- return drawImageN(img, x, y, -1, -1, 0, 0, -1, -1, bg, observer);
+ return drawImageN(img, x, y, -1, -1, 0, 0, -1, -1, false, false, bg, observer);
}
/**
@@ -917,7 +939,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
*/
public boolean drawImage(Image img, int x, int y, int w, int h,
Color bg, ImageObserver observer) {
- return drawImageN(img, x, y, w, h, 0, 0, -1, -1, bg, observer);
+ return drawImageN(img, x, y, w, h, 0, 0, -1, -1, false, false, bg, observer);
}
/**
@@ -940,32 +962,40 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
int sx1, int sy1, int sx2, int sy2,
Color bg, ImageObserver observer) {
+ boolean flipX = false;
+ boolean flipY = false;
+
if (dx1 > dx2) {
int swap = dx1;
dx1 = dx2;
dx2 = swap;
+ flipX = !flipX;
}
if (dy1 > dy2) {
int swap = dy1;
dy1 = dy2;
dy2 = swap;
+ flipY = !flipY;
}
if (sx1 > sx2) {
int swap = sx1;
sx1 = sx2;
sx2 = swap;
+ flipX = !flipX;
}
if (sy1 > sy2) {
int swap = sy1;
sy1 = sy2;
sy2 = swap;
+ flipY = !flipY;
}
return drawImageN(img, dx1, dy1, dx2 - dx1, dy2 - dy1,
- sx1, sy1, sx2 - sx1, sy2 - sy1, bg, observer);
+ sx1, sy1, sx2 - sx1, sy2 - sy1,
+ flipX, flipY, bg, observer);
}
/**
@@ -975,6 +1005,7 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
protected boolean drawImageN(Image img,
int dx, int dy, int dw, int dh,
int sx, int sy, int sw, int sh,
+ boolean flipX, boolean flipY,
Color bg, ImageObserver observer) {
if ((sx < 0) || (sy < 0) ||
@@ -1037,8 +1068,14 @@ abstract class BDGraphicsBase extends Graphics2D implements ConstrainableGraphic
}
// draw actual colour array
- for (int i = 0; i < dh; i++) {
- drawSpan(dx, dy + i, dw, rgbArray, (stride * (i + sy)) + sx);
+ if (flipY) {
+ for (int i = 0; i < dh; i++) {
+ drawSpan(dx, dy + dh - 1 - i, dw, rgbArray, (stride * (i + sy)) + sx, flipX);
+ }
+ } else {
+ for (int i = 0; i < dh; i++) {
+ drawSpan(dx, dy + i, dw, rgbArray, (stride * (i + sy)) + sx, flipX);
+ }
}
return true;
diff --git a/src/libbluray/bdj/java/java/awt/BDWindowGraphics.java b/src/libbluray/bdj/java/java/awt/BDWindowGraphics.java
index 20e9c97..743f441 100644
--- a/src/libbluray/bdj/java/java/awt/BDWindowGraphics.java
+++ b/src/libbluray/bdj/java/java/awt/BDWindowGraphics.java
@@ -151,11 +151,13 @@ public class BDWindowGraphics extends BDGraphics {
public boolean drawImageN(Image img,
int dx, int dy, int dw, int dh,
int sx, int sy, int sw, int sh,
+ boolean flipX, boolean flipY,
Color bg, ImageObserver observer) {
synchronized (window) {
boolean complete = super.drawImageN(
img, dx, dy, dw, dh, sx, sy, sw, sh,
+ flipX, flipY,
bg, observer);
if (complete) {
window.notifyChanged();
More information about the libbluray-devel
mailing list