1 /**
2  * RFX codec encoder
3  *
4  * Copyright 2014-2015 Jay Sorg <jay.sorg@gmail.com>
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 __RFXCODEC_ENCODE_H
20 #define __RFXCODEC_ENCODE_H
21 
22 #include <rfxcodec_common.h>
23 
24 struct rfx_rect
25 {
26     int x;
27     int y;
28     int cx;
29     int cy;
30 };
31 
32 struct rfx_tile
33 {
34     int x; /* multiple of 64 */
35     int y; /* multiple of 64 */
36     int cx; /* must be 64 or less */
37     int cy; /* must be 64 or less */
38     int quant_y;
39     int quant_cb;
40     int quant_cr;
41 };
42 
43 void *
44 rfxcodec_encode_create(int width, int height, int format, int flags);
45 int
46 rfxcodec_encode_create_ex(int width, int height, int format, int flags,
47                           void **handle);
48 int
49 rfxcodec_encode_destroy(void *handle);
50 /* quants, 5 ints per set, should be num_quants * 5 chars in quants)
51  * each char is 2 quant values
52  * quantizer order is
53  * 0 - LL3
54  * 1 - LH3
55  * 2 - HL3
56  * 3 - HH3
57  * 4 - LH2
58  * 5 - HL2
59  * 6 - HH2
60  * 7 - LH1
61  * 8 - HL1
62  * 9 - HH1 */
63 int
64 rfxcodec_encode(void *handle, char *cdata, int *cdata_bytes,
65                 const char *buf, int width, int height, int stride_bytes,
66                 const struct rfx_rect *region, int num_region,
67                 const struct rfx_tile *tiles, int num_tiles,
68                 const char *quants, int num_quants);
69 int
70 rfxcodec_encode_ex(void *handle, char *cdata, int *cdata_bytes,
71                    const char *buf, int width, int height, int stride_bytes,
72                    const struct rfx_rect *region, int num_region,
73                    const struct rfx_tile *tiles, int num_tiles,
74                    const char *quants, int num_quants, int flags);
75 
76 /* use simple types here, no sint16_t, uint8_t, ... */
77 typedef int (*rfxencode_rlgr1_proc)(const short *data, unsigned char *buffer, int buffer_size);
78 typedef int (*rfxencode_rlgr3_proc)(const short *data, unsigned char *buffer, int buffer_size);
79 typedef int (*rfxencode_differential_proc)(short *buffer, int buffer_size);
80 typedef int (*rfxencode_quantization_proc)(short *buffer, const char *quantization_values);
81 typedef int (*rfxencode_dwt_2d_proc)(const unsigned char *in_buffer, short *buffer, short *dwt_buffer);
82 
83 typedef int (*rfxencode_diff_rlgr1_proc)(short *coef, unsigned char *cdata, int cdata_size);
84 typedef int (*rfxencode_diff_rlgr3_proc)(short *coef, unsigned char *cdata, int cdata_size);
85 
86 typedef int (*rfxencode_dwt_shift_x86_sse2_proc)(const char *qtable, const unsigned char *data, short *dwt_buffer1, short *dwt_buffer);
87 typedef int (*rfxencode_dwt_shift_x86_sse41_proc)(const char *qtable, const unsigned char *data, short *dwt_buffer1, short *dwt_buffer);
88 
89 typedef int (*rfxencode_dwt_shift_amd64_sse2_proc)(const char *qtable, const unsigned char *data, short *dwt_buffer1, short *dwt_buffer);
90 typedef int (*rfxencode_dwt_shift_amd64_sse41_proc)(const char *qtable, const unsigned char *data, short *dwt_buffer1, short *dwt_buffer);
91 
92 struct rfxcodec_encode_internals
93 {
94     rfxencode_rlgr1_proc rfxencode_rlgr1;
95     rfxencode_rlgr3_proc rfxencode_rlgr3;
96     rfxencode_differential_proc rfxencode_differential;
97     rfxencode_quantization_proc rfxencode_quantization;
98     rfxencode_dwt_2d_proc rfxencode_dwt_2d;
99     rfxencode_diff_rlgr1_proc rfxencode_diff_rlgr1;
100     rfxencode_diff_rlgr3_proc rfxencode_diff_rlgr3;
101     rfxencode_dwt_shift_x86_sse2_proc rfxencode_dwt_shift_x86_sse2;
102     rfxencode_dwt_shift_x86_sse41_proc rfxencode_dwt_shift_x86_sse41;
103     rfxencode_dwt_shift_amd64_sse2_proc rfxencode_dwt_shift_amd64_sse2;
104     rfxencode_dwt_shift_amd64_sse41_proc rfxencode_dwt_shift_amd64_sse41;
105 };
106 
107 int
108 rfxcodec_encode_get_internals(struct rfxcodec_encode_internals *internals);
109 
110 #endif
111