1 // Copyright (C) 2024 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "image.h"
16 
17 #include <vector>
18 
19 namespace cuttlefish {
20 
CreateImageContentsWithFourCorners(uint32_t width,uint32_t height,const RGBA8888 & bottomLeft,const RGBA8888 & bottomRight,const RGBA8888 & topLeft,const RGBA8888 & topRight)21 std::vector<uint8_t> CreateImageContentsWithFourCorners(
22     uint32_t width, uint32_t height, const RGBA8888& bottomLeft,
23     const RGBA8888& bottomRight, const RGBA8888& topLeft,
24     const RGBA8888& topRight) {
25   std::vector<uint8_t> ret;
26   ret.reserve(width * height * 4);
27 
28   const RGBA8888* grid[2][2] = {
29       {&topLeft, &bottomLeft},
30       {&topRight, &bottomRight},
31   };
32 
33   for (uint32_t y = 0; y < height; y++) {
34     const bool isBotHalf = (y <= (height / 2));
35     for (uint32_t x = 0; x < width; x++) {
36       const bool isLeftHalf = (x <= (width / 2));
37 
38       const RGBA8888* color = grid[isLeftHalf ? 0 : 1][isBotHalf ? 0 : 1];
39       ret.push_back(color->r);
40       ret.push_back(color->g);
41       ret.push_back(color->b);
42       ret.push_back(color->a);
43     }
44   }
45   return ret;
46 }
47 
48 }  // namespace cuttlefish