Home | History | Annotate | Download | only in filters
      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.filters;
     18 
     19 import android.content.res.Resources;
     20 import android.graphics.Bitmap;
     21 import android.graphics.BitmapFactory;
     22 
     23 import com.android.gallery3d.R;
     24 
     25 public class IconUtilities {
     26     public static final int PUNCH = R.drawable.filtershow_fx_0005_punch;
     27     public static final int VINTAGE = R.drawable.filtershow_fx_0000_vintage;
     28     public static final int BW_CONTRAST = R.drawable.filtershow_fx_0004_bw_contrast;
     29     public static final int BLEACH = R.drawable.filtershow_fx_0002_bleach;
     30     public static final int INSTANT = R.drawable.filtershow_fx_0001_instant;
     31     public static final int WASHOUT = R.drawable.filtershow_fx_0007_washout;
     32     public static final int BLUECRUSH = R.drawable.filtershow_fx_0003_blue_crush;
     33     public static final int WASHOUT_COLOR = R.drawable.filtershow_fx_0008_washout_color;
     34     public static final int X_PROCESS = R.drawable.filtershow_fx_0006_x_process;
     35 
     36     public static Bitmap getFXBitmap(Resources res, int id) {
     37         Bitmap ret;
     38         BitmapFactory.Options o = new BitmapFactory.Options();
     39         o.inScaled = false;
     40 
     41         if (id != 0) {
     42             return BitmapFactory.decodeResource(res, id, o);
     43         }
     44         return null;
     45     }
     46 
     47     public static Bitmap loadBitmap(Resources res, int resource) {
     48 
     49         final BitmapFactory.Options options = new BitmapFactory.Options();
     50         options.inPreferredConfig = Bitmap.Config.ARGB_8888;
     51         Bitmap bitmap = BitmapFactory.decodeResource(
     52                 res,
     53                 resource, options);
     54 
     55         return bitmap;
     56     }
     57 
     58     public static Bitmap applyFX(Bitmap bitmap, final Bitmap fxBitmap) {
     59         ImageFilterFx fx = new ImageFilterFx() {
     60             @Override
     61             public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
     62 
     63                 int w = bitmap.getWidth();
     64                 int h = bitmap.getHeight();
     65                 int fxw = fxBitmap.getWidth();
     66                 int fxh = fxBitmap.getHeight();
     67 
     68                 nativeApplyFilter(bitmap, w, h, fxBitmap, fxw, fxh);
     69                 return bitmap;
     70             }
     71         };
     72         return fx.apply(bitmap, 0, 0);
     73     }
     74 }
     75