Home | History | Annotate | Download | only in imageproc
      1 /*
      2  * Copyright (C) 2011 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 
     18 package android.filterpacks.imageproc;
     19 
     20 import android.content.Context;
     21 import android.filterfw.core.Filter;
     22 import android.filterfw.core.FilterContext;
     23 import android.filterfw.core.Frame;
     24 import android.filterfw.core.FrameFormat;
     25 import android.filterfw.core.GenerateFieldPort;
     26 import android.filterfw.core.KeyValueMap;
     27 import android.filterfw.format.ImageFormat;
     28 import android.graphics.Bitmap;
     29 import android.graphics.Bitmap.CompressFormat;
     30 
     31 import android.util.Log;
     32 
     33 import java.io.OutputStream;
     34 import java.io.IOException;
     35 
     36 /**
     37  * @hide
     38  */
     39 public class ImageEncoder extends Filter {
     40 
     41     @GenerateFieldPort(name = "stream")
     42     private OutputStream mOutputStream;
     43 
     44     @GenerateFieldPort(name = "quality", hasDefault = true)
     45     private int mQuality = 80;
     46 
     47     public ImageEncoder(String name) {
     48         super(name);
     49     }
     50 
     51     @Override
     52     public void setupPorts() {
     53         addMaskedInputPort("image", ImageFormat.create(ImageFormat.COLORSPACE_RGBA,
     54                                                        FrameFormat.TARGET_UNSPECIFIED));
     55     }
     56 
     57     @Override
     58     public void process(FilterContext env) {
     59         Frame input = pullInput("image");
     60         Bitmap bitmap = input.getBitmap();
     61         bitmap.compress(CompressFormat.JPEG, mQuality, mOutputStream);
     62     }
     63 
     64 }
     65