as3_jpeg.c
Go to the documentation of this file.
1 /*
2  * This file is part of the OpenKinect Project. http://www.openkinect.org
3  *
4  * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
5  * for details.
6  *
7  * This code is licensed to you under the terms of the Apache License, version
8  * 2.0, or, at your option, the terms of the GNU General Public License,
9  * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
10  * or the following URLs:
11  * http://www.apache.org/licenses/LICENSE-2.0
12  * http://www.gnu.org/licenses/gpl-2.0.txt
13  *
14  * If you redistribute this file in source form, modified or unmodified, you
15  * may:
16  * 1) Leave this header intact and distribute it under the same terms,
17  * accompanying it with the APACHE20 and GPL20 files, or
18  * 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
19  * 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
20  * In all cases you must keep the copyright notice intact and include a copy
21  * of the CONTRIB file.
22  *
23  * Binary distributions must follow the binary distribution requirements of
24  * either License.
25  */
26 
27 #include "as3_jpeg.h"
28 
29 /*
30  * Compress RGB buffer in memory
31  */
32 int RGB_2_JPEG(unsigned char *buffer, unsigned char **compressed, long unsigned int *new_len, int quality) {
33  struct jpeg_compress_struct cinfo = {0};
34  struct jpeg_error_mgr jerr;
35  JSAMPROW row_ptr[1];
36  int row_stride;
37 
38  *compressed = NULL;
39  *new_len = 0;
40 
41  cinfo.err = jpeg_std_error(&jerr);
42  jpeg_create_compress(&cinfo);
43  jpeg_mem_dest(&cinfo, compressed, new_len);
44 
45  cinfo.image_width = 640;
46  cinfo.image_height = 480;
47  cinfo.input_components = 3;
48  cinfo.in_color_space = JCS_RGB;
49 
50  jpeg_set_defaults(&cinfo);
51  jpeg_set_quality(&cinfo, quality, TRUE);
52  jpeg_start_compress(&cinfo, TRUE);
53  row_stride = 640 * 3;
54 
55  while (cinfo.next_scanline < cinfo.image_height) {
56  row_ptr[0] = &buffer[cinfo.next_scanline * row_stride];
57  jpeg_write_scanlines(&cinfo, row_ptr, 1);
58  }
59 
60  jpeg_finish_compress(&cinfo);
61  jpeg_destroy_compress(&cinfo);
62 
63  return 1;
64 }
#define TRUE
Definition: OniCTypes.h:31
int RGB_2_JPEG(unsigned char *buffer, unsigned char **compressed, long unsigned int *new_len, int quality)
Definition: as3_jpeg.c:32


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Mon Jun 10 2019 13:46:42