MacDev 板


LINE

請問一下 我利用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)
1F:推 anpig:我很懷疑這樣compile會過嗎? 07/26 14:06
2F:→ wcmein:過也 不過這是readbmp.cpp 的檔 我沒列出readbmp.h的檔 因 07/26 14:20
3F:→ wcmein:為這樣會很長 主要我是要拿來貼圖的 因此我需要load bmp 07/26 14:22
4F:推 atst:有trace過code嗎? 07/26 14:33
5F:→ atst:要不要先試著在每個return的地方設一下break point 07/26 14:33
6F:→ atst:看看是不是真的如你所預期的? 07/26 14:34
7F:推 jclin:如果是PowerPC CPU, 是不是讀檔內容跟 endian 轉換的問題 07/26 17:09
8F:推 wcmein:compiler過了 可是檢查MB那段 內容不是MB 然後程式就退出 07/26 17:17
9F:→ wcmein:檢查後是這樣 該怎辦哩 07/26 17:18
10F:推 HalfLucifer:ppc or x86 ? 07/26 17:59
11F:推 atst:問題很明確,這段code是給特定格式的bmp檔用的 07/27 01:11
12F:→ atst:印象中,bmp檔也有不同的格式與header 07/27 01:13
13F:→ atst:從你的描述中看來,應該是所讀取的header的內容, 07/27 01:14
14F:→ atst:與原本windows所要求的不同 07/27 01:14
15F:→ atst:建議1. 檢查檔案的header,確定是此一問題導致 07/27 01:15
16F:→ atst:2.若是,重寫header的剖析,以及讀檔時的各項判斷式 07/27 01:16
17F:→ atst:加油囉.. 07/27 01:17
18F:→ wcmein:是ppc 重寫header的剖析 我查查範例了 07/27 09:23
19F:推 Blueshiva:header.bfType != 'MB' -> header.bfType != 'BM' 07/27 11:14
20F:推 wcmein:改成BM也不行 檢查後bits=0因此讀取失敗 請問大家 有讀取 07/27 11:31
21F:→ wcmein:影像檔的source code 或libarary嗎 在mac下的 07/27 11:33
22F:→ wcmein:想放棄這個source code了 07/27 11:35
23F:推 atst:建議你,在header.bfType != "MB" 07/27 12:31
24F:→ atst:設中斷點檢查一下. 07/27 12:32
25F:→ atst:header.bfType的型態,值各為何? 07/27 12:33
26F:→ atst:若改用別的API當然也可以,但這樣的話, 07/27 12:34
27F:→ atst:你對Debug的方式不會有進步 07/27 12:35
28F:→ atst:還是試著使用Debug工具一步步把問題找出來吧... 07/27 12:35
29F:推 atst:如果只是想讀bmp, 參考http://0rz.tw/2c2V3 07/27 13:25
30F:推 wcmein:謝了 我在試試看好了 07/28 08:24







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Boy-Girl站內搜尋

TOP