看板 MacDev 關於我們 聯絡資訊
請問一下 我利用C++ 藉由 opengl 讀取影像檔 我在windows的VC++6.0 下可以讀取 可是在mac 的XCode (C++ tool) 下就無法讀取了 請問是何種原因 以下為source code 取材自opengl超級聖經 第二版 請問是哪裏有問題 ///// source code 開始 LoadDIBitmap(const char *filename, /* I - File to load */ BITMAPINFO **info) /* O - Bitmap information */ { FILE *fp; /* Open file pointer */ GLubyte *bits; /* Bitmap pixel bits */ int bitsize; /* Size of bitmap */ int infosize; /* Size of header information */ BITMAPFILEHEADER header; /* File header */ /* Try opening the file; use "rb" mode to read this *binary* file. */ if ((fp = fopen(filename, "rb")) == NULL) return (NULL); /* Read the file header and any following bitmap information... */ if (fread(&header, sizeof(BITMAPFILEHEADER), 1, fp) < 1) { /* Couldn't read the file header - return NULL... */ fclose(fp); return (NULL); } if (header.bfType != 'MB') /* Check for BM reversed... */ { /* Not a bitmap file - return NULL... */ fclose(fp); return (NULL); } infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER); if ((*info = (BITMAPINFO *)malloc(infosize)) == NULL) { /* Couldn't allocate memory for bitmap info - return NULL... */ fclose(fp); return (NULL); } if (fread(*info, 1, infosize, fp) < infosize) { /* Couldn't read the bitmap header - return NULL... */ free(*info); fclose(fp); return (NULL); } /* Now that we have all the header info read in, allocate memory for * * the bitmap and read *it* in... */ if ((bitsize = (*info)->bmiHeader.biSizeImage) == 0) bitsize = ((*info)->bmiHeader.biWidth * (*info)->bmiHeader.biBitCount + 7) / 8 * abs((*info)->bmiHeader.biHeight); if ((bits = malloc(bitsize)) == NULL) { /* Couldn't allocate memory - return NULL! */ free(*info); fclose(fp); return (NULL); } if (fread(bits, 1, bitsize, fp) < bitsize) { /* Couldn't read bitmap - free memory and return NULL! */ free(*info); free(bits); fclose(fp); return (NULL); } /* OK, everything went fine - return the allocated bitmap... */ fclose(fp); return (bits); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.96.77.105 ※ 編輯: wcmein 來自: 140.96.77.105 (07/26 13:11)
anpig:我很懷疑這樣compile會過嗎? 07/26 14:06
wcmein:過也 不過這是readbmp.cpp 的檔 我沒列出readbmp.h的檔 因 07/26 14:20
wcmein:為這樣會很長 主要我是要拿來貼圖的 因此我需要load bmp 07/26 14:22
atst:有trace過code嗎? 07/26 14:33
atst:要不要先試著在每個return的地方設一下break point 07/26 14:33
atst:看看是不是真的如你所預期的? 07/26 14:34
jclin:如果是PowerPC CPU, 是不是讀檔內容跟 endian 轉換的問題 07/26 17:09
wcmein:compiler過了 可是檢查MB那段 內容不是MB 然後程式就退出 07/26 17:17
wcmein:檢查後是這樣 該怎辦哩 07/26 17:18
HalfLucifer:ppc or x86 ? 07/26 17:59
atst:問題很明確,這段code是給特定格式的bmp檔用的 07/27 01:11
atst:印象中,bmp檔也有不同的格式與header 07/27 01:13
atst:從你的描述中看來,應該是所讀取的header的內容, 07/27 01:14
atst:與原本windows所要求的不同 07/27 01:14
atst:建議1. 檢查檔案的header,確定是此一問題導致 07/27 01:15
atst:2.若是,重寫header的剖析,以及讀檔時的各項判斷式 07/27 01:16
atst:加油囉.. 07/27 01:17
wcmein:是ppc 重寫header的剖析 我查查範例了 07/27 09:23
Blueshiva:header.bfType != 'MB' -> header.bfType != 'BM' 07/27 11:14
wcmein:改成BM也不行 檢查後bits=0因此讀取失敗 請問大家 有讀取 07/27 11:31
wcmein:影像檔的source code 或libarary嗎 在mac下的 07/27 11:33
wcmein:想放棄這個source code了 07/27 11:35
atst:建議你,在header.bfType != "MB" 07/27 12:31
atst:設中斷點檢查一下. 07/27 12:32
atst:header.bfType的型態,值各為何? 07/27 12:33
atst:若改用別的API當然也可以,但這樣的話, 07/27 12:34
atst:你對Debug的方式不會有進步 07/27 12:35
atst:還是試著使用Debug工具一步步把問題找出來吧... 07/27 12:35
atst:如果只是想讀bmp, 參考http://0rz.tw/2c2V3 07/27 13:25
wcmein:謝了 我在試試看好了 07/28 08:24