1 /*
2 * Copyright 2020, 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 <stddef.h>
18
19 #include <teeui/label.h>
20 #include <teeui/localization/ConfirmationUITranslations.h>
21
22 #include "example_utils.h"
23
24 namespace teeui {
25 namespace example {
26
alfaCombineChannel(uint32_t shift,double alfa,uint32_t a,uint32_t b)27 uint32_t alfaCombineChannel(uint32_t shift, double alfa, uint32_t a, uint32_t b) {
28 a >>= shift;
29 a &= 0xff;
30 b >>= shift;
31 b &= 0xff;
32 double acc = alfa * a + (1 - alfa) * b;
33 if (acc <= 0) return 0;
34 uint32_t result = acc;
35 if (result > 255) return 255 << shift;
36 return result << shift;
37 }
38
drawPixel(uint32_t x,uint32_t y,uint32_t color) const39 Error FrameBuffer::drawPixel(uint32_t x, uint32_t y, uint32_t color) const {
40 size_t pos = (top_ + y) * lineStride_ + x + left_;
41 if (pos >= size_in_elements_) {
42 return Error::OutOfBoundsDrawing;
43 }
44 double alfa = (color & 0xff000000) >> 24;
45 alfa /= 255.0;
46 auto acc = buffer_[pos];
47 buffer_[pos] = alfaCombineChannel(0, alfa, color, acc) |
48 alfaCombineChannel(8, alfa, color, acc) |
49 alfaCombineChannel(16, alfa, color, acc);
50 return Error::OK;
51 }
52
translate(LabelImpl * label)53 void translate(LabelImpl* label) {
54 uint64_t textId = label->textId();
55 const char* translation =
56 localization::lookup(static_cast<localization::TranslationId>(textId));
57 label->setText({&translation[0], &translation[strlen(translation)]});
58 }
59
60 } // namespace example
61 } // namespace teeui