blob: 84230a72f1c2095fe865d51929d34c6fa921c221 [file] [log] [blame]
John Reck16c9d6a2015-11-17 15:51:08 -08001/*
2 * Copyright (C) 2015 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#include "TestUtils.h"
18
19namespace android {
20namespace uirenderer {
21
22SkColor TestUtils::interpolateColor(float fraction, SkColor start, SkColor end) {
23 int startA = (start >> 24) & 0xff;
24 int startR = (start >> 16) & 0xff;
25 int startG = (start >> 8) & 0xff;
26 int startB = start & 0xff;
27
28 int endA = (end >> 24) & 0xff;
29 int endR = (end >> 16) & 0xff;
30 int endG = (end >> 8) & 0xff;
31 int endB = end & 0xff;
32
33 return (int)((startA + (int)(fraction * (endA - startA))) << 24)
34 | (int)((startR + (int)(fraction * (endR - startR))) << 16)
35 | (int)((startG + (int)(fraction * (endG - startG))) << 8)
36 | (int)((startB + (int)(fraction * (endB - startB))));
37}
38
39} /* namespace uirenderer */
40} /* namespace android */