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_;
struct jpeg_error_mgr jerr_;
Private typedef
/* ... */
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_);
}{ ... }