1 /*
2  * Copyright Samsung Electronics Co.,LTD.
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __HARDWARE_SAMSUNG_EXYNOS_HWJPEGDECOMPRESSOR_H__
19 #define __HARDWARE_SAMSUNG_EXYNOS_HWJPEGDECOMPRESSOR_H__
20 
21 #ifdef __cplusplus
22 extern "C" {
23 
24 /*
25  * hwjpeg_decompress_ptr - handle of decompressor instance
26  */
27 typedef struct hwjpeg_decompressor_struct {
28     unsigned int image_width;     /* width of the compressed image */
29     unsigned int image_height;    /* height of the compressed image */
30     unsigned char num_components; /* number of components of the compressed image */
31     unsigned char
32             chroma_h_samp_factor; /* horizontal chroma sampling factor of the compressed image */
33     unsigned char
34             chroma_v_samp_factor; /* vertical chroma sampling factor of the compressed image */
35     unsigned char scale_factor; /* down-scaling factor during decompression: one of 1, 2, 4 and 8 */
36 
37     unsigned int output_width;  /* width of the output image (image_width/scale_factor) */
38     unsigned int output_height; /* height of the output image (image_height/scale_factor) */
39     __u32 output_format; /* 4CC style format identifier of the output image defined in videodev2.h
40                           */
41 } *hwjpeg_decompress_ptr;
42 
43 /*
44  * hwjpeg_create_decompress - create an instance of decompressor
45  *
46  * @return: the handle of the decompressor instance. NULL on failure.
47  *
48  * The decompresson process starts from calling this function. The return value
49  * is the handle of the decompressor instance. Every step of the decompression
50  * process needs the handle. The handle should be destroyed with
51  * hwjpeg_destroy_decompress() when it is no longer required.
52  */
53 hwjpeg_decompress_ptr hwjpeg_create_decompress(void);
54 
55 /*
56  * hwjpeg_file_src - configure the path to a file of compressed JPEG stream
57  *
58  * @cinfo: decompressor instance handle
59  * @path: path to the file of compressed JPEG stream.
60  *        It is assumed that EOI is at the end of the file.
61  * @return: false on failure
62  */
63 bool hwjpeg_file_src(hwjpeg_decompress_ptr cinfo, const char *path);
64 
65 /*
66  * hwjpeg_dmabuf_src - configure the buffer file descriptor that contains the compressed JPEG stream
67  *
68  * @cinfo: decompressor instance handle
69  * @infd: the file descriptor exported by ION of the buffer that contains the compressed JPEG stream
70  * @insize: the length in bytes of @infd. It is assumed that EOI is at the end of the buffer.
71  * @dummybytes: The available dummy bytes after @insize.
72  * @return: false on failure
73  */
74 bool hwjpeg_dmabuf_src(hwjpeg_decompress_ptr cinfo, int infd, size_t insize, size_t dummybytes);
75 
76 /*
77  * hwjpeg_mem_src - configure the buffer that contains the compressed JPEG stream
78  *
79  * @cinfo: decompressor instance handle
80  * @inbuffer: the address of the buffer that contains the compressed JPEG stream
81  * @insize: the length in bytes of @inbuffer. It is assumed that EOI is at the end of the buffer.
82  * @dummybytes: The available dummy bytes after @insize.
83  * @return: false on failure
84  */
85 bool hwjpeg_mem_src(hwjpeg_decompress_ptr cinfo, unsigned char *inbuffer, size_t insize,
86                     size_t dummybytes);
87 
88 /*
89  * hwjpeg_config_image_format - configure output image format
90  *
91  * @cinfo: decompressor instance handle
92  * @v4l2_pix_fmt: fourcc format identifier defined in linux/videodev2.h
93  */
94 void hwjpeg_config_image_format(hwjpeg_decompress_ptr cinfo, __u32 v4l2_pix_fmt);
95 
96 /*
97  * hwjpeg_mem_dst - configure the buffer to store decompressed image
98  *
99  * @cinfo: decompressor instance handle
100  * @outbuffer: The array of addresses of the buffers to stroe decompressed image
101  *             The maximum number of elements of @outbuffer is 3. The number of elements
102  *             of @outbuffer depends on the image format configured by hwjpeg_config_image_format().
103  * @outsize: The lengths in bytes of the buffers of @outbuffer.
104  * @num_buffers: The number of elements in @outsizes and @outbuffer
105  * @return: false on failure.
106  */
107 bool hwjpeg_mem_dst(hwjpeg_decompress_ptr cinfo, unsigned char *outbuffer[], size_t outsize[],
108                     unsigned int num_buffers);
109 
110 /*
111  * hwjpeg_dmabuf_dst - configure the buffer to store decompressed image
112  *
113  * @cinfo: decompressor instance handle
114  * @outfd: The array of file descriptors exported by ION of the buffers to stroe decompressed image
115  *         The maximum number of elements of @outfd is 3. The number of elements of @outfd depends
116  *         on the image format configured by hwjpeg_config_image_format().
117  * @outsizes: The lengths in bytes of the buffers of @outfd.
118  * @num_buffers: The number of elements in @outsizes and @outfd
119  * @return: false on failure.
120  */
121 bool hwjpeg_dmabuf_dst(hwjpeg_decompress_ptr cinfo, int outfd[], size_t outsize[],
122                        unsigned int num_buffers);
123 
124 /*
125  * hwjpeg_set_downscale_factor - configure the downscaling factor during decompression
126  *
127  * @cinfo: decompressor instance handle
128  * @factor: downscaling factor. @factor should be one of 1, 2, 4 and 8.
129  *
130  * Downscaling factor is the inverse number of the downscaling ratio. @cinfo->output_width and
131  * @cinfo->output_height is decided by @factor.
132  *  - @cinfo->output_width = @cinfo->image_width / @factor
133  *  - @cinfo->output_height = @cinfo->image_height / @factor
134  * Note that both of @cinfo->image_width / @factor and @cinfo->image_height / @factor
135  * should be also integers. The results should be also even number according to the
136  * output image format configured by hwjpeg_config_image_format().
137  * Otherwise, the decompression will fail.
138  */
139 void hwjpeg_set_downscale_factor(hwjpeg_decompress_ptr cinfo, unsigned int factor);
140 
141 /*
142  * hwjpeg_read_header - reads the headers of the compressed JPEG stream
143  *
144  * @cinfo: decompressor instance handle
145  * @return: false on failure.
146  *
147  * NOTE that the fields of hwjpeg_decompression_ptr is available after hwjpeg_read_header()
148  * returns true.
149  */
150 bool hwjpeg_read_header(hwjpeg_decompress_ptr cinfo);
151 
152 /*
153  * hwjpeg_has_enough_stream_buffer - Confirm if the stream buffer is enough
154  *
155  * @cinfo: decompressor instance handle
156  * @return: true if the stream buffer is enough to decompress by H/W
157  *
158  * This function should be called after hwjpeg_read_header() is called
159  * successfully.
160  */
161 bool hwjpeg_has_enough_stream_buffer(hwjpeg_decompress_ptr cinfo);
162 
163 /*
164  * hwjpeg_start_decompress - starts decompression
165  *
166  * @cinfo: decompressor instance handle
167  * @return: false on failure.
168  *
169  * This function blocks until the decompression finishes.
170  */
171 bool hwjpeg_start_decompress(hwjpeg_decompress_ptr cinfo);
172 
173 /*
174  * hwjpeg_destroy_decompress - releases all resources of the decompressor instance
175  *
176  * @cinfo: decompressor instance handle to destroy
177  */
178 void hwjpeg_destroy_decompress(hwjpeg_decompress_ptr cinfo);
179 
180 };     /* extern "C" */
181 #endif /* __cplusplus */
182 
183 #endif /*__HARDWARE_SAMSUNG_EXYNOS7420_HWJPEGDECOMPRESSOR_H__*/
184