1 // Copyright 2019 The Amber Authors.
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 #ifndef SAMPLES_PNG_H_
16 #define SAMPLES_PNG_H_
17 
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
22 #include "amber/amber.h"
23 
24 namespace png {
25 
26 /// Converts the image of dimensions |width| and |height| and with pixels stored
27 /// in row-major order in |values| with format B8G8R8A8 into PNG format,
28 /// returning the PNG binary as a string.
29 amber::Result ConvertToPNG(uint32_t width,
30                            uint32_t height,
31                            const std::vector<amber::Value>& values,
32                            std::vector<uint8_t>* buffer);
33 
34 /// Loads a PNG image from |file_name|. Image dimensions of the loaded file are
35 /// stored into |width| and |height|, and the image data is stored in a one
36 /// byte per data element format into |values|.
37 amber::Result LoadPNG(const std::string file_name,
38                       uint32_t* width,
39                       uint32_t* height,
40                       std::vector<amber::Value>* values);
41 
42 }  // namespace png
43 
44 #endif  // SAMPLES_PNG_H_
45