1 /*
2    Copyright (C) 2009 Red Hat, Inc.
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef GLZ_ENCODER_H_
19 #define GLZ_ENCODER_H_
20 
21 /* Manging the lz encoding using a dictionary that is shared among encoders */
22 
23 #include <common/lz_common.h>
24 
25 #include "red-common.h"
26 #include "glz-encoder-dict.h"
27 
28 SPICE_BEGIN_DECLS
29 
30 struct GlzEncoderUsrContext {
31     SPICE_GNUC_PRINTF(2, 3) void (*error)(GlzEncoderUsrContext *usr, const char *fmt, ...);
32     SPICE_GNUC_PRINTF(2, 3) void (*warn)(GlzEncoderUsrContext *usr, const char *fmt, ...);
33     SPICE_GNUC_PRINTF(2, 3) void (*info)(GlzEncoderUsrContext *usr, const char *fmt, ...);
34     void    *(*malloc)(GlzEncoderUsrContext *usr, int size);
35     void (*free)(GlzEncoderUsrContext *usr, void *ptr);
36 
37     // get the next chunk of the image which is entered to the dictionary. If the image is down to
38     // top, return it from the last line to the first one (stride should always be positive)
39     int (*more_lines)(GlzEncoderUsrContext *usr, uint8_t **lines);
40 
41     // get the next chunk of the compressed buffer.return number of bytes in the chunk.
42     int (*more_space)(GlzEncoderUsrContext *usr, uint8_t **io_ptr);
43 
44     // called when an image is removed from the dictionary, due to the window size limit
45     void (*free_image)(GlzEncoderUsrContext *usr, GlzUsrImageContext *image);
46 
47 };
48 
49 typedef void GlzEncoderContext;
50 
51 GlzEncoderContext *glz_encoder_create(uint8_t id, GlzEncDictContext *dictionary,
52                                       GlzEncoderUsrContext *usr);
53 
54 void glz_encoder_destroy(GlzEncoderContext *opaque_encoder);
55 
56 /*
57         assumes width is in pixels and stride is in bytes
58     usr_context       : when an image is released from the window due to capacity overflow,
59                         usr_context is given as a parameter to the free_image callback.
60     o_enc_dict_context: if glz_enc_dictionary_remove_image is called, it should be
61                         called with the o_enc_dict_context that is associated with
62                         the image.
63 
64         return: the number of bytes in the compressed data and sets o_enc_dict_context
65 
66         NOTE  : currently supports only rgb images in which width*bytes_per_pixel = stride OR
67                 palette images in which stride equals the min number of bytes to hold a line.
68                 The stride should be > 0
69 */
70 int glz_encode(GlzEncoderContext *opaque_encoder, LzImageType type, int width, int height,
71                int top_down, uint8_t *lines, unsigned int num_lines, int stride,
72                uint8_t *io_ptr, unsigned int num_io_bytes, GlzUsrImageContext *usr_context,
73                GlzEncDictImageContext **o_enc_dict_context);
74 
75 SPICE_END_DECLS
76 
77 #endif /* GLZ_ENCODER_H_ */
78