xref: /aosp_15_r20/external/tensorflow/tensorflow/core/lib/jpeg/jpeg_handle.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2015 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 
16 // This file declares the functions and structures for memory I/O with libjpeg
17 // These functions are not meant to be used directly, see jpeg_mem.h instead.
18 
19 #ifndef TENSORFLOW_CORE_LIB_JPEG_JPEG_HANDLE_H_
20 #define TENSORFLOW_CORE_LIB_JPEG_JPEG_HANDLE_H_
21 
22 #include "tensorflow/core/platform/jpeg.h"
23 #include "tensorflow/core/platform/types.h"
24 
25 namespace tensorflow {
26 namespace jpeg {
27 
28 // Handler for fatal JPEG library errors: clean up & return
29 void CatchError(j_common_ptr cinfo);
30 
31 typedef struct {
32   struct jpeg_destination_mgr pub;
33   JOCTET *buffer;
34   int bufsize;
35   int datacount;
36   tstring *dest;
37 } MemDestMgr;
38 
39 typedef struct {
40   struct jpeg_source_mgr pub;
41   const unsigned char *data;
42   unsigned long int datasize;
43   bool try_recover_truncated_jpeg;
44 } MemSourceMgr;
45 
46 void SetSrc(j_decompress_ptr cinfo, const void *data,
47             unsigned long int datasize, bool try_recover_truncated_jpeg);
48 
49 // JPEG destination: we will store all the data in a buffer "buffer" of total
50 // size "bufsize", if the buffer overflows, we will be in trouble.
51 void SetDest(j_compress_ptr cinfo, void *buffer, int bufsize);
52 // Same as above, except that buffer is only used as a temporary structure and
53 // is emptied into "destination" as soon as it fills up.
54 void SetDest(j_compress_ptr cinfo, void *buffer, int bufsize,
55              tstring *destination);
56 
57 }  // namespace jpeg
58 }  // namespace tensorflow
59 
60 #endif  // TENSORFLOW_CORE_LIB_JPEG_JPEG_HANDLE_H_
61