Home | History | Annotate | Download | only in videoeditor
      1 /*
      2  * Copyright (C) 2010 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.media.videoeditor;
     19 
     20 /**
     21  * This class allows to apply color effect on a media item.
     22  * {@hide}
     23  */
     24 public class EffectColor extends Effect {
     25 
     26     /**
     27      * Change the video frame color to the RGB color value provided
     28      */
     29     public static final int TYPE_COLOR = 1;
     30     /**
     31      * Change the video frame color to a gradation from RGB color (at the top of
     32      * the frame) to black (at the bottom of the frame).
     33      */
     34     public static final int TYPE_GRADIENT = 2;
     35     /**
     36      * Change the video frame color to sepia
     37      */
     38     public static final int TYPE_SEPIA = 3;
     39     /**
     40      * Invert the video frame color
     41      */
     42     public static final int TYPE_NEGATIVE = 4;
     43     /**
     44      * Make the video look like as if it was recorded in 50's
     45      */
     46     public static final int TYPE_FIFTIES = 5;
     47     /**
     48      * Change the video frame color to the RGB color value GREEN
     49      */
     50     public static final int GREEN = 0x0000ff00;
     51     /**
     52      * Change the video frame color to the RGB color value PINK
     53      */
     54     public static final int PINK = 0x00ff66cc;
     55     /**
     56      * Change the video frame color to the RGB color value GRAY
     57      */
     58     public static final int GRAY = 0x007f7f7f;
     59 
     60     /**
     61      *  The effect type
     62      */
     63     private final int mType;
     64 
     65     /**
     66      *  The effect color
     67      */
     68     private final int mColor;
     69 
     70     /**
     71      * An object of this type cannot be instantiated by using the default
     72      * constructor
     73      */
     74     @SuppressWarnings("unused")
     75     private EffectColor() {
     76         this(null, null, 0, 0, 0, 0);
     77     }
     78 
     79     /**
     80      * Constructor
     81      *
     82      * @param mediaItem The media item owner
     83      * @param effectId The effect id
     84      * @param startTimeMs The start time relative to the media item to which it
     85      *            is applied
     86      * @param durationMs The duration of this effect in milliseconds
     87      * @param type type of the effect. type is one of: TYPE_COLOR,
     88      *            TYPE_GRADIENT, TYPE_SEPIA, TYPE_NEGATIVE, TYPE_FIFTIES.
     89      * @param color If type is TYPE_COLOR, color is the RGB color as 888.
     90      *              If type is TYPE_GRADIENT, color is the RGB color at the
     91      *              top of the frame. Otherwise, color is ignored
     92      */
     93     public EffectColor(MediaItem mediaItem, String effectId, long startTimeMs,
     94                       long durationMs, int type, int color) {
     95         super(mediaItem, effectId, startTimeMs, durationMs);
     96         switch (type) {
     97             case TYPE_COLOR:
     98             case TYPE_GRADIENT: {
     99                 switch (color) {
    100                     case GREEN:
    101                     case PINK:
    102                     case GRAY:
    103                         mColor = color;
    104                         break;
    105 
    106                     default:
    107                         throw new IllegalArgumentException("Invalid Color: " + color);
    108                     }
    109                     break;
    110             }
    111             case TYPE_SEPIA:
    112             case TYPE_NEGATIVE:
    113             case TYPE_FIFTIES: {
    114                 mColor = -1;
    115                 break;
    116             }
    117 
    118             default: {
    119                 throw new IllegalArgumentException("Invalid type: " + type);
    120             }
    121         }
    122         mType = type;
    123     }
    124 
    125     /**
    126      * Get the effect type.
    127      *
    128      * @return The effect type
    129      */
    130     public int getType() {
    131         return mType;
    132     }
    133 
    134     /**
    135      * Get the color if effect type is TYPE_COLOR or TYPE_GRADIENT.
    136      *
    137      * @return the color as RGB 888 if type is TYPE_COLOR or TYPE_GRADIENT.
    138      */
    139     public int getColor() {
    140         return mColor;
    141     }
    142 }
    143