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