PDA

View Full Version : سوال: سوال درباره دو دستور LoadBmp24 و LnvertBMP



baran_mehr
چهارشنبه 18 فروردین 1389, 14:56 عصر
سلام به همه دوستان عزیز:تشویق:
میخواستم بدونم آیا درباره این دو دستور چیزی میدونید؟
LnvertBMP و دستور دوم LoadBmp24
اینکه چیکار میکنه و چطور باید ازشون استفاده کرد.

baran_mehr
پنج شنبه 19 فروردین 1389, 18:20 عصر
کسی از دوستان تا به حال در باره این دو تابع چیزی نشنیده؟
من خودم توی help سی رو نگاه کردم چیزی پیدا نکردم

amin1softco
پنج شنبه 19 فروردین 1389, 20:09 عصر
http://www.exaflop.org/docs/fastsprites/convimg.c

baran_mehr
پنج شنبه 19 فروردین 1389, 22:50 عصر
ممنون دوست عزیر
امکان داره مختصری توضیح درباره کار این دستورات بگب

amin1softco
جمعه 20 فروردین 1389, 00:42 صبح
دستور LoadBmp24 یک فایل bmp که 24 بیت برای هر پیکسل داره رو می تونه لود کنه و اطلاعات فایل رو تر جمه کنه تفاوت 8 بیتی با 24 بیتی اینه که در فایل ها 24 بیتی temmplatecolor حذف شده و بعد از هدرفایل مستقیم به اطلاعات مربوط به هر پیکسل می رسیم.

دستور InvertBMP یا به قول شما LnvertBMP یک کار برای ما انجام میده چون در فایل بیتمپ اطلاعات تصویر از گوشه پایین سمت چپ شروع می شه اگه شما یک فایل رو به ترتیب از اولش بخونی و پیکسل به پیکسل رسمش کنی یک تصویر وارونه داری کار این تابع اینه که آرایش پیکسل ها رو تغییر بده به طوری که اگه از اول فایل بخونیم و بریم جلو عکس در ست چاپ بشه نه وارونه



// invert the Bitmap bits so it becomes a top down image
// normally BMP files are bottom up.
void InvertBMP(BITMAPINFO* pBmInfo, unsigned char* pBmBits)
{
int Width, w;
int numRowsToSwap;
int TopRow, BottomRow;

// calculate the actual width of the row in bytes
if(pBmInfo->bmiHeader.biBitCount == 24) {
// calculate the width in Bytes for the image scanline
// (padded to DWORD boundary)
Width = ((pBmInfo->bmiHeader.biWidth*3) + 3) & ~3;
} else {
Width = pBmInfo->bmiHeader.biWidth / 32;
if(pBmInfo->bmiHeader.biWidth % 32 != 0)
Width = Width + 1;

Width *= 4;
}

// calculate the number of rows to swap
numRowsToSwap = pBmInfo->bmiHeader.biHeight / 2;

while(numRowsToSwap > 0) {
// calculate the top and bottom row being worked on
TopRow = numRowsToSwap - 1;
BottomRow = pBmInfo->bmiHeader.biHeight - numRowsToSwap;

// iterate accross the rows and swap the pixels
for(w = 0; w < Width; w++) {
unsigned char t;

t = pBmBits[(TopRow*Width) + w];
pBmBits[(TopRow*Width) + w] = pBmBits[(BottomRow*Width) + w];
pBmBits[(BottomRow*Width) + w] = t;
}

// new rows
numRowsToSwap--;
}
}







// Load a 24 bpp bitmap from the file pszFileName.
// Allocate and fill a BITMAPINFO and the bits.
int LoadBMP24(char* pszFileName, BITMAPINFO** pBmInfo, unsigned char** pBmBits)
{
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
DWORD dwRead;
DWORD nSizeOfBits;
FILE* fIn;

// open the bitmap file
fIn = fopen(pszFileName, "rb");

if( fIn == NULL) {
printf("\nCould not open %s\n", pszFileName);
return FALSE;
}

// read the BITMAPFILEHEADER
dwRead = fread(&bmfh, sizeof(BITMAPFILEHEADER), 1, fIn );

if (dwRead != 1 ) {
fclose(fIn);
printf("\nRead bitmap file header failed\n");
return FALSE;
}


// Retrieve the BITMAPFILEHEADER structure.
dwRead = fread(&bmih, sizeof(BITMAPINFOHEADER), 1, fIn );

if (dwRead != 1 ) {
fclose(fIn);
printf("\nRead bitmap info header failed\n");
return FALSE;
}

// make sure this is a 24 bpp bitmap
if(bmih.biBitCount != 24) {
fclose(fIn);
printf("\n%s: Not a 24 bit BMP\n", pszFileName);
return FALSE;
}

// make shure this is a bottom up DIB
if(bmih.biHeight < 0) {
fclose(fIn);
printf("\n%s: Not a Bottom Up BMP\n", pszFileName);
return FALSE;
}

// Allocate memory for the BITMAPINFO structure. Note there are no colour entries in this
// file because it is 24 bit
*pBmInfo = (BITMAPINFO*) malloc(sizeof(BITMAPINFOHEADER));

// Load BITMAPINFOHEADER into the BITMAPINFO structure.
(*pBmInfo)->bmiHeader.biSize = bmih.biSize;
(*pBmInfo)->bmiHeader.biWidth = bmih.biWidth;
(*pBmInfo)->bmiHeader.biHeight = bmih.biHeight;
(*pBmInfo)->bmiHeader.biPlanes = bmih.biPlanes;
(*pBmInfo)->bmiHeader.biBitCount = bmih.biBitCount;
(*pBmInfo)->bmiHeader.biCompression = bmih.biCompression;
(*pBmInfo)->bmiHeader.biSizeImage = bmih.biSizeImage;
(*pBmInfo)->bmiHeader.biXPelsPerMeter = bmih.biXPelsPerMeter;
(*pBmInfo)->bmiHeader.biYPelsPerMeter = bmih.biYPelsPerMeter;
(*pBmInfo)->bmiHeader.biClrUsed = bmih.biClrUsed;
(*pBmInfo)->bmiHeader.biClrImportant = bmih.biClrImportant;

// Allocate memory for the required number of bytes.
nSizeOfBits = bmfh.bfSize - bmfh.bfOffBits;
*pBmBits = (unsigned char*)malloc(nSizeOfBits);

// seek to the begining of the bitmap data
fseek(fIn, bmfh.bfOffBits, SEEK_SET);

// read the bitmap data
dwRead = 0;
while(dwRead < nSizeOfBits ) {
dwRead = dwRead + fread((*pBmBits)+dwRead, 1, nSizeOfBits-dwRead, fIn );
}

// close the file
fclose(fIn);

InvertBMP( *pBmInfo, *pBmBits );

return TRUE;
}

baran_mehr
جمعه 20 فروردین 1389, 09:31 صبح
ممنون دوست عزیز
LnvertBMP نیست همون I nvertBMP هست فقط اشتباه چاپی بود