-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbmp_enc.c
More file actions
81 lines (70 loc) · 2.19 KB
/
bmp_enc.c
File metadata and controls
81 lines (70 loc) · 2.19 KB
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
#include "bmp_enc.h"
#include "jpg_dec.h"
#include "png_dec.h"
#include "user_ram.h"
#include "user_display.h"
#include "ff.h"
#include <string.h>
FIL pic_file;
void encodeToBMP(uint8_t *bmp_header, uint32_t xsize, uint32_t ysize)
{
uint8_t header[54] =
{
0x42, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
uint32_t file_size = (uint32_t)xsize * (uint32_t)ysize * 3 + 54;
header[2] = (unsigned char)(file_size &0x000000ff);
header[3] = (file_size >> 8) & 0x000000ff;
header[4] = (file_size >> 16) & 0x000000ff;
header[5] = (file_size >> 24) & 0x000000ff;
uint32_t width = xsize;
header[18] = width & 0x000000ff;
header[19] = (width >> 8) & 0x000000ff;
header[20] = (width >> 16) & 0x000000ff;
header[21] = (width >> 24) & 0x000000ff;
uint32_t height = ysize;
header[22] = height & 0x000000ff;
header[23] = (height >> 8) & 0x000000ff;
header[24] = (height >> 16) & 0x000000ff;
header[25] = (height >> 24) & 0x000000ff;
memmove(bmp_header, header, sizeof(header));
}
/*
* param idx: item id
*/
uint8_t writeToBMP(const uint8_t *data, uint32_t data_len, uint32_t item_id)
{
uint8_t filename_buf[100];
sprintf((char *)filename_buf, "0:/out%04d.bmp", item_id);
uint8_t res = f_open(&pic_file, (char const *)filename_buf, FA_WRITE|FA_CREATE_ALWAYS);
if(res)
{
printf("unable creat file!\n");
return 0;
}
else
{
//bmp
f_write(&pic_file, data, data_len, NULL);
}
printf("write file succ, file name = %s, len = %d\n", filename_buf, pic_file.fsize);
f_close(&pic_file);
}
void DisplayBMP(uint8_t pic_type)
{
if(pic_type == 1) //png
{
dec_png_buf(source, length, sdram_buffer_2, sizeof(sdram_buffer_2));
}
else //jpg
{
dec_jpg_buf(source, length, sdram_buffer_2);
}
LCD_DisplayBmp(50, 50, sdram_buffer_2);
printf("pic type = %s\n", pic_type==1 ? "PNG":"JPG");
}