public Result doInBackground(Request message) { SaveRequest request = (SaveRequest) message; Uri sourceUri = request.sourceUri; Uri selectedUri = request.selectedUri; File destinationFile = request.destinationFile; Bitmap previewImage = request.previewImage; ImagePreset preset = request.preset; boolean flatten = request.flatten; final boolean exit = request.exit; // We create a small bitmap showing the result that we can // give to the notification UpdateBitmap updateBitmap = new UpdateBitmap(); /// M: [BUG.ADD] @{ // while OriginalBounds == null, should exit the task. if (MasterImage.getImage().getOriginalBounds() == null) { URIResult result = new URIResult(); result.uri = null; result.exit = false; return result; } else { // back up the bounds. MasterImage.getImage().backupBounds(); } /// @} updateBitmap.bitmap = createNotificationBitmap(previewImage, sourceUri, preset); postUpdate(updateBitmap); SaveImage saveImage = new SaveImage( mProcessingService, sourceUri, selectedUri, destinationFile, previewImage, new SaveImage.Callback() { @Override public void onPreviewSaved(Uri uri) { UpdatePreviewSaved previewSaved = new UpdatePreviewSaved(); previewSaved.uri = uri; previewSaved.exit = exit; postUpdate(previewSaved); } @Override public void onProgress(int max, int current) { UpdateProgress updateProgress = new UpdateProgress(); updateProgress.max = max; updateProgress.current = current; postUpdate(updateProgress); } }); Uri uri = saveImage.processAndSaveImage( preset, flatten, request.quality, request.sizeFactor, request.exit); URIResult result = new URIResult(); result.uri = uri; result.exit = request.exit; return result; }
public void deleteCurrentBand() { int index = mBands.indexOf(mCurrentBand); mBands.remove(mCurrentBand); trimVector(); if (getNumberOfBands() == 0) { addBand(MasterImage.getImage().getOriginalBounds()); } mCurrentBand = mBands.get(0); }
public void setImageFrame(Rect imageFrame, int orientation) { if (mImageFrame != null && mImageFrame.equals(imageFrame)) { return; } if (getType() == Action.ADD_ACTION) { return; } Bitmap temp = MasterImage.getImage().getTemporaryThumbnailBitmap(); if (temp != null) { mImage = temp; } Bitmap bitmap = MasterImage.getImage().getThumbnailBitmap(); if (bitmap != null) { mImageFrame = imageFrame; int w = mImageFrame.width(); int h = mImageFrame.height(); postNewIconRenderRequest(w, h); } }
public void setOriginal(Bitmap bitmap) { if (mOriginalBitmap != null) { mOriginalBitmap.recycle(); } mOriginalBitmap = bitmap; Log.v(LOGTAG, "setOriginal, size " + bitmap.getWidth() + " x " + bitmap.getHeight()); ImagePreset preset = MasterImage.getImage().getPreset(); setupEnvironment(preset, false); updateOriginalAllocation(preset); }
private void setupEnvironment(ImagePreset preset, boolean highResPreview) { mEnvironment.setPipeline(this); mEnvironment.setFiltersManager(mFiltersManager); mEnvironment.setBitmapCache(MasterImage.getImage().getBitmapCache()); if (highResPreview) { mEnvironment.setScaleFactor(mHighResPreviewScaleFactor); } else { mEnvironment.setScaleFactor(mPreviewScaleFactor); } mEnvironment.setQuality(FilterEnvironment.QUALITY_PREVIEW); mEnvironment.setImagePreset(preset); mEnvironment.setStop(false); }
public void renderFilters(RenderingRequest request) { synchronized (CachingPipeline.class) { if (getRenderScriptContext() == null) { return; } ImagePreset preset = request.getImagePreset(); setupEnvironment(preset, false); Bitmap bitmap = MasterImage.getImage().getOriginalBitmapHighres(); if (bitmap == null) { return; } bitmap = mEnvironment.getBitmapCopy(bitmap, BitmapCache.FILTERS); bitmap = preset.apply(bitmap, mEnvironment); if (!mEnvironment.needsStop()) { request.setBitmap(bitmap); } else { mEnvironment.cache(bitmap); } mFiltersManager.freeFilterResources(preset); } }
@Override public int onStartCommand(Intent intent, int flags, int startId) { mNeedsAlive = true; if (intent != null && intent.getBooleanExtra(SAVING, false)) { // we save using an intent to keep the service around after the // activity has been destroyed. String presetJson = intent.getStringExtra(PRESET); String source = intent.getStringExtra(SOURCE_URI); String selected = intent.getStringExtra(SELECTED_URI); String destination = intent.getStringExtra(DESTINATION_FILE); int quality = intent.getIntExtra(QUALITY, 100); float sizeFactor = intent.getFloatExtra(SIZE_FACTOR, 1); boolean flatten = intent.getBooleanExtra(FLATTEN, false); boolean exit = intent.getBooleanExtra(EXIT, false); Uri sourceUri = Uri.parse(source); Uri selectedUri = null; if (selected != null) { selectedUri = Uri.parse(selected); } File destinationFile = null; if (destination != null) { destinationFile = new File(destination); } ImagePreset preset = new ImagePreset(); preset.readJsonFromString(presetJson); mNeedsAlive = false; mSaving = true; handleSaveRequest( sourceUri, selectedUri, destinationFile, preset, MasterImage.getImage().getHighresImage(), flatten, quality, sizeFactor, exit); } return START_REDELIVER_INTENT; }
public void clearBitmap() { if (mImage != null && mImage != MasterImage.getImage().getTemporaryThumbnailBitmap()) { MasterImage.getImage().getBitmapCache().cache(mImage); } mImage = null; }
public boolean needsRepaint() { SharedBuffer buffer = MasterImage.getImage().getPreviewBuffer(); return buffer.checkRepaintNeeded(); }
public synchronized void render(RenderingRequest request) { // TODO: cleanup/remove GEOMETRY / FILTERS paths synchronized (CachingPipeline.class) { if (getRenderScriptContext() == null) { return; } if ((request.getType() != RenderingRequest.PARTIAL_RENDERING && request.getType() != RenderingRequest.ICON_RENDERING && request.getBitmap() == null) || request.getImagePreset() == null) { return; } if (DEBUG) { Log.v(LOGTAG, "render image of type " + getType(request)); } Bitmap bitmap = request.getBitmap(); ImagePreset preset = request.getImagePreset(); setupEnvironment(preset, true); mFiltersManager.freeFilterResources(preset); if (request.getType() == RenderingRequest.PARTIAL_RENDERING) { MasterImage master = MasterImage.getImage(); bitmap = ImageLoader.getScaleOneImageForPreset( master.getActivity(), mEnvironment.getBimapCache(), master.getUri(), request.getBounds(), request.getDestination()); if (bitmap == null) { Log.w(LOGTAG, "could not get bitmap for: " + getType(request)); return; } } if (request.getType() == RenderingRequest.FULL_RENDERING || request.getType() == RenderingRequest.GEOMETRY_RENDERING || request.getType() == RenderingRequest.FILTERS_RENDERING) { updateOriginalAllocation(preset); } if (DEBUG && bitmap != null) { Log.v( LOGTAG, "after update, req bitmap (" + bitmap.getWidth() + "x" + bitmap.getHeight() + " ? resizeOriginal (" + mResizedOriginalBitmap.getWidth() + "x" + mResizedOriginalBitmap.getHeight()); } if (request.getType() == RenderingRequest.FULL_RENDERING || request.getType() == RenderingRequest.GEOMETRY_RENDERING) { mOriginalAllocation.copyTo(bitmap); } else if (request.getType() == RenderingRequest.FILTERS_RENDERING) { mFiltersOnlyOriginalAllocation.copyTo(bitmap); } if (request.getType() == RenderingRequest.FULL_RENDERING || request.getType() == RenderingRequest.FILTERS_RENDERING || request.getType() == RenderingRequest.ICON_RENDERING || request.getType() == RenderingRequest.PARTIAL_RENDERING || request.getType() == RenderingRequest.STYLE_ICON_RENDERING) { if (request.getType() == RenderingRequest.ICON_RENDERING) { mEnvironment.setQuality(FilterEnvironment.QUALITY_ICON); } else { mEnvironment.setQuality(FilterEnvironment.QUALITY_PREVIEW); } if (request.getType() == RenderingRequest.ICON_RENDERING) { Rect iconBounds = request.getIconBounds(); Bitmap source = MasterImage.getImage().getThumbnailBitmap(); if (iconBounds.width() > source.getWidth() * 2) { source = MasterImage.getImage().getLargeThumbnailBitmap(); } if (iconBounds != null) { bitmap = mEnvironment.getBitmap(iconBounds.width(), iconBounds.height(), BitmapCache.ICON); Canvas canvas = new Canvas(bitmap); Matrix m = new Matrix(); float minSize = Math.min(source.getWidth(), source.getHeight()); float maxSize = Math.max(iconBounds.width(), iconBounds.height()); float scale = maxSize / minSize; m.setScale(scale, scale); float dx = (iconBounds.width() - (source.getWidth() * scale)) / 2.0f; float dy = (iconBounds.height() - (source.getHeight() * scale)) / 2.0f; m.postTranslate(dx, dy); canvas.drawBitmap(source, m, new Paint(Paint.FILTER_BITMAP_FLAG)); } else { bitmap = mEnvironment.getBitmapCopy(source, BitmapCache.ICON); } } Bitmap bmp = preset.apply(bitmap, mEnvironment); if (!mEnvironment.needsStop()) { request.setBitmap(bmp); } mFiltersManager.freeFilterResources(preset); } } }