作者wcmein (浪漫铁人8号 )
看板MacDev
标题[问题] 读取bmp影像档
时间Thu Jul 26 12:38:59 2007
请问一下
我利用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
30F:推 wcmein:谢了 我在试试看好了 07/28 08:24