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
34
35
36
37
38
39
40
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
95
96
97
98
99
100
101
102
/* ... */
#include "encode.h"
Includes
static struct jpeg_compress_struct cinfo;
static struct jpeg_error_mgr jerr;
Private typedef
extern RGB_typedef *RGB_matrix;
/* ... */
void jpeg_encode(JFILE *file, JFILE *file1, uint32_t width, uint32_t height, uint32_t image_quality, uint8_t * buff)
{
JSAMPROW row_pointer;
uint32_t bytesread;
uint32_t index;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, file1);
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
cinfo.dct_method = JDCT_FLOAT;
jpeg_set_quality(&cinfo, image_quality, TRUE);
jpeg_start_compress(&cinfo, TRUE);
f_read(file, buff, 14, (UINT*)&bytesread);
index = *(__IO uint16_t *) (buff + 10);
index |= (*(__IO uint16_t *) (buff + 12)) << 16;
while (cinfo.next_scanline < cinfo.image_height)
{
f_lseek(file, ((cinfo.image_height-1-cinfo.next_scanline)*width*3)+index);
if(f_read(file, buff, width*3, (UINT*)&bytesread) == FR_OK)
{
row_pointer = (JSAMPROW)buff;
jpeg_write_scanlines(&cinfo, &row_pointer, 1);
}if (f_read(file, buff, width*3, (UINT*)&bytesread) == FR_OK) { ... }
}while (cinfo.next_scanline < cinfo.image_height) { ... }
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
}{ ... }