use of com.android.gallery3d.filtershow.pipeline.ImagePreset 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.pipeline.ImagePreset in project android_packages_apps_Gallery2 by LineageOS.
the class StateView method onTouchEvent.
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean ret = super.onTouchEvent(event);
FilterShowActivity activity = (FilterShowActivity) getContext();
if (event.getActionMasked() == MotionEvent.ACTION_UP) {
activity.startTouchAnimation(this, event.getX(), event.getY());
}
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
mStartTouchY = event.getY();
mStartTouchX = event.getX();
if (mType == BEGIN) {
MasterImage.getImage().setShowsOriginal(true);
}
}
if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
setTranslationX(0);
setTranslationY(0);
MasterImage.getImage().setShowsOriginal(false);
if (mType != BEGIN && event.getActionMasked() == MotionEvent.ACTION_UP) {
setSelected(true);
FilterRepresentation representation = getState().getFilterRepresentation();
MasterImage image = MasterImage.getImage();
ImagePreset preset = image != null ? image.getCurrentPreset() : null;
if (getTranslationY() == 0 && image != null && preset != null && representation != image.getCurrentFilterRepresentation() && preset.getRepresentation(representation) != null) {
activity.showRepresentation(representation);
setSelected(false);
}
}
}
if (mType != BEGIN && event.getActionMasked() == MotionEvent.ACTION_MOVE) {
float delta = event.getY() - mStartTouchY;
if (Math.abs(delta) > mDeleteSlope) {
activity.setHandlesSwipeForView(this, mStartTouchX, mStartTouchY);
}
}
return true;
}
use of com.android.gallery3d.filtershow.pipeline.ImagePreset in project android_packages_apps_Gallery2 by LineageOS.
the class ImageCurves method curves.
private ImageFilterCurves curves() {
String filterName = getFilterName();
ImagePreset p = getImagePreset();
if (p != null) {
return (ImageFilterCurves) FiltersManager.getManager().getFilter(ImageFilterCurves.class);
}
return null;
}
use of com.android.gallery3d.filtershow.pipeline.ImagePreset in project android_packages_apps_Gallery2 by LineageOS.
the class ImageFilterTruePortrait method apply.
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
if (getParameters() == null || quality == FilterEnvironment.QUALITY_ICON) {
return bitmap;
}
Bitmap filteredBitmap = null;
boolean result = false;
int orientation = MasterImage.getImage().getOrientation();
Rect originalBounds = MasterImage.getImage().getOriginalBounds();
int filteredW;
int filteredH;
if (quality == FilterEnvironment.QUALITY_FINAL) {
filteredW = originalBounds.width();
filteredH = originalBounds.height();
} else {
Bitmap originalBmp = MasterImage.getImage().getOriginalBitmapHighres();
filteredW = originalBmp.getWidth();
filteredH = originalBmp.getHeight();
// image is rotated
if (orientation == ImageLoader.ORI_ROTATE_90 || orientation == ImageLoader.ORI_ROTATE_270 || orientation == ImageLoader.ORI_TRANSPOSE || orientation == ImageLoader.ORI_TRANSVERSE) {
int tmp = filteredW;
filteredW = filteredH;
filteredH = tmp;
}
// non even width or height
if (filteredW % 2 != 0 || filteredH % 2 != 0) {
float aspect = (float) filteredH / (float) filteredW;
if (filteredW >= filteredH) {
filteredW = MasterImage.MAX_BITMAP_DIM;
filteredH = (int) (filteredW * aspect);
} else {
filteredH = MasterImage.MAX_BITMAP_DIM;
filteredW = (int) (filteredH / aspect);
}
}
}
filteredBitmap = MasterImage.getImage().getBitmapCache().getBitmap(filteredW, filteredH, BitmapCache.FILTERS);
result = applyEffect(filteredBitmap);
if (result == false) {
Log.e(TAG, "Imagelib API failed");
showToast(GalleryAppImpl.getContext().getString(R.string.no_faces_found), Toast.LENGTH_SHORT);
return bitmap;
} else {
mPaint.reset();
mPaint.setAntiAlias(true);
if (quality == FilterEnvironment.QUALITY_FINAL) {
mPaint.setFilterBitmap(true);
mPaint.setDither(true);
}
if (needsClear()) {
bitmap.setHasAlpha(true);
bitmap.eraseColor(Color.TRANSPARENT);
}
Canvas canvas = new Canvas(bitmap);
ImagePreset preset = getEnvironment().getImagePreset();
int bmWidth = bitmap.getWidth();
int bmHeight = bitmap.getHeight();
GeometryHolder holder;
if (preset.getDoApplyGeometry()) {
holder = GeometryMathUtils.unpackGeometry(preset.getGeometryFilters());
} else {
holder = new GeometryHolder();
}
RectF crop = new RectF();
Matrix m = GeometryMathUtils.getOriginalToScreen(holder, crop, true, filteredW, filteredH, bmWidth, bmHeight);
canvas.save();
canvas.clipRect(crop);
canvas.drawBitmap(filteredBitmap, m, mPaint);
canvas.restore();
MasterImage.getImage().getBitmapCache().cache(filteredBitmap);
}
return bitmap;
}
use of com.android.gallery3d.filtershow.pipeline.ImagePreset in project android_packages_apps_Gallery2 by LineageOS.
the class Action method postNewIconRenderRequest.
private void postNewIconRenderRequest(int w, int h) {
if (mRepresentation != null) {
ImagePreset preset = new ImagePreset();
preset.addFilter(mRepresentation);
RenderingRequest.postIconRequest(mContext, w, h, preset, this);
}
}
Aggregations