1 /*
2  * Copyright 2016 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 #ifndef HDR_PLUS_CLIENT_UTILS_H
18 #define HDR_PLUS_CLIENT_UTILS_H
19 
20 #include <utils/Errors.h>
21 
22 #include "HdrPlusTypes.h"
23 
24 namespace android {
25 namespace hdrplus_client_utils {
26 
27 /*
28  * Write the image buffer to a .ppm file.
29  *
30  * filename is the filename of the .ppm file and should include ".ppm" in the end.
31  * streamConfig is the stream configuration of the buffer.
32  * buffer is the buffer to be saved to a .ppm file.
33  *
34  * Returns
35  *  OK:             if the file is saved successfully.
36  *  BAD_VALUE:      if the format is not support or the stream configuration is invalid.
37  *  NO_INIT:        if it failed to open the file.
38  */
39 status_t writePpm(const std::string &filename, const pbcamera::StreamConfiguration &streamConfig,
40         const pbcamera::StreamBuffer &buffer);
41 
42 /*
43  * Compare the image buffer against a golden .ppm file.
44  *
45  * filename is the filename of the .ppm file and should include ".ppm" in the end.
46  * streamConfig is the stream configuration of the buffer.
47  * buffer is the buffer to be compared.
48  * diffRatio will be the difference ratio between the image buffer and the golden ppm file.
49  *           It's calculated as sum(R, G, B diffs in each pixel) / (width * height * 256 * 3)
50  *
51  * Returns
52  *  OK:             if the comparison completed successfully.
53  *  BAD_VALUE:      if the format is not support or the stream configuration is invalid, or the
54  *                  file cannot be parsed correctly.
55  *  NO_INIT:        if it failed to open the file.
56  */
57 status_t comparePpm(const std::string &filename, const pbcamera::StreamConfiguration &streamConfig,
58         const pbcamera::StreamBuffer &buffer, float *diffRatio);
59 
60 } // hdrplus_client_utils
61 } // namespace android
62 
63 #endif // HDR_PLUS_CLIENT_UTILS_H
64