ImageEncoder.java revision 65953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9
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 18package android.filterpacks.imageproc; 19 20import android.content.Context; 21import android.filterfw.core.Filter; 22import android.filterfw.core.FilterContext; 23import android.filterfw.core.Frame; 24import android.filterfw.core.FrameFormat; 25import android.filterfw.core.GenerateFieldPort; 26import android.filterfw.core.KeyValueMap; 27import android.filterfw.format.ImageFormat; 28import android.graphics.Bitmap; 29import android.graphics.Bitmap.CompressFormat; 30 31import android.util.Log; 32 33import java.io.OutputStream; 34import java.io.IOException; 35 36/** 37 * @hide 38 */ 39public 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