1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
27
28
29
30
31
32
33
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
77
78
79
80
81
82
83
84
/* ... */
#include "decode.h"
Includes
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
Private typedef
/* ... */
void jpeg_decode(JFILE *file, uint32_t width, uint8_t * buff, uint8_t (*callback)(uint8_t*, uint32_t))
{
JSAMPROW buffer[2] = {0};
uint32_t row_stride = 0;
buffer[0] = buff;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_stdio_src (&cinfo, file);
jpeg_read_header(&cinfo, TRUE);
cinfo.dct_method = JDCT_FLOAT;
jpeg_start_decompress(&cinfo);
row_stride = width * 3;
while (cinfo.output_scanline < cinfo.output_height)
{
(void) jpeg_read_scanlines(&cinfo, buffer, 1);
if (callback(buffer[0], row_stride) != 0)
{
break;
}if (callback(buffer[0], row_stride) != 0) { ... }
}while (cinfo.output_scanline < cinfo.output_height) { ... }
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
}{ ... }