1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
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 TENSORFLOW_LITE_EXPERIMENTAL_ACCELERATION_MINI_BENCHMARK_METRICS_JPEG_HEADER_PARSER_H_
16 #define TENSORFLOW_LITE_EXPERIMENTAL_ACCELERATION_MINI_BENCHMARK_METRICS_JPEG_HEADER_PARSER_H_
17 
18 #include <string>
19 #include <tuple>
20 
21 #include "tensorflow/lite/c/c_api_types.h"
22 #include "tensorflow/lite/experimental/acceleration/mini_benchmark/decode_jpeg_status.h"
23 #include "tensorflow/lite/experimental/acceleration/mini_benchmark/jpeg_common.h"
24 #include "tensorflow/lite/string_type.h"
25 #include "tensorflow/lite/string_util.h"
26 
27 namespace tflite {
28 namespace acceleration {
29 namespace decode_jpeg_kernel {
30 
31 // Extract the info in JpegHeader from the given buffer.
32 // Fails if the buffer doesn't contain a valid JPEG image in JFIF format.
33 Status ReadJpegHeader(const tflite::StringRef& jpeg_image_data,
34                       JpegHeader* header);
35 
36 // Writes into the given string the content of the JPEG image altered with
37 // the content of new_header.
38 // This is intented to be used in tests to forge existing images.
39 Status BuildImageWithNewHeader(const tflite::StringRef& orig_jpeg_image_data,
40                                const JpegHeader& new_header,
41                                std::string& new_image_data);
42 
43 }  // namespace decode_jpeg_kernel
44 }  // namespace acceleration
45 }  // namespace tflite
46 
47 #endif  // TENSORFLOW_LITE_EXPERIMENTAL_ACCELERATION_MINI_BENCHMARK_METRICS_JPEG_HEADER_PARSER_H_
48