1 /* 2 * Copyright (C) 2023 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 #pragma once 17 18 #include <cstdint> 19 #include <string> 20 #include <vector> 21 22 #include "Expected.h" 23 24 namespace gfxstream { 25 26 struct RGBAImage { 27 uint32_t width; 28 uint32_t height; 29 std::vector<uint8_t> pixels; 30 }; 31 gfxstream::expected<RGBAImage, std::string> LoadRGBAFromBitmapFile( 32 const std::string& filename); 33 34 gfxstream::expected<Ok, std::string> SaveRGBAToBitmapFile( 35 uint32_t w, 36 uint32_t h, 37 const uint8_t* rgbaPixels, 38 const std::string& filename = ""); 39 40 struct YUV420Image { 41 uint32_t width; 42 uint32_t height; 43 std::vector<uint8_t> y; 44 std::vector<uint8_t> u; 45 std::vector<uint8_t> v; 46 }; 47 gfxstream::expected<YUV420Image, std::string> LoadYUV420FromBitmapFile( 48 const std::string& filename); 49 50 RGBAImage FillWithColor(uint32_t width, 51 uint32_t height, 52 uint8_t red, 53 uint8_t green, 54 uint8_t blue, 55 uint8_t alpha); 56 57 YUV420Image ConvertRGBA8888ToYUV420(const RGBAImage& image); 58 59 struct PixelDiff { 60 uint32_t x; 61 uint32_t y; 62 uint8_t expectedR; 63 uint8_t expectedG; 64 uint8_t expectedB; 65 uint8_t expectedA; 66 uint8_t actualR; 67 uint8_t actualG; 68 uint8_t actualB; 69 uint8_t actualA; 70 }; 71 72 gfxstream::expected<Ok, std::vector<PixelDiff>> CompareImages( 73 const RGBAImage& expected, 74 const RGBAImage& actual); 75 76 } // namespace gfxstream 77