use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImageShow method drawImageAndAnimate.
public void drawImageAndAnimate(Canvas canvas, Bitmap image) {
if (image == null) {
return;
}
MasterImage master = MasterImage.getImage();
Matrix m = master.computeImageToScreen(image, 0, false);
if (m == null) {
return;
}
canvas.save();
RectF d = new RectF(0, 0, image.getWidth(), image.getHeight());
m.mapRect(d);
d.roundOut(mImageBounds);
master.setImageBounds(canvas, mImageBounds);
boolean showAnimatedImage = master.onGoingNewLookAnimation();
if (!showAnimatedImage && mDidStartAnimation) {
// animation ended, but do we have the correct image to show?
if (master.getPreset().equals(master.getCurrentPreset())) {
// we do, let's stop showing the animated image
mDidStartAnimation = false;
MasterImage.getImage().resetAnimBitmap();
} else {
showAnimatedImage = true;
}
} else if (showAnimatedImage) {
mDidStartAnimation = true;
}
if (showAnimatedImage) {
canvas.save();
// Animation uses the image before the change
Bitmap previousImage = master.getPreviousImage();
Matrix mp = master.computeImageToScreen(previousImage, 0, false);
RectF dp = new RectF(0, 0, previousImage.getWidth(), previousImage.getHeight());
mp.mapRect(dp);
Rect previousBounds = new Rect();
dp.roundOut(previousBounds);
float centerX = dp.centerX();
float centerY = dp.centerY();
boolean needsToDrawImage = true;
if (master.getCurrentLookAnimation() == MasterImage.CIRCLE_ANIMATION) {
float maskScale = MasterImage.getImage().getMaskScale();
if (maskScale >= 0.0f) {
float maskW = sMask.getWidth() / 2.0f;
float maskH = sMask.getHeight() / 2.0f;
Point point = mActivity.hintTouchPoint(this);
float maxMaskScale = 2 * Math.max(getWidth(), getHeight()) / Math.min(maskW, maskH);
maskScale = maskScale * maxMaskScale;
float x = point.x - maskW * maskScale;
float y = point.y - maskH * maskScale;
// Prepare the shader
mShaderMatrix.reset();
mShaderMatrix.setScale(1.0f / maskScale, 1.0f / maskScale);
mShaderMatrix.preTranslate(-x + mImageBounds.left, -y + mImageBounds.top);
float scaleImageX = mImageBounds.width() / (float) image.getWidth();
float scaleImageY = mImageBounds.height() / (float) image.getHeight();
mShaderMatrix.preScale(scaleImageX, scaleImageY);
mMaskPaint.reset();
Shader maskShader = createShader(image);
maskShader.setLocalMatrix(mShaderMatrix);
mMaskPaint.setShader(maskShader);
// as needed
drawShadow(canvas, mImageBounds);
canvas.drawBitmap(previousImage, m, mPaint);
canvas.clipRect(mImageBounds);
canvas.translate(x, y);
canvas.scale(maskScale, maskScale);
canvas.drawBitmap(sMask, 0, 0, mMaskPaint);
needsToDrawImage = false;
}
} else if (master.getCurrentLookAnimation() == MasterImage.ROTATE_ANIMATION) {
Rect d1 = computeImageBounds(master.getPreviousImage().getHeight(), master.getPreviousImage().getWidth());
Rect d2 = computeImageBounds(master.getPreviousImage().getWidth(), master.getPreviousImage().getHeight());
float finalScale = d1.width() / (float) d2.height();
finalScale = (1.0f * (1.0f - master.getAnimFraction())) + (finalScale * master.getAnimFraction());
canvas.rotate(master.getAnimRotationValue(), centerX, centerY);
canvas.scale(finalScale, finalScale, centerX, centerY);
} else if (master.getCurrentLookAnimation() == MasterImage.MIRROR_ANIMATION) {
if (master.getCurrentFilterRepresentation() instanceof FilterMirrorRepresentation) {
FilterMirrorRepresentation rep = (FilterMirrorRepresentation) master.getCurrentFilterRepresentation();
ImagePreset preset = master.getPreset();
ArrayList<FilterRepresentation> geometry = (ArrayList<FilterRepresentation>) preset.getGeometryFilters();
GeometryMathUtils.GeometryHolder holder = null;
holder = GeometryMathUtils.unpackGeometry(geometry);
if (holder.rotation.value() == 90 || holder.rotation.value() == 270) {
if (rep.isHorizontal() && !rep.isVertical()) {
canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
} else if (rep.isVertical() && !rep.isHorizontal()) {
canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
} else if (rep.isHorizontal() && rep.isVertical()) {
canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
} else {
canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
}
} else {
if (rep.isHorizontal() && !rep.isVertical()) {
canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
} else if (rep.isVertical() && !rep.isHorizontal()) {
canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
} else if (rep.isHorizontal() && rep.isVertical()) {
canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
} else {
canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
}
}
}
}
if (needsToDrawImage) {
// as needed
drawShadow(canvas, previousBounds);
if (hasFusionApplied() || this instanceof ImageFusion) {
previousImage.setHasAlpha(true);
}
canvas.drawBitmap(previousImage, mp, mPaint);
}
canvas.restore();
} else {
// as needed
drawShadow(canvas, mImageBounds);
if (hasFusionApplied() || this instanceof ImageFusion) {
image.setHasAlpha(true);
}
canvas.drawBitmap(image, m, mPaint);
}
canvas.restore();
}
use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImagePreset method updateWith.
public void updateWith(ImagePreset preset) {
if (preset.mFilters.size() != mFilters.size()) {
Log.e(LOGTAG, "Updating a preset with an incompatible one");
return;
}
for (int i = 0; i < mFilters.size(); i++) {
FilterRepresentation destRepresentation = mFilters.elementAt(i);
FilterRepresentation sourceRepresentation = preset.mFilters.elementAt(i);
destRepresentation.useParametersFrom(sourceRepresentation);
}
}
use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImagePreset method showFilters.
public void showFilters() {
Log.v(LOGTAG, "\\\\\\ showFilters -- " + mFilters.size() + " filters");
int n = 0;
for (FilterRepresentation representation : mFilters) {
Log.v(LOGTAG, " filter " + n + " : " + representation.toString());
n++;
}
Log.v(LOGTAG, "/// showFilters -- " + mFilters.size() + " filters");
}
use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImagePreset method same.
public boolean same(ImagePreset preset) {
if (preset == null) {
return false;
}
if (preset.mFilters.size() != mFilters.size()) {
return false;
}
if (mDoApplyGeometry != preset.mDoApplyGeometry) {
return false;
}
if (mDoApplyFilters != preset.mDoApplyFilters) {
if (mFilters.size() > 0 || preset.mFilters.size() > 0) {
return false;
}
}
if (mDoApplyFilters && preset.mDoApplyFilters) {
for (int i = 0; i < preset.mFilters.size(); i++) {
FilterRepresentation a = preset.mFilters.elementAt(i);
FilterRepresentation b = mFilters.elementAt(i);
if (!a.equals(b)) {
return false;
}
}
}
return true;
}
use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImagePreset method applyFilters.
public void applyFilters(int from, int to, Allocation in, Allocation out, FilterEnvironment environment) {
if (mDoApplyFilters) {
if (from < 0) {
from = 0;
}
if (to == -1) {
to = mFilters.size();
}
for (int i = from; i < to; i++) {
FilterRepresentation representation = mFilters.elementAt(i);
if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY || representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
continue;
}
if (i > from) {
in.copyFrom(out);
}
environment.applyRepresentation(representation, in, out);
}
}
}
Aggregations