-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathjpegtest.c
143 lines (120 loc) · 3.53 KB
/
jpegtest.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <wiringPi.h>
#include "tft_lib.h"
#include "tjpgd2/tjpgd.h"
#include "tjpgd2/decode_jpeg.h"
#include "driver/ili9341.h"
#define DRIVER_NAME "ILI9341"
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
#define OFFSET_X 0
#define OFFSET_Y 0
#define INIT_FUNCTION(a, b, c, d, e) ili9341_lcdInit(a, b, c, d, e)
#define _DEBUG_ 0
time_t elapsedTime(struct timeval startTime, struct timeval endTime) {
time_t diffsec = difftime(endTime.tv_sec, startTime.tv_sec);
suseconds_t diffsub = endTime.tv_usec - startTime.tv_usec;
//printf("diffsec=%ld diffsub=%ld\n",diffsec, diffsub);
if(diffsub < 0) {
diffsec--;
diffsub = (endTime.tv_usec+1000000) - startTime.tv_usec;
}
uint16_t diffmsec = diffsub / 1000;
time_t diff = (diffsec * 1000) + diffmsec;
return diff;
}
time_t JPEGTest(TFT_t * dev, char * file, int width, int height) {
struct timeval startTime, endTime;
gettimeofday(&startTime, NULL);
lcdFillScreen(dev, BLACK);
int _width = width;
if (width > 240) _width = 240;
int _height = height;
if (height > 320) _height = 320;
pixel_s **pixels;
uint16_t imageWidth;
uint16_t imageHeight;
uint16_t err = decode_image(&pixels, file, width, height, &imageWidth, &imageHeight);
if (err == ESP_OK) {
printf("width=%d height=%d\n", width, height);
printf("imageWidth=%d imageHeight=%d\n", imageWidth, imageHeight);
uint16_t jpegWidth = width;
uint16_t offsetX = 0;
if (width > imageWidth) {
jpegWidth = imageWidth;
offsetX = (width - imageWidth) / 2;
}
printf("jpegWidth=%d offsetX=%d\n", jpegWidth, offsetX);
uint16_t jpegHeight = height;
uint16_t offsetY = 0;
if (height > imageHeight) {
jpegHeight = imageHeight;
offsetY = (height - imageHeight) / 2;
}
printf("jpegHeight=%d offsetY=%d\n", jpegHeight, offsetY);
uint16_t *colors = (uint16_t*)malloc(sizeof(uint16_t) * jpegWidth);
int ypos = (height-1) - offsetY;
for(int y = 0; y < jpegHeight; y++){
for(int x = 0;x < jpegWidth; x++){
pixel_s pixel = pixels[y][x];
uint16_t color = rgb565_conv(pixel.red, pixel.green, pixel.blue);
//lcdDrawPixel(dev, x+offsetX, y+offsetY, color);
lcdDrawPixel(dev, x+offsetX, ypos, color);
}
ypos--;
}
free(colors);
release_image(&pixels, _width, _height);
//printf("Finish\n");
} else {
printf("decode_image err=%d imageWidth=%d imageHeight=%d\n", err, imageWidth, imageHeight);
}
gettimeofday(&endTime, NULL);
time_t diff = elapsedTime(startTime, endTime);
printf("%s elapsed time[ms]=%ld\n",__func__, diff);
return diff;
}
int main(int argc, char **argv){
if(wiringPiSetup() == -1) {
printf("wiringPiSetup Fail\n");
return 1;
}
int i;
char base[128];
strcpy(base, argv[0]);
for(i=strlen(base);i>0;i--) {
if (base[i-1] == '/') {
base[i] = 0;
break;
}
}
if(_DEBUG_)printf("base=%s\n",base);
char ppath[128];
strcpy(ppath,base);
strcat(ppath,"pin.conf");
if(_DEBUG_)printf("ppath=%s\n",ppath);
struct stat buffer;
if (stat(ppath, &buffer) != 0) {
printf("pin.conf [%s] not found\n",ppath);
return 1;
}
TFT_t dev;
lcdInterface(&dev, ppath);
lcdReset(&dev);
INIT_FUNCTION(&dev, SCREEN_WIDTH, SCREEN_HEIGHT, OFFSET_X, OFFSET_Y);
char file[64];
//strcpy(file, "./images/RaspberryPi_logo.jpeg");
//strcpy(file, "./images/Ubuntu_log.jpeg");
strcpy(file, "./images/dailyImage.jpeg");
JPEGTest(&dev, file, SCREEN_WIDTH, SCREEN_HEIGHT);
sleep(5);
//lcdFadeout(&dev, DIRECTION90, BLACK);
}