1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  * Copyright (C) 2016 Mopria Alliance, Inc.
4  * Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef LIB_PHOTO_SCALER_H
20 #define LIB_PHOTO_SCALER_H
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include "wtypes.h"
27 
28 typedef unsigned char bool_t;
29 
30 /*
31  * A 64-bit floating point value
32  */
33 typedef struct float64_s {
34     uint32 decimal;
35     uint32 fraction;
36 } float64_t;
37 
38 /*
39  * Mode selected for a scaling operation
40  */
41 typedef enum scaler_modes_e {
42     PSCALER_SCALE_UP = 1,
43     PSCALER_SCALE_DOWN = 2,
44     PSCALER_SCALE_MIXED_XUP = 5,
45     PSCALER_SCALE_MIXED_YUP = 7,
46 
47     PSCALER_SCALE_MODE_INVALID
48 } scaler_mode_t;
49 
50 /*
51  * Context structure for a scaling operation
52  */
53 typedef struct scaler_config_s {
54     uint16 iSrcWidth;           // input width (x-axis dimension)
55     uint16 iSrcHeight;          // input height (y-axis dimension)
56 
57     uint16 iOutWidth;           // output width (x-axis dimension)
58     uint16 iOutHeight;          // output height (y-axis dimension)
59 
60     uint8 *pSrcBuf;             // input buffers [plane]
61     uint16 iSrcBufWidth;        // input buffer width (typically source width)
62 
63     uint8 *pOutBuf;             // output buffers [plane]
64     uint16 iOutBufWidth;        // output buffer width
65 
66     uint8 *pTmpBuf;             // mixed axis temp buffer
67     float64_t fSrcStartRow;     // first input row as a float
68     uint16 iSrcStartRow;        // first input row of this slice
69     uint16 iSrcEndRow;          // last input row of this slice
70 
71     uint16 iOutStartRow;        // first output row of this slice
72     uint16 iOutEndRow;          // last output row of this slice
73 
74     float64_t fSrcStartColumn;  // first input column as a float
75 
76     uint16 iOutStartColumn;     // first output column of this slice
77 
78     float64_t fXfactor;         // x_factor_int & x_factor_fract
79     float64_t fXfactorInv;      // x_factor_inv_int & x_factor_inv_fract
80     float64_t fYfactor;         // y_factor_int & y_factor_fract
81     float64_t fYfactorInv;      // y_factor_inv_int & y_factor_inv_fract
82 
83     scaler_mode_t scaleMode;    // scale mode for the current image
84 } scaler_config_t;
85 
86 /*
87  * Called once per job to initialize pscaler_config for specified input/output sizes
88  */
89 extern void scaler_make_image_scaler_tables(uint16 image_input_width, uint16 image_input_buf_width,
90         uint16 image_output_width, uint16 image_output_buf_width, uint16 image_input_height,
91         uint16 image_output_height, scaler_config_t *pscaler_config);
92 
93 /*
94  * Called once to configure a single image stripe/slice. Must be called after
95  * scaler_make_image_scaler_tables.
96  */
97 extern void scaler_calculate_scaling_rows(uint16 start_output_row_number,
98         uint16 end_output_row_number, void *tables_ptr, uint16 *start_input_row_number,
99         uint16 *end_input_row_number, uint16 *num_output_rows_generated,
100         uint16 *num_rows_offset_to_start_output_row,
101         uint32 *mixed_axis_temp_buffer_size_needed);
102 
103 /*
104  * Called after each call to scaler_calculate_scaling_rows to produce scaled output
105  */
106 extern void scaler_scale_image_data(uint8 *input_plane, void *tables_ptr,
107         uint8 *scaled_output_plane, uint8 *temp_buffer_for_mixed_axis_scaling);
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif // LIB_PHOTO_SCALER_H