Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "encode.h"
Private typedef
cinfo
jerr
jpeg_encode(FIL *, FIL *, uint32_t, uint32_t, uint32_t, uint8_t *)
Files
loading...
SourceVuSTM32 Libraries and SamplesLibJPEG_EncodingSrc/encode.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file LibJPEG/LibJPEG_Encoding/Src/encode.c * @author MCD Application Team * @brief This file contain the compress method. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "encode.h" Includes /* Private typedef -----------------------------------------------------------*/ /* This struct contains the JPEG compression parameters */ static struct jpeg_compress_struct cinfo; /* This struct represents a JPEG error handler */ static struct jpeg_error_mgr jerr; Private typedef /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ extern RGB_typedef *RGB_matrix; /** * @brief Jpeg Encode * @param file: pointer to the bmp file * @param file1: pointer to the jpg file * @param width: image width * @param height: image height * @param image_quality: image quality * @param buff: pointer to the image line * @retval None *//* ... */ void jpeg_encode(JFILE *file, JFILE *file1, uint32_t width, uint32_t height, uint32_t image_quality, uint8_t * buff) { /* Encode BMP Image to JPEG */ JSAMPROW row_pointer; /* Pointer to a single row */ uint32_t bytesread; uint32_t index; /* Step 1: allocate and initialize JPEG compression object */ /* Set up the error handler */ cinfo.err = jpeg_std_error(&jerr); /* Initialize the JPEG compression object */ jpeg_create_compress(&cinfo); /* Step 2: specify data destination */ jpeg_stdio_dest(&cinfo, file1); /* Step 3: set parameters for compression */ cinfo.image_width = width; cinfo.image_height = height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; /* Set default compression parameters */ jpeg_set_defaults(&cinfo); cinfo.dct_method = JDCT_FLOAT; jpeg_set_quality(&cinfo, image_quality, TRUE); /* Step 4: start compressor */ jpeg_start_compress(&cinfo, TRUE); /* Get bitmap data address offset */ 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) { /* In this application, the input file is a BMP, which first encodes the bottom of the picture */ /* JPEG encodes the highest part of the picture first. We need to read the lines upside down */ /* Move the read pointer to 'last line of the picture - next_scanline' */ 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) { ... } /* Step 5: finish compression */ jpeg_finish_compress(&cinfo); /* Step 6: release JPEG compression object */ jpeg_destroy_compress(&cinfo); }{ ... }
Details