use of com.android.gallery3d.filtershow.filters.FilterFusionRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class SaveImage method findFusionRepresentation.
private FilterFusionRepresentation findFusionRepresentation(ImagePreset preset) {
FilterDualCamFusionRepresentation dcRepresentation = (FilterDualCamFusionRepresentation) preset.getFilterWithSerializationName(FilterDualCamFusionRepresentation.SERIALIZATION_NAME);
FilterTruePortraitFusionRepresentation tpRepresentation = (FilterTruePortraitFusionRepresentation) preset.getFilterWithSerializationName(FilterTruePortraitFusionRepresentation.SERIALIZATION_NAME);
FilterFusionRepresentation fusionRep = null;
if (dcRepresentation != null)
fusionRep = (FilterFusionRepresentation) dcRepresentation;
else if (tpRepresentation != null)
fusionRep = (FilterFusionRepresentation) tpRepresentation;
return fusionRep;
}
use of com.android.gallery3d.filtershow.filters.FilterFusionRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class SaveImage method processAndSaveImage.
public Uri processAndSaveImage(ImagePreset preset, boolean flatten, int quality, float sizeFactor, boolean exit) {
Uri uri = null;
if (exit) {
uri = resetToOriginalImageIfNeeded(preset, !flatten);
}
if (uri != null) {
return null;
}
resetProgress();
boolean noBitmap = true;
int num_tries = 0;
int sampleSize = 1;
// If necessary, move the source file into the auxiliary directory,
// newSourceUri is then pointing to the new location.
// If no file is moved, newSourceUri will be the same as mSourceUri.
Uri newSourceUri = mSourceUri;
/*
* if (!flatten) { newSourceUri = moveSrcToAuxIfNeeded(mSourceUri, mDestinationFile); }
*/
Uri savedUri = mSelectedImageUri;
if (mPreviewImage != null) {
Bitmap previewBmp;
// Check for Fusion
FilterFusionRepresentation fusionRep = findFusionRepresentation(preset);
boolean hasFusion = (fusionRep != null && fusionRep.hasUnderlay());
if (hasFusion) {
previewBmp = flattenFusion(mContext, Uri.parse(fusionRep.getUnderlay()), mPreviewImage, Math.max(mPreviewImage.getWidth(), mPreviewImage.getHeight()), 0);
// If we fail to flatten, save original image
if (previewBmp == null) {
previewBmp = mPreviewImage;
hasFusion = false;
}
} else {
previewBmp = mPreviewImage;
}
if (flatten) {
Object xmp = getPanoramaXMPData(newSourceUri, preset);
ExifInterface exif = getExifData(newSourceUri);
long time = System.currentTimeMillis();
updateExifData(exif, time);
if (putExifData(mDestinationFile, exif, previewBmp, quality)) {
putPanoramaXMPData(mDestinationFile, xmp);
ContentValues values = getContentValues(mContext, mSelectedImageUri, mDestinationFile, time);
Object result = mContext.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
Log.d(GalleryActivity.QSST, "image exported successfully");
}
} else {
Object xmp = getPanoramaXMPData(newSourceUri, preset);
ExifInterface exif = getExifData(newSourceUri);
long time = System.currentTimeMillis();
updateExifData(exif, time);
// If we succeed in writing the bitmap as a jpeg, return a uri.
if (putExifData(mDestinationFile, exif, previewBmp, quality)) {
putPanoramaXMPData(mDestinationFile, xmp);
// mDestinationFile will save the newSourceUri info in the XMP.
if (!flatten) {
XmpPresets.writeFilterXMP(mContext, newSourceUri, mDestinationFile, preset);
}
// After this call, mSelectedImageUri will be actually
// pointing at the new file mDestinationFile.
savedUri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri, mDestinationFile, time, false);
}
}
if (hasFusion) {
// recycle bitmap
previewBmp.recycle();
previewBmp = null;
}
if (mCallback != null) {
mCallback.onPreviewSaved(savedUri);
}
}
// Stopgap fix for low-memory devices.
while (noBitmap) {
try {
updateProgress();
// Try to do bitmap operations, downsample if low-memory
Bitmap bitmap = ImageLoader.loadOrientedBitmapWithBackouts(mContext, newSourceUri, sampleSize);
if (bitmap == null) {
return null;
}
if (sizeFactor != 1f) {
// if we have a valid size
int w = (int) (bitmap.getWidth() * sizeFactor);
int h = (int) (bitmap.getHeight() * sizeFactor);
if (w == 0 || h == 0) {
w = 1;
h = 1;
}
bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
}
updateProgress();
CachingPipeline pipeline = new CachingPipeline(FiltersManager.getManager(), "Saving");
bitmap = pipeline.renderFinalImage(bitmap, preset);
// Check for Fusion
FilterFusionRepresentation fusionRep = findFusionRepresentation(preset);
boolean hasFusion = (fusionRep != null && fusionRep.hasUnderlay());
if (hasFusion) {
Bitmap underlay = flattenFusion(mContext, Uri.parse(fusionRep.getUnderlay()), bitmap, 0, sampleSize);
if (underlay != null) {
bitmap.recycle();
bitmap = underlay;
}
}
updateProgress();
Object xmp = getPanoramaXMPData(newSourceUri, preset);
ExifInterface exif = getExifData(newSourceUri);
long time = System.currentTimeMillis();
updateProgress();
updateExifData(exif, time);
updateProgress();
// If we succeed in writing the bitmap as a jpeg, return a uri.
if (putExifData(mDestinationFile, exif, bitmap, quality)) {
putPanoramaXMPData(mDestinationFile, xmp);
// mDestinationFile will save the newSourceUri info in the XMP.
if (!flatten) {
XmpPresets.writeFilterXMP(mContext, newSourceUri, mDestinationFile, preset);
uri = updateFile(mContext, savedUri, mDestinationFile, time);
} else {
ContentValues values = getContentValues(mContext, mSelectedImageUri, mDestinationFile, time);
Object result = mContext.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
}
}
updateProgress();
noBitmap = false;
} catch (OutOfMemoryError e) {
// Try 5 times before failing for good.
if (++num_tries >= 5) {
throw e;
}
System.gc();
sampleSize *= 2;
resetProgress();
}
}
return uri;
}
Aggregations