wantedboy
03-10-2014, 22:28
با عرض سلام خدمت دوستان
این کتابخانه در مد 8 بیتی به خوبی کار میکنه و عکس bmp 24 بیتی از روی مموری نشون میده.
مشکل اینجاست وقتی مد lcd روی 16 بیتی تنظیم میشه عکس های نمایش داده شده رو به رنگ زرد یا آبی میرن.!!!
میدونم باید یه تغییراتی داخلش بدیم مشکل از جای دیگه ای نیست.
/************************************************** *********************************************** DESCRIPTION
* ===========
* Reading BMP from SD card
* using : Petit FatFs - FAT file system module R0.01a (C)ChaN, 2009
*
* Display on TFT QVGA circuitidea.com BL-TFT240320PLUS
* support only bmp 24 bit
* support BMP padding data. Option for complex BMP (image width devide by 4 giving 0).
* for small size and fast display.
*
* BMP padding
* -----------
* in BMP total horizontal bytes must devide by 4. remain is padding 0-3 byte.
* For fast way to display picture. do this.
* 1. create picture width can device by 4 give 0
* 2. using FILL IN AREA mode of QVGA.
*
* HISTORY
* -------
* 01/10/2009 Using stream mode for faster and smooter.
* **NOTE**
* Becare full to set stream parameter before use function. bmpShow has no link to FATFS (FATFS not public variable).
*
* fs.flag |= FA_STREAM; // Set stream mode
* bmpShow((unsigned int)SCREEN_HOR_SIZE/2 - w/2, (unsigned int)SCREEN_VER_SIZE/2 - h/2);
* fs.flag &= ~FA_STREAM; // Clear stream mode
*
************************************************** **********************************************/
#include "ff.h"
#include "TFT/tftlcd_functions.h"
#include "stm32f10x.h"
//-------------------------FAT------------------------------------
FRESULT ress;
FATFS drive;
FIL fil;
typedef struct BMIH { //declares BitMap Info Header structure
unsigned long biSize; //Length of bitmap information header (40 bytes for Windows V3 bitmaps)
unsigned long biWidth; //Width (pixels)
unsigned long biHeight; //Height (pixels)
unsigned short biPlanes; //Color planes, always 1
unsigned short biBitCount; //Color bits per pixel (1, 4, 8, 16, 24 and 32)
unsigned long biCompression; //Compression method, we only read uncompressed (type 0)
unsigned long biSizeImage; //Image data length
unsigned long biXPelsPerMeter; //Horizontal resolution (pixels per meter)
unsigned long biYPelsPerMeter; //Vertical resolution (pixel per meter)
unsigned long biClrUsed; //Number of colors, ignored.
unsigned long biClrImportant; //Number of important colors, ignored.
}BMP_INFO;
typedef struct BMFH { //declares BitMap File Header structure
unsigned short bfType; //Always 0x42 0x4D (hex for BM <-- indicating a bitmap)
unsigned long bfSize; //File size (bytes)
unsigned short bfReserved1; //Reserved, ignored
unsigned short bfReserved2; //Reserved, ignored
unsigned long bfOffBits; //Location in file of the first bitmap data
}BMP_HEADER;
unsigned long bmpWidth; //Width (pixels)
unsigned long bmpHeight; //Height (pixels)
FRESULT bmpFile(const char* fname)
{
BMP_HEADER BMPHeader;
BMP_INFO BMPInfo;
//FRESULT res;
int br;
if (f_open(&fil,fname,FA_READ) != FR_OK) return 1; // File Open count
if (f_read(&fil,&BMPHeader, sizeof(BMPHeader), &br) != FR_OK) return 2; // read bmp header
if (BMPHeader.bfType != 0x4d42 ) return 3; // type is 'BM'
if (f_read(&fil,&BMPInfo, sizeof(BMPInfo), &br) != FR_OK) return 4; // read bmp info
if (BMPInfo.biSize != 40) return 5; //unknown header format/length
if (BMPInfo.biPlanes != 1) return 6; //this should be 1
if (BMPInfo.biWidth > 240) return 7; //image over size
if (BMPInfo.biHeight > 320) return 8; //image over size
if (BMPInfo.biCompression != 0) return 9; //0=no compression
bmpWidth = BMPInfo.biWidth;
bmpHeight = BMPInfo.biHeight;
if (f_lseek(&fil,BMPHeader.bfOffBits)!= FR_OK) return 10; // move to start of bmp data
return FR_OK;
}
void RGB(unsigned char B,unsigned char G,unsigned char R)
{
unsigned short dat = 0x0000;
B = B >> 3;
G = G >> 2;
R = R >> 3;
// tftlcd_write_wdr2((R << 3) | (G >> 3), (G << 5) | B );
dat =((R << 3) | (G >> 3))<<8;
dat =(G << 5) | B;
tftlcd_write_wdr(dat);
}
unsigned char bmpShow(unsigned int sx, unsigned int sy) // support BMP 24 bit True color only
{
//unsigned short color;
unsigned int x,y;
unsigned int i,j;
unsigned int ex,ey;
unsigned char res,buffer[256];
unsigned int br;
ex = sx + bmpWidth-1;
ey = sy + bmpHeight-1;
if (sx < TFT_margin_xl)sx = TFT_margin_xl;
if (ex > TFT_margin_xr)ex = TFT_margin_xr;
if (sy < TFT_margin_yu)sy = TFT_margin_yu;
if (ey > TFT_margin_yl)ey = TFT_margin_yl;
tftlcd_write_index_register(TS_INS_ENTRY_MOD);
tftlcd_write_wdr(0x10);
tftlcd_write_index_register(TS_INS_START_ADX);
tftlcd_write_wdr(sx);
tftlcd_write_index_register(TS_INS_END_ADX);
tftlcd_write_wdr(ex);
tftlcd_write_index_register(TS_INS_GRAM_ADX);
tftlcd_write_wdr(sx);
x = (ex - sx + 1);
#ifndef TFT_ORN_PORTRAIT
sy = TS_SIZE_Y - 1 - sy;
ey = TS_SIZE_Y - 1 - ey;
tftlcd_write_index_register(TS_INS_START_ADY);
tftlcd_write_wdr(ey);
tftlcd_write_index_register(TS_INS_END_ADY);
tftlcd_write_wdr(sy);
tftlcd_write_index_register(TS_INS_GRAM_ADY);
tftlcd_write_wdr(sy);
y = sy - ey + 1;
#else
tftlcd_write_index_register(TS_INS_START_ADY);
tftlcd_write_wdr(sy);
tftlcd_write_index_register(TS_INS_END_ADY);
tftlcd_write_wdr(ey);
tftlcd_write_index_register(TS_INS_GRAM_ADY);
tftlcd_write_wdr(sy);
y = ey - sy;
#endif
tftlcd_write_index_register(TS_INS_RW_GRAM);
for (;;)
{
res = f_read(&fil,buffer,x,&br);
if(res || !br)break;
for (i=0; i<x; i+=3)
{
RGB(buffer[i+2],buffer[i+1],buffer[i]);
}
}
tftlcd_write_index_register(TS_INS_ENTRY_MOD);
tftlcd_write_wdr(TS_VAL_ENTRY_MOD);
return res;
}
به احتمال خیلی زیاد از قسمت void RGB باشه.
مثلا اون تعداد شیفت ها که داده.
ممنون میشم کمک کنید.
این کتابخانه در مد 8 بیتی به خوبی کار میکنه و عکس bmp 24 بیتی از روی مموری نشون میده.
مشکل اینجاست وقتی مد lcd روی 16 بیتی تنظیم میشه عکس های نمایش داده شده رو به رنگ زرد یا آبی میرن.!!!
میدونم باید یه تغییراتی داخلش بدیم مشکل از جای دیگه ای نیست.
/************************************************** *********************************************** DESCRIPTION
* ===========
* Reading BMP from SD card
* using : Petit FatFs - FAT file system module R0.01a (C)ChaN, 2009
*
* Display on TFT QVGA circuitidea.com BL-TFT240320PLUS
* support only bmp 24 bit
* support BMP padding data. Option for complex BMP (image width devide by 4 giving 0).
* for small size and fast display.
*
* BMP padding
* -----------
* in BMP total horizontal bytes must devide by 4. remain is padding 0-3 byte.
* For fast way to display picture. do this.
* 1. create picture width can device by 4 give 0
* 2. using FILL IN AREA mode of QVGA.
*
* HISTORY
* -------
* 01/10/2009 Using stream mode for faster and smooter.
* **NOTE**
* Becare full to set stream parameter before use function. bmpShow has no link to FATFS (FATFS not public variable).
*
* fs.flag |= FA_STREAM; // Set stream mode
* bmpShow((unsigned int)SCREEN_HOR_SIZE/2 - w/2, (unsigned int)SCREEN_VER_SIZE/2 - h/2);
* fs.flag &= ~FA_STREAM; // Clear stream mode
*
************************************************** **********************************************/
#include "ff.h"
#include "TFT/tftlcd_functions.h"
#include "stm32f10x.h"
//-------------------------FAT------------------------------------
FRESULT ress;
FATFS drive;
FIL fil;
typedef struct BMIH { //declares BitMap Info Header structure
unsigned long biSize; //Length of bitmap information header (40 bytes for Windows V3 bitmaps)
unsigned long biWidth; //Width (pixels)
unsigned long biHeight; //Height (pixels)
unsigned short biPlanes; //Color planes, always 1
unsigned short biBitCount; //Color bits per pixel (1, 4, 8, 16, 24 and 32)
unsigned long biCompression; //Compression method, we only read uncompressed (type 0)
unsigned long biSizeImage; //Image data length
unsigned long biXPelsPerMeter; //Horizontal resolution (pixels per meter)
unsigned long biYPelsPerMeter; //Vertical resolution (pixel per meter)
unsigned long biClrUsed; //Number of colors, ignored.
unsigned long biClrImportant; //Number of important colors, ignored.
}BMP_INFO;
typedef struct BMFH { //declares BitMap File Header structure
unsigned short bfType; //Always 0x42 0x4D (hex for BM <-- indicating a bitmap)
unsigned long bfSize; //File size (bytes)
unsigned short bfReserved1; //Reserved, ignored
unsigned short bfReserved2; //Reserved, ignored
unsigned long bfOffBits; //Location in file of the first bitmap data
}BMP_HEADER;
unsigned long bmpWidth; //Width (pixels)
unsigned long bmpHeight; //Height (pixels)
FRESULT bmpFile(const char* fname)
{
BMP_HEADER BMPHeader;
BMP_INFO BMPInfo;
//FRESULT res;
int br;
if (f_open(&fil,fname,FA_READ) != FR_OK) return 1; // File Open count
if (f_read(&fil,&BMPHeader, sizeof(BMPHeader), &br) != FR_OK) return 2; // read bmp header
if (BMPHeader.bfType != 0x4d42 ) return 3; // type is 'BM'
if (f_read(&fil,&BMPInfo, sizeof(BMPInfo), &br) != FR_OK) return 4; // read bmp info
if (BMPInfo.biSize != 40) return 5; //unknown header format/length
if (BMPInfo.biPlanes != 1) return 6; //this should be 1
if (BMPInfo.biWidth > 240) return 7; //image over size
if (BMPInfo.biHeight > 320) return 8; //image over size
if (BMPInfo.biCompression != 0) return 9; //0=no compression
bmpWidth = BMPInfo.biWidth;
bmpHeight = BMPInfo.biHeight;
if (f_lseek(&fil,BMPHeader.bfOffBits)!= FR_OK) return 10; // move to start of bmp data
return FR_OK;
}
void RGB(unsigned char B,unsigned char G,unsigned char R)
{
unsigned short dat = 0x0000;
B = B >> 3;
G = G >> 2;
R = R >> 3;
// tftlcd_write_wdr2((R << 3) | (G >> 3), (G << 5) | B );
dat =((R << 3) | (G >> 3))<<8;
dat =(G << 5) | B;
tftlcd_write_wdr(dat);
}
unsigned char bmpShow(unsigned int sx, unsigned int sy) // support BMP 24 bit True color only
{
//unsigned short color;
unsigned int x,y;
unsigned int i,j;
unsigned int ex,ey;
unsigned char res,buffer[256];
unsigned int br;
ex = sx + bmpWidth-1;
ey = sy + bmpHeight-1;
if (sx < TFT_margin_xl)sx = TFT_margin_xl;
if (ex > TFT_margin_xr)ex = TFT_margin_xr;
if (sy < TFT_margin_yu)sy = TFT_margin_yu;
if (ey > TFT_margin_yl)ey = TFT_margin_yl;
tftlcd_write_index_register(TS_INS_ENTRY_MOD);
tftlcd_write_wdr(0x10);
tftlcd_write_index_register(TS_INS_START_ADX);
tftlcd_write_wdr(sx);
tftlcd_write_index_register(TS_INS_END_ADX);
tftlcd_write_wdr(ex);
tftlcd_write_index_register(TS_INS_GRAM_ADX);
tftlcd_write_wdr(sx);
x = (ex - sx + 1);
#ifndef TFT_ORN_PORTRAIT
sy = TS_SIZE_Y - 1 - sy;
ey = TS_SIZE_Y - 1 - ey;
tftlcd_write_index_register(TS_INS_START_ADY);
tftlcd_write_wdr(ey);
tftlcd_write_index_register(TS_INS_END_ADY);
tftlcd_write_wdr(sy);
tftlcd_write_index_register(TS_INS_GRAM_ADY);
tftlcd_write_wdr(sy);
y = sy - ey + 1;
#else
tftlcd_write_index_register(TS_INS_START_ADY);
tftlcd_write_wdr(sy);
tftlcd_write_index_register(TS_INS_END_ADY);
tftlcd_write_wdr(ey);
tftlcd_write_index_register(TS_INS_GRAM_ADY);
tftlcd_write_wdr(sy);
y = ey - sy;
#endif
tftlcd_write_index_register(TS_INS_RW_GRAM);
for (;;)
{
res = f_read(&fil,buffer,x,&br);
if(res || !br)break;
for (i=0; i<x; i+=3)
{
RGB(buffer[i+2],buffer[i+1],buffer[i]);
}
}
tftlcd_write_index_register(TS_INS_ENTRY_MOD);
tftlcd_write_wdr(TS_VAL_ENTRY_MOD);
return res;
}
به احتمال خیلی زیاد از قسمت void RGB باشه.
مثلا اون تعداد شیفت ها که داده.
ممنون میشم کمک کنید.