1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.gallery3d.filtershow.pipeline; 18 19 import android.graphics.Bitmap; 20 import android.graphics.Canvas; 21 import android.util.Log; 22 import com.android.gallery3d.filtershow.cache.BitmapCache; 23 import com.android.gallery3d.filtershow.imageshow.PrimaryImage; 24 25 public class Buffer { 26 private static final String LOGTAG = "Buffer"; 27 private Bitmap mBitmap; 28 private ImagePreset mPreset; 29 Buffer(Bitmap bitmap)30 public Buffer(Bitmap bitmap) { 31 if (bitmap != null) { 32 BitmapCache cache = PrimaryImage.getImage().getBitmapCache(); 33 mBitmap = cache.getBitmapCopy(bitmap, BitmapCache.PREVIEW_CACHE); 34 } 35 } 36 isSameSize(Bitmap bitmap)37 public boolean isSameSize(Bitmap bitmap) { 38 if (mBitmap == null || bitmap == null) { 39 return false; 40 } 41 if (mBitmap.getWidth() == bitmap.getWidth() 42 && mBitmap.getHeight() == bitmap.getHeight()) { 43 return true; 44 } 45 return false; 46 } 47 useBitmap(Bitmap bitmap)48 public synchronized void useBitmap(Bitmap bitmap) { 49 Canvas canvas = new Canvas(mBitmap); 50 canvas.drawBitmap(bitmap, 0, 0, null); 51 } 52 getBitmap()53 public synchronized Bitmap getBitmap() { 54 return mBitmap; 55 } 56 sync()57 public void sync() { 58 } 59 getPreset()60 public ImagePreset getPreset() { 61 return mPreset; 62 } 63 setPreset(ImagePreset preset)64 public void setPreset(ImagePreset preset) { 65 if ((mPreset == null) || (!mPreset.same(preset))) { 66 mPreset = new ImagePreset(preset); 67 } else { 68 mPreset.updateWith(preset); 69 } 70 } 71 remove()72 public void remove() { 73 BitmapCache cache = PrimaryImage.getImage().getBitmapCache(); 74 if (cache.cache(mBitmap)) { 75 mBitmap = null; 76 } 77 } 78 } 79