C_and_CPP 板


LINE

请问file size的9-13注解和24-28注解 不太懂意思 1. // write to new bmp 2. fp_t = fopen(fname_t, "wb"); 3. if (fp_t == NULL) 4. { 5. printf("fopen fname_t error\n"); 6. return -1; 7. } 8. // file size 9. file_size = width * height * 3 + rgb_raw_data_offset; 10. header[2] = (unsigned char)(file_size & 0x000000ff); 11. header[3] = (file_size >> 8) & 0x000000ff; 12. header[4] = (file_size >> 16) & 0x000000ff; 13. header[5] = (file_size >> 24) & 0x000000ff; 14. // width 15. header[18] = width & 0x000000ff; 16. header[19] = (width >> 8) & 0x000000ff; 17. header[20] = (width >> 16) & 0x000000ff; 18. header[21] = (width >> 24) & 0x000000ff; 19. // height 20. header[22] = height &0x000000ff; 21. header[23] = (height >> 8) & 0x000000ff; 22. header[24] = (height >> 16) & 0x000000ff; 23. header[25] = (height >> 24) & 0x000000ff; 24. // write header 25. fwrite(header, sizeof(unsigned char), rgb_raw_data_offset, fp_t); 26. // write image 27. fwrite(image_t, sizeof(unsigned char), (size_t)(long)width * height * 3, 28. fp_t); 29. fclose(fp_t); --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.120.32.178
1F:推 VictorTom:http://zh.wikipedia.org/zh-tw/BMP 11/23 12:34
2F:→ VictorTom:去把格式的spec看一看你才知道它在写什麽资料进档案:) 11/23 12:34
3F:→ kkk1225:请问为什麽header後面要做(>>8)&0x000000ff在干麻的 11/23 12:51
4F:推 littleshan:明显是在处理 endian 不同的情况 11/23 12:55
5F:→ littleshan:这是很不好的 code,看来写的人不断地 copy-paste 11/23 12:56
6F:→ kkk1225:什麽是endian 11/23 12:57
7F:推 littleshan: http://en.wikipedia.org/wiki/Endianness 11/23 13:00
8F:→ VictorTom:小弟我也觉得10~13写法有点鸟, 而且好像处理不了endian 11/23 13:32
9F:→ VictorTom:不同的情况啊?_? 话说, 所以同一张BMP在endian不同的系 11/23 13:33
10F:→ VictorTom:统里解读出来会不一样喔?_? 指raw binary一模一样的情况 11/23 13:33
11F:推 littleshan:应该说 这段code只能在little endian的机器上跑吧 11/23 14:36
12F:推 VictorTom:对~~小弟就是这个意思XD 只是同一个BMP档会因为endian 11/23 14:37
13F:→ VictorTom:问题导致在Big End的时候就无法正常抓到size吗?? 还是 11/23 14:37
14F:→ VictorTom:这种case某一方要牵就对方?_? 11/23 14:38
15F:→ VictorTom:手上没有Big End的平台可以玩, 看来只好遇到了再去慢慢 11/23 14:38
16F:→ VictorTom:查资料, 没遇到就........XDDD 11/23 14:38
17F:推 twotwoone:http://www.cs.umass.edu/~verts/cs32/endian.html 11/23 14:52
18F:→ twotwoone:『What does that Mean for Us?』往下看一分钟 11/23 14:53
19F:推 VictorTom:先谢谢221大提供的资料, 大概下班回家才有空看吧....Orz 11/23 14:57
20F:→ VictorTom:就先跳到您说的那段, 看来是单一endian的, 所以BMP在 11/23 14:58
21F:→ VictorTom:Big End要牵就Lit End; 相对的有其他格式相反. 那这样 11/23 14:59
22F:→ VictorTom:看来那段sample code这样处理Lit End反而是正确的说@_@" 11/23 14:59
23F:推 twotwoone:http://codepad.org/va40P6qm 他就跟我这样都是写死 11/23 15:22
24F:→ twotwoone:程式码必须运行於 little-endian 的机器,他想要做的 11/23 15:22
25F:→ twotwoone:『BMP影像另存新档』动作才会正确 11/23 15:23
26F:→ twotwoone:当然fwrite部份,我都写4byte了,也是写死在32位元机器 11/23 15:25
27F:推 VictorTom:啊, 问题不在header[2~5], 在那个 file_size>> 是吗Orz 11/23 15:34
28F:推 twotwoone:是的,就弹性比较低。 11/23 18:43
29F:→ twotwoone:不过 header[] 阵列也是多此一举,因为只是把资料从记忆 11/23 18:43
30F:→ twotwoone:体的一端比如 int file_size 搬到另一端 header[] 而已 11/23 18:44
31F:→ kkk1225:我的程式还有前半段,上面的程式是後半段而已 11/24 16:44
32F:→ kkk1225:非常谢谢各位的回覆 11/24 16:47







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

请输入看板名称,例如:Tech_Job站内搜寻

TOP