PDA

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : کتابخانه sdbmp.c در مد 16 بیتی برای lcd n96



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 باشه.
مثلا اون تعداد شیفت ها که داده.
ممنون میشم کمک کنید.

wantedboy
03-10-2014, 23:06
سلام دوستان
این موضوع فکر کنم کمک کنه.

توضیحات در مورد فرمت bmp

فرمت bmp یا بیتمپ یک نوع فایل تصویری است که در آن عمل کد کردن صورت نگرفته و به راحتی می توان رنگ هر پیکسل دست پیدا کرد. در صورتی که تصویر بیتمپ به صورت فرمت 24بیتی ذخیره شود، تا بایت 54 ام هدر تصویر است که یک سری توضیحات در مورد فایل قرار دارد. از بایت 54 ام به بعد بایت های رنگ هر پیکسل قرار دارد. به این صورت که هر سه بایت پشت سر هم رنگ یک پیکسل را تشکیل می دهد. برای نمونه بایت 55 ام رنگ آبی ، بایت 56 رنگ سبز و بایت 57 ام رنگ قرمز را مشخص می کند تا ترکیب رنگ rgb برای نمایش یک پیکسل درست شود.

در lcd n96 فرمت رنگ بندی به صورت 16بیتی است یعنی رنگ قرمز 5بیت ، رنگ سبز 6بیت و رنگ آبی 5بیت را در بر میگرد. بنابراین برای نمایش تصویر بیتمپ باید آن را از فرمت رنگ 24بتی به صورت 16بیتی در آوریم. بدین منظور باید رنگ قرمز را از رنج 0 تا 255(8بیتی) به رنج 0 تا 31 (5بیتی) ، رنگ سبز را از رنج 0 تا 255(8بیتی)به رنج 0 تا 63 (6بیتی) و رنگ آبی را از رنج 0 تا 255 به رنج 0تا31 بیت ببریم. که با یک عمل تناسب ساده این کار صورت میگیرد.

من با توجه به موضوع بالا این تغییر دادم درست نشد.

void RGB(unsigned char B,unsigned char G,unsigned char R) {
unsigned short dat = 0x0000;

// B = B >> 3;
// G = G >> 2;
// R = R >> 3;
B=B*31>>8;
G=G*63>>8;
R=R*31>>8;






// tftlcd_write_wdr2((R << 3) | (G >> 3), (G << 5) | B );

// dat =((R << 3) | (G >> 3))<<8;
// dat =(G << 5) | B;
tftlcd_write_wdr((R<<11)+(G<<5)+B);

}

mzarkoob
04-10-2014, 10:46
سلام
از این کد من استفاده کردم. حداقل می دونم برای تصاویر 24 بیت که روی LCD 7 اینچ با درایور ssd1963 نمایش میداد درست کار می کرد!

wantedboy
04-10-2014, 13:26
سلام
از این کد من استفاده کردم. حداقل می دونم برای تصاویر 24 بیت که روی LCD 7 اینچ با درایور ssd1963 نمایش میداد درست کار می کرد!

سلام
داخل avr هم رو مد 8 بیتی رنگ درست نشون میداد ولی تا مد 16 بیتی میشد رنگ تصویر به یه سمتی تمایل پیدا می کرد.
تنها دستوری که در مد ها تغییر می کرد همون ریختن پیکسل ها داخل lcd که من هرچی تغییرش دادم به رنگ درستی نرسیدم.فکر کنم از همین باشه
لطفا کمک کنیدددد

vahid_22002
09-10-2014, 19:54
دلیل داره! باید type casting انجام بدین!

wantedboy
09-10-2014, 22:40
دلیل داره! باید type casting انجام بدین!
سلام
اگه میشه توضیح بیشتری بدید

vahid_22002
11-10-2014, 20:13
نمی دونم گیرش چیه؟ دلیلش چیه؟ اما تو codevision این گیر بود، فکر کنم تو keil هم این ایراد باشه.
شما R و G و B رو به جای char از نوع long int تعریف کن. خیلی هم محدودیت حافظه نداری. که حالا یه char بشه long int.
دیکه type casting هم نمی خواد.