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灯, 水草

请输入看板名称,例如:e-shopping站内搜寻

TOP