#include "jpeg_memory.h"
#include <iostream>
Go to the source code of this file.
|
| jpeg_memory_dest (j_compress_ptr cinfo, JOCTET *buffer, int bufsize) |
|
int | jpeg_compress (char *dst, char *src, int width, int height, int dstsize, int quality) |
|
int | jpeg_compress_to_file (char *src, char *file, int width, int height, int quality) |
|
static void | init_source (j_decompress_ptr cinfo) |
|
static boolean | fill_input_buffer (j_decompress_ptr cinfo) |
|
static void | skip_input_data (j_decompress_ptr cinfo, long num_bytes) |
|
static void | term_source (j_decompress_ptr cinfo) |
|
void | jpeg_memory_src (j_decompress_ptr cinfo, unsigned char *ptr, size_t size) |
|
void | jpeg_decompress (unsigned char *dst, unsigned char *src, int size, int *w, int *h) |
|
void | jpeg_decompress_from_file (unsigned char *dst, char *file, int size, int *w, int *h) |
|
static boolean fill_input_buffer |
( |
j_decompress_ptr |
cinfo) | |
|
|
static |
static void init_source |
( |
j_decompress_ptr |
cinfo) | |
|
|
static |
int jpeg_compress |
( |
char * |
dst, |
|
|
char * |
src, |
|
|
int |
width, |
|
|
int |
height, |
|
|
int |
dstsize, |
|
|
int |
quality |
|
) |
| |
Definition at line 24 of file jpeg_memory.cpp.
References memory_destination_mgr::datacount, height, jpeg_memory_dest(), TRUE, and width.
26 struct jpeg_compress_struct cinfo;
27 struct jpeg_error_mgr jerr;
28 unsigned char *dataRGB = (
unsigned char*) src;
29 JSAMPROW row_pointer = (JSAMPROW) dataRGB;
36 memset( &cinfo, 0,
sizeof (cinfo) );
37 cinfo.err = jpeg_std_error( &jerr );
38 jpeg_create_compress( &cinfo );
41 cinfo.image_width =
width;
42 cinfo.image_height =
height;
43 cinfo.input_components = 3;
44 cinfo.in_color_space = JCS_RGB;
45 jpgbuff = (JOCTET*) dst;
49 jpeg_set_defaults( &cinfo );
50 jpeg_set_quality( &cinfo, quality,
TRUE );
51 jpeg_start_compress( &cinfo,
TRUE );
53 while (cinfo.next_scanline < cinfo.image_height) {
54 row_pointer = (JSAMPROW) ( dataRGB+(cinfo.next_scanline*3*
width) );
55 jpeg_write_scanlines( &cinfo, &row_pointer, 1 );
57 jpeg_finish_compress( &cinfo );
62 jpeg_destroy_compress( &cinfo );
int jpeg_compress_to_file |
( |
char * |
src, |
|
|
char * |
file, |
|
|
int |
width, |
|
|
int |
height, |
|
|
int |
quality |
|
) |
| |
Definition at line 66 of file jpeg_memory.cpp.
References fclose, fopen, height, TRUE, and width.
69 struct jpeg_compress_struct cinfo;
70 struct jpeg_error_mgr jerr;
72 if ( ( outfile =
fopen(
file,
"wb" ) ) == NULL ) {
73 cerr<<
"can't open "<<
file<<endl;
78 memset( &cinfo, 0,
sizeof (cinfo) );
79 cinfo.err = jpeg_std_error( &jerr );
80 jpeg_create_compress( &cinfo );
83 cinfo.image_width =
width;
84 cinfo.image_height =
height;
85 cinfo.input_components = 3;
86 cinfo.in_color_space = JCS_RGB;
89 jpeg_stdio_dest( &cinfo, outfile );
90 jpeg_set_defaults( &cinfo );
91 jpeg_set_quality( &cinfo, quality,
TRUE );
92 jpeg_start_compress( &cinfo,
TRUE );
94 while (cinfo.next_scanline < cinfo.image_height) {
95 row_pointer = (JSAMPROW) &src[cinfo.next_scanline*3*
width];
96 jpeg_write_scanlines( &cinfo, &row_pointer, 1 );
98 jpeg_finish_compress( &cinfo );
101 jpeg_destroy_compress( &cinfo );
void jpeg_decompress |
( |
unsigned char * |
dst, |
|
|
unsigned char * |
src, |
|
|
int |
size, |
|
|
int * |
w, |
|
|
int * |
h |
|
) |
| |
Definition at line 155 of file jpeg_memory.cpp.
References jpeg_memory_src(), TRUE, and y.
157 struct jpeg_decompress_struct cinfo;
158 struct jpeg_error_mgr jerr;
160 unsigned char *dstcur;
162 cinfo.err = jpeg_std_error( &jerr );
163 jpeg_create_decompress( &cinfo );
165 jpeg_read_header( &cinfo,
TRUE );
166 jpeg_start_decompress( &cinfo );
168 *w = cinfo.output_width;
169 *
h = cinfo.output_height;
170 line_size = cinfo.output_width*cinfo.output_components;
173 for (y = 0; y < cinfo.output_height; y++) {
174 jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &dstcur, 1 );
177 jpeg_finish_decompress( &cinfo );
178 jpeg_destroy_decompress( &cinfo );
void jpeg_decompress_from_file |
( |
unsigned char * |
dst, |
|
|
char * |
file, |
|
|
int |
size, |
|
|
int * |
w, |
|
|
int * |
h |
|
) |
| |
Definition at line 181 of file jpeg_memory.cpp.
References fclose, fopen, TRUE, and y.
183 struct jpeg_decompress_struct cinfo;
184 struct jpeg_error_mgr jerr;
186 unsigned char *dstcur;
188 if ( ( infile =
fopen(
file,
"rb" ) ) == NULL ) {
189 cerr<<
"can't open "<<
file<<endl;
192 cinfo.err = jpeg_std_error( &jerr );
193 jpeg_create_decompress( &cinfo );
194 jpeg_stdio_src( &cinfo, infile );
195 jpeg_read_header( &cinfo,
TRUE );
196 jpeg_start_decompress( &cinfo );
198 *w = cinfo.output_width;
199 *
h = cinfo.output_height;
200 line_size = cinfo.output_width*cinfo.output_components;
203 for (
size_t y = 0;
y < cinfo.output_height;
y++) {
204 jpeg_read_scanlines( &cinfo, (JSAMPARRAY) &dstcur, 1 );
207 jpeg_finish_decompress( &cinfo );
208 jpeg_destroy_decompress( &cinfo );
jpeg_memory_dest |
( |
j_compress_ptr |
cinfo, |
|
|
JOCTET * |
buffer, |
|
|
int |
bufsize |
|
) |
| |
void jpeg_memory_src |
( |
j_decompress_ptr |
cinfo, |
|
|
unsigned char * |
ptr, |
|
|
size_t |
size |
|
) |
| |
set momory-jpeg image to JPEG lib Info struct
- Parameters
-
cinfo | JPEG lib decompress infomation structure |
ptr | JPEG image |
size | JPEG image size |
Definition at line 139 of file jpeg_memory.cpp.
References fill_input_buffer(), init_source(), size, skip_input_data(), and term_source().
Referenced by jpeg_decompress().
141 struct jpeg_source_mgr *src;
142 src = cinfo->src = (
struct jpeg_source_mgr*)
143 (*cinfo->mem->alloc_small)( (j_common_ptr) cinfo,
149 src->resync_to_restart = jpeg_resync_to_restart;
151 src->next_input_byte = ptr;
152 src->bytes_in_buffer =
size;
static void skip_input_data |
( |
j_decompress_ptr |
cinfo, |
|
|
long |
num_bytes |
|
) |
| |
|
static |
Definition at line 117 of file jpeg_memory.cpp.
Referenced by jpeg_memory_src().
119 if ( (
size_t) num_bytes > cinfo->src->bytes_in_buffer ) {
120 cinfo->src->next_input_byte = NULL;
121 cinfo->src->bytes_in_buffer = 0;
123 cinfo->src->next_input_byte += (size_t) num_bytes;
124 cinfo->src->bytes_in_buffer -= (size_t) num_bytes;
static void term_source |
( |
j_decompress_ptr |
cinfo) | |
|
|
static |