diff --git a/ST7789/bmp.c b/ST7789/bmp.c new file mode 100644 index 0000000..a39def5 --- /dev/null +++ b/ST7789/bmp.c @@ -0,0 +1,568 @@ +// + +// +#include "bmp.h" +#include "st7789.h" +unsigned char work[4096] = {0}; +unsigned int count = 0; +BMP_8 bmp8[][IMG_WIDTH]; + + +void bmp24_to_rgb565(BMP_24 bmp24[][IMG_WIDTH],RGB565 rgb565[][IMG_WIDTH],uint16_t img[][IMG_WIDTH]) +{ + for (int i = 0; i < IMG_HEIGHT; i++) //BMP24->RGB565 + { + for (int j = 0; j < IMG_WIDTH; j++) + { + rgb565[i][j].r_bit =bmp24[i][j].r_val>>3; + rgb565[i][j].g_bit = bmp24[i][j].g_val>>2; + rgb565[i][j].b_bit = bmp24[i][j].b_val>>3; + } + } + for (int i = 0; i < IMG_HEIGHT; i++) + { + for (int j = 0; j < IMG_WIDTH; j++) + { + img[i][j] =(rgb565[i][j].r_bit << 11 |rgb565[i][j].g_bit << 5 |rgb565[i][j].b_bit); + img[i][j] =( img[i][j] >> 8) | ((img[i][j] & 0xFF) << 8); + } + } +} + +void bmp8_to_bmp1(BMP_8 bmp8[][IMG_WIDTH],uint8_t img[][IMG_WIDTH/8],uint8_t thre) +{ + uint8_t after_thre[IMG_HEIGHT*IMG_WIDTH]; + for(int i=0;i=thre; + } + } + for(int i=0;ihigh_threshold) + high_threshold=temp_mat[i]; + } + *max_temp=high_threshold; + *min_temp=low_threshold; + //温度异常退出重新获取 + if(high_threshold>300||low_threshold<-40) + return 1; + uint8_t max_gray=0; + for(int i=0;imax_gray) + { + max_gray=bmp8[i].gray_val; + max_index=i; + } + } + max_index/IMG_INITIAL_WIDTH*IMG_HEIGHT+5; + + int max_y=max_index/IMG_INITIAL_WIDTH*IMG_HEIGHT/IMG_INITIAL_HEIGHT+(240-IMG_HEIGHT)/2+IMG_HEIGHT/IMG_INITIAL_HEIGHT/2; + int max_x=(max_index%IMG_INITIAL_WIDTH)*IMG_WIDTH/IMG_INITIAL_WIDTH+(320-IMG_WIDTH)/2+IMG_WIDTH/IMG_INITIAL_WIDTH/2; + BSP_LCD_FillRect(max_x-6,max_y-1,12,2,BLACK); + BSP_LCD_FillRect(max_x-1,max_y-6,2,12,BLACK); + //ST7789_DrawFilledRectangle(max_x-6,max_y-1,12,2,BLACK); + //ST7789_DrawFilledRectangle(max_x-1,max_y-6,2,12,BLACK); + return 0; +} + +//邻近插值法 +void Resize_draw(BMP_8 bmp8[],uint8_t method) +{ + BMP_24 input_bmp24[IMG_INITIAL_HEIGHT][IMG_INITIAL_WIDTH]; + gray_to_rgb(bmp8,input_bmp24,method); + RGB565 TEMP_RGB565; + //SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); + //ST7789_SetAddressWindow((320-IMG_WIDTH)/2, (240-IMG_HEIGHT)/2, IMG_WIDTH+(320-IMG_WIDTH)/2-1, IMG_HEIGHT+(240-IMG_HEIGHT)/2-1); + SetDisplayWindow((320-IMG_WIDTH)/2, (240-IMG_HEIGHT)/2, IMG_WIDTH+(320-IMG_WIDTH)/2-1, IMG_HEIGHT+(240-IMG_HEIGHT)/2-1); + ST7789_Select(); + ST7789_DC_Set(); + uint16_t data[IMG_WIDTH*IMG_HEIGHT/4]; + for(int i=0;i>3; + TEMP_RGB565.g_bit =input_bmp24[i][j].g_val>>2; + TEMP_RGB565.b_bit =input_bmp24[i][j].b_val>>3; + uint16_t color; + color =(TEMP_RGB565.r_bit << 11 |TEMP_RGB565.g_bit << 5 |TEMP_RGB565.b_bit); + color =( color >> 8) | ((color & 0xFF) << 8); + if(i%6==0) + { + for(int a=0;a w - 2 ? w - 2 : Lx < 0 ? 0 : Lx; +// Rx = Rx > w - 1 ? w - 1 : Rx < 0 ? 0 : Rx; +// Ly = Ly > h - 2 ? h - 2 : Ly < 0 ? 0 : Ly; +// Ry = Ry > h - 1 ? h - 1 : Ry < 0 ? 0 : Ry; +// float u = (float)Rx - fx; +// float v = (float)Ry - fy; +// float r1=u*(float)bmp8[Ly][Lx].gray_val+(1-u)*(float)bmp8[Ly][Rx].gray_val; +// float r2=u*(float)bmp8[Ry][Lx].gray_val+(1-u)*(float)bmp8[Ry][Rx].gray_val; +// temp.gray_val=(uint8_t)(v * r1 + (1 - v) * r2); + bmp8_to_color(method,temp.gray_val,&temp_24); + TEMP_RGB565.r_bit =temp_24.r_val>>3; + TEMP_RGB565.g_bit =temp_24.g_val>>2; + TEMP_RGB565.b_bit =temp_24.b_val>>3; + color[0] =(TEMP_RGB565.r_bit << 11 |TEMP_RGB565.g_bit << 5 |TEMP_RGB565.b_bit); + color[0] =( color[0] >> 8) | ((color[0] & 0xFF) << 8); + if(indexr_val=abs(0-gray_val); + bmp24->g_val=abs(127-gray_val); + bmp24->b_val=abs(255-gray_val); + break; + + case GCM_Pseudo2: + if( (gray_val>=0) && (gray_val<=63) ) + { + bmp24->r_val=0; + bmp24->g_val=0; + bmp24->b_val=(gray_val*255/64); + } + else if( (gray_val>=64) && (gray_val<=127) ) + { + bmp24->r_val=0; + bmp24->g_val=((gray_val-64)*255/64); + bmp24->b_val=((127-gray_val)*255/64); + } + else if( (gray_val>=128) && (gray_val<=191) ) + { + bmp24->r_val=((gray_val-128)*255/64); + bmp24->g_val=255; + bmp24->b_val=0; + } + else if( (gray_val>=192) && (gray_val<=255) ) + { + bmp24->r_val=255; + bmp24->g_val=((255-gray_val)*255/64); + bmp24->b_val=0; + } + break; + + case GCM_Metal1: + if( (gray_val>=0) && (gray_val<=63) ) + { + bmp24->r_val=0; + bmp24->g_val=0; + bmp24->b_val=(gray_val*255/64); + } + else if( (gray_val>=64) && (gray_val<=95) ) + { + bmp24->r_val=((gray_val-63)*127/32); + bmp24->g_val=((gray_val-63)*127/32); + bmp24->b_val=255; + } + else if( (gray_val>=96) && (gray_val<=127) ) + { + bmp24->r_val=((gray_val-95)*127/32)+128; + bmp24->g_val=((gray_val-95)*127/32)+128; + bmp24->b_val=((127-gray_val)*255/32); + } + else if( (gray_val>=128) && (gray_val<=191) ) + { + bmp24->r_val=255; + bmp24->g_val=255; + bmp24->b_val=0; + } + else if( (gray_val>=192) && (gray_val<=255) ) + { + bmp24->r_val=255; + bmp24->g_val=255; + bmp24->b_val=((gray_val-192)*255/64); + } + break; + + case GCM_Metal2: + bmp24->r_val=0; bmp24->b_val=0; bmp24->b_val=0; + if( (gray_val>=0) && (gray_val<=16) ) + { + bmp24->r_val=0; + } + else if( (gray_val>=17) && (gray_val<=140) ) + { + bmp24->r_val=((gray_val-16)*255/(140-16)); + } + else if( (gray_val>=141) && (gray_val<=255) ) + { + bmp24->r_val=255; + } + + if( (gray_val>=0) && (gray_val<=101) ) + { + bmp24->g_val=0; + } + else if( (gray_val>=102) && (gray_val<=218) ) + { + bmp24->g_val=((gray_val-101)*255/(218-101)); + } + else if( (gray_val>=219) && (gray_val<=255) ) + { + bmp24->g_val=255; + } + + if( (gray_val>=0) && (gray_val<=91) ) + { + bmp24->b_val=28+((gray_val-0)*100/(91-0)); + } + else if( (gray_val>=92) && (gray_val<=120) ) + { + bmp24->b_val=((120-gray_val)*128/(120-91)); + } + else if( (gray_val>=129) && (gray_val<=214) ) + { + bmp24->b_val=0; + } + else if( (gray_val>=215) && (gray_val<=255) ) + { + bmp24->b_val=((gray_val-214)*255/(255-214)); + } + break; + + case GCM_Rainbow1: + if( (gray_val>=0) && (gray_val<=31) ) + { + bmp24->r_val=0; + bmp24->g_val=0; + bmp24->b_val=(gray_val*255/32); + } + else if( (gray_val>=32) && (gray_val<=63) ) + { + bmp24->r_val=0; + bmp24->g_val=((gray_val-32)*255/32); + bmp24->b_val=255; + } + else if( (gray_val>=64) && (gray_val<=95) ) + { + bmp24->r_val=0; + bmp24->g_val=255; + bmp24->b_val=((95-gray_val)*255/32); + } + else if( (gray_val>=96) && (gray_val<=127) ) + { + bmp24->r_val=((gray_val-96)*255/32); + bmp24->g_val=255; + bmp24->b_val=0; + } + else if( (gray_val>=128) && (gray_val<=191) ) + { + bmp24->r_val=255; + bmp24->g_val=((191-gray_val)*255/64); + bmp24->b_val=0; + } + else if( (gray_val>=192) && (gray_val<=255) ) + { + bmp24->r_val=255; + bmp24->g_val=((gray_val-192)*255/64);//0 + bmp24->b_val=((gray_val-192)*255/64); + } + break; + + case GCM_Rainbow2: + if( (gray_val>=0) && (gray_val<=63) ) + { + bmp24->r_val=0; + bmp24->g_val=((gray_val-0)*255/64); + bmp24->b_val=255; + } + else if( (gray_val>=64) && (gray_val<=95) ) + { + bmp24->r_val=0; + bmp24->g_val=255; + bmp24->b_val=((95-gray_val)*255/32); + } + else if( (gray_val>=96) && (gray_val<=127) ) + { + bmp24->r_val=((gray_val-96)*255/32); + bmp24->g_val=255; + bmp24->b_val=0; + } + else if( (gray_val>=128) && (gray_val<=191) ) + { + bmp24->r_val=255; + bmp24->g_val=((191-gray_val)*255/64); + bmp24->b_val=0; + } + else if( (gray_val>=192) && (gray_val<=255) ) + { + bmp24->r_val=255; + bmp24->g_val=((gray_val-192)*255/64); + bmp24->b_val=((gray_val-192)*255/64); + } + break; + + case GCM_Rainbow3: + if( (gray_val>=0) && (gray_val<=51) ) + { + bmp24->r_val=0; + bmp24->g_val=gray_val*5; + bmp24->b_val=255; + } + else if( (gray_val>=52) && (gray_val<=102) ) + { + bmp24->r_val=0; + bmp24->g_val=255; + bmp24->b_val=255-(gray_val-51)*5; + } + else if( (gray_val>=103) && (gray_val<=153) ) + { + bmp24->r_val=(gray_val-102)*5; + bmp24->g_val=255; + bmp24->b_val=0; + } + else if( (gray_val>=154) && (gray_val<=204) ) + { + bmp24->r_val=255; + bmp24->g_val=(255-128*(gray_val-153)/51); + bmp24->b_val=0; + } + else if( (gray_val>=205) && (gray_val<=255) ) + { + bmp24->r_val=255; + bmp24->g_val=(127-127*(gray_val-204)/51); + bmp24->b_val=0; + } + break; + + case GCM_Zhou: + if( (gray_val>=0) && (gray_val<=63) ) + { + bmp24->r_val=0; + bmp24->g_val=((64-gray_val)*255/64); + bmp24->b_val=255; + } + else if( (gray_val>=64) && (gray_val<=127) ) + { + bmp24->r_val=0; + bmp24->g_val=((gray_val-64)*255/64); + bmp24->b_val=((127-gray_val)*255/64); + } + else if( (gray_val>=128) && (gray_val<=191) ) + { + bmp24->r_val=((gray_val-128)*255/64); + bmp24->g_val=255; + bmp24->b_val=0; + } + else if( (gray_val>=192) && (gray_val<=255) ) + { + bmp24->r_val=255; + bmp24->g_val=((255-gray_val)*255/64); + bmp24->b_val=0; + } + break; + + case GCM_Ning: + if ((gray_val>=0) && (gray_val<=63)) + { + bmp24->r_val=0; + bmp24->g_val=254-4*gray_val; + bmp24->b_val=255; + } + else if ((gray_val>=64) && (gray_val<=127)) + { + bmp24->r_val=0; + bmp24->g_val=4*gray_val-254; + bmp24->b_val=510-4*gray_val; + } + else if ((gray_val>=128) && (gray_val<=191)) + { + bmp24->r_val=4*gray_val-510; + bmp24->g_val=255; + bmp24->b_val=0; + } + else if ((gray_val>=192) && (gray_val<=255)) + { + bmp24->r_val=255; + bmp24->g_val=1022-4*gray_val; + bmp24->b_val=0; + } + break; + + case GCM_Gray: + bmp24->r_val=gray_val; + bmp24->g_val=gray_val; + bmp24->b_val=gray_val; + break; + + default: + break; + } +} + +void draw_spectrum(uint8_t method) +{ + uint16_t color; + for(int i=255;i>0;i-=2) + { + BMP_24 temp24; + RGB565 temp565; + bmp8_to_color(method,i,&temp24); + temp565.r_bit =temp24.r_val>>3; + temp565.g_bit =temp24.g_val>>2; + temp565.b_bit =temp24.b_val>>3; + color =(temp565.r_bit << 11 |temp565.g_bit << 5 |temp565.b_bit); + ST7789_DrawFilledRectangle(310,228-((int)((i/2)*1.6875))-2,8,2,color); + + } +} diff --git a/ST7789/bmp.h b/ST7789/bmp.h new file mode 100644 index 0000000..136acd2 --- /dev/null +++ b/ST7789/bmp.h @@ -0,0 +1,65 @@ + +#ifndef SD_TEST_BMP_H +#define SD_TEST_BMP_H +#include +#include +#include +#include "st7789.h" +#include "math.h" +#include "stm32_hx8347d_lcd.h" +#include "arm_math.h" + +#define abs(s) (s)>0?(s):-1*(s) +//#define IMG_WIDTH 288 +#define IMG_WIDTH 240 +#define IMG_HEIGHT 216 +#define IMG_INITIAL_WIDTH 32 +#define IMG_INITIAL_HEIGHT 24 +#define savefile 0x01 +#define notsavefile 0x00 +#define GCM_Pseudo1 0x01 +#define GCM_Pseudo2 0x02 +#define GCM_Rainbow1 0x03 +#define GCM_Rainbow2 0x04 +#define GCM_Ning 0x05 +#define GCM_Rainbow3 0x06 +#define GCM_Zhou 0x07 +#define GCM_Gray 0x08 +#define GCM_Metal1 0x09 +#define GCM_Metal2 0x0A + +typedef struct RGBQUAD +{ + uint8_t rgbBlue; //指定蓝色强度 + uint8_t rgbGreen; //指定绿色强度 + uint8_t rgbRed; //指定红色强度 + uint8_t rgbReserved; //保留,设置为0 +} RGBQUAD; +typedef struct BMP_8 +{ + uint8_t gray_val; +}BMP_8; +typedef struct BMP_24 +{ + uint8_t r_val; + uint8_t g_val; + uint8_t b_val; + +}BMP_24; +typedef struct RGB565 +{ + uint8_t r_bit; + uint8_t g_bit; + uint8_t b_bit; +}RGB565; + +void bmp24_to_rgb565(BMP_24 bmp24[][IMG_WIDTH],RGB565 rgb565[][IMG_WIDTH],uint16_t img[][IMG_WIDTH]); +void bmp8_to_bmp1(BMP_8 bmp8[][IMG_WIDTH],uint8_t img[][IMG_WIDTH/8],uint8_t thre); +uint8_t temp_to_bmp8(BMP_8 bmp8[],const float temp_mat[],int size,float *max_temp,float *min_temp,uint8_t revese); +void Resize_draw(BMP_8 bmp8[],uint8_t method); +uint8_t Besize_draw(BMP_8 input_bmp8[],uint8_t method,uint8_t ifsavefile); +void gray_to_rgb(BMP_8 bmp8[],BMP_24 bmp24[][IMG_INITIAL_WIDTH],uint8_t method); +void bmp8_to_color(uint8_t method,uint8_t gray_val,BMP_24*bmp24); +void draw_spectrum(uint8_t method); + +#endif //SD_TEST_BMP_H diff --git a/mlx90640/mlx90640_lcd_display.c b/mlx90640/mlx90640_lcd_display.c index 22a3c89..05bd86d 100644 --- a/mlx90640/mlx90640_lcd_display.c +++ b/mlx90640/mlx90640_lcd_display.c @@ -39,7 +39,11 @@ int x, y, i, j; // array for the 32 x 24 measured tempValues static float tempValues[32*24]; volatile uint8_t zoneMask[32*24]={0x0}, edgeMask[32*24]={0x0}; +<<<<<<< HEAD void mlx90640_setCalibrationWaterTemp(void); +======= +void setCalibrationWaterTemp(void); +>>>>>>> 5e99684106096ccf79c571db54b302efc6a01d1a void blackOutFilter(void); static uint16_t TempToColor(float val); static void setTempScale(void); @@ -90,10 +94,16 @@ static uint16_t TempToColor(float val) // use the displays color mapping function to get 5-6-5 color palette (R=5 bits, G=6 bits, B-5 bits) return BSP_LCD_GetColor565(red, green, blue); } +<<<<<<< HEAD void mlx90640_setCalibrationWaterTemp(void) { char tempbuf[128]=""; APP_LOG(TS_OFF,VLEVEL_L,"Start Calibration of Water, Put water in the center of FOV \r\n"); +======= +void setCalibrationWaterTemp(void) +{ + char tempbuf[128]=""; +>>>>>>> 5e99684106096ccf79c571db54b302efc6a01d1a readTempValues(); setTempScale(); calibrationWaterTemp = centerTemp; @@ -360,7 +370,11 @@ void mlx90640_display_process(void) LCD_BL_OFF(); // BSP_LCD_DisplayOff(); } +<<<<<<< HEAD APP_LOG(TS_OFF, VLEVEL_L, "Water Spill Spot Detected Count = %2d Level = %d of 600 \r\n", waterSpillSpotCount,waterSpillLevel); +======= + +>>>>>>> 5e99684106096ccf79c571db54b302efc6a01d1a if ((waterSpillSpotCount != lastWaterSpillSpotCount)&&(waterSpillSpotCount != 0)) { APP_LOG(TS_OFF, VLEVEL_L, "Water Spill Spot Detected Count = %2d Level = %d of 600 \r\n", waterSpillSpotCount,waterSpillLevel); lastWaterSpillSpotCount = waterSpillSpotCount;