为什么位图文件的大小是 320x240 9730byte?
Why is the size of the bitmap file 320x240 9730byte?
我的环境:
CentOS6.5 (32bit)
ext4 file system
Intel Fortran v14.0.1
我正在尝试读取 bmp 格式的文件。
我研究了bmp格式。有 14 个字节的 BITMAPFILEHEADER 和 40 个字节的 BITMAPINFOHEADER。
图像的宽度和高度为 320x240。
图片色深为1位
根据我的计算,bmp文件的大小是
14 + 40 + 320x240/8 = 9654.
然而,实际尺寸是 9730。
造成差异 (9730 - 9654 = 76) 的原因是什么?这是因为文件的扇区大小吗?
以下是我用于打印 header 信息的代码 (Fortran)。
implicit none
type :: t_bmpFileHeader
sequence
integer(2) :: bfType
integer(4) :: bfSize
integer(2) :: bfReserved1
integer(2) :: bfReserved2
integer(4) :: bfOffBits
end type t_bmpFileHeader
type(t_bmpFileHeader) :: fheader
open(10, file='test.bmp', form='binary', status='unknown')
read(10) fheader
print *, fheader%bfSize
print *, fheader%bfOffBits
close(10)
end
输出(bfSize 和 bfOffBits)是
9730
130
以下是 identify -verbose test.bmp
. 的输出
Image: test.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: PseudoClass
Geometry: 320x240+0+0
Units: PixelsPerCentimeter
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Pixels: 76800
Gray:
min: 0 (0)
max: 1 (1)
mean: 0.0985417 (0.0985417)
standard deviation: 0.298046 (0.298046)
kurtosis: 5.25731
skewness: 2.69394
entropy: 0.464356
Colors: 2
Histogram:
69232: ( 0, 0, 0) #000000 gray(0)
7568: (255,255,255) #FFFFFF gray(255)
Colormap entries: 2
Colormap:
0: ( 0, 0, 0) #000000 gray(0)
1: (255,255,255) #FFFFFF gray(255)
Rendering intent: Perceptual
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: gray(255)
Border color: gray(223)
Matte color: gray(189)
Transparent color: gray(0)
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 320x240+0+0
Dispose: Undefined
Iterations: 0
Compression: Undefined
Orientation: Undefined
Properties:
date:create: 2015-01-18T07:39:32+09:00
date:modify: 2015-01-18T07:39:32+09:00
signature: 15df8571403f34fba791b56123e6923fc88fcc9f24e57a24aad152c651f3a55d
Artifacts:
filename: test.bmp
verbose: true
Tainted: False
Filesize: 9.73KB
Number pixels: 76.8K
Pixels per second: 3.0130237EB
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.9.0-4 Q16 i686 2015-01-17 http://www.imagemagick.org
像素数据的每条扫描线向上舍入为4字节的偶数倍。请务必考虑到这一点,因为不均匀的宽度会占用比您预期更多的字节(不过在这个特定示例中,320 是 4 的偶数倍)。
位深度 <= 8 的位图有一种颜色 table,您忽略了它。所以还有另外8-1024字节,具体取决于位深和压缩类型。
可能存在其他 header 字段和对齐填充,具体取决于位图类型(有许多可用选项会影响数据的打包方式)。
这些额外的细节很容易说明您丢失了额外的字节,因此您必须注意位图 header 实际告诉您的内容。
阅读以下内容了解更多详情:
我的环境:
CentOS6.5 (32bit)
ext4 file system
Intel Fortran v14.0.1
我正在尝试读取 bmp 格式的文件。
我研究了bmp格式。有 14 个字节的 BITMAPFILEHEADER 和 40 个字节的 BITMAPINFOHEADER。
图像的宽度和高度为 320x240。 图片色深为1位
根据我的计算,bmp文件的大小是
14 + 40 + 320x240/8 = 9654.
然而,实际尺寸是 9730。
造成差异 (9730 - 9654 = 76) 的原因是什么?这是因为文件的扇区大小吗?
以下是我用于打印 header 信息的代码 (Fortran)。
implicit none
type :: t_bmpFileHeader
sequence
integer(2) :: bfType
integer(4) :: bfSize
integer(2) :: bfReserved1
integer(2) :: bfReserved2
integer(4) :: bfOffBits
end type t_bmpFileHeader
type(t_bmpFileHeader) :: fheader
open(10, file='test.bmp', form='binary', status='unknown')
read(10) fheader
print *, fheader%bfSize
print *, fheader%bfOffBits
close(10)
end
输出(bfSize 和 bfOffBits)是
9730
130
以下是
identify -verbose test.bmp
. 的输出
Image: test.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: PseudoClass
Geometry: 320x240+0+0
Units: PixelsPerCentimeter
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Pixels: 76800
Gray:
min: 0 (0)
max: 1 (1)
mean: 0.0985417 (0.0985417)
standard deviation: 0.298046 (0.298046)
kurtosis: 5.25731
skewness: 2.69394
entropy: 0.464356
Colors: 2
Histogram:
69232: ( 0, 0, 0) #000000 gray(0)
7568: (255,255,255) #FFFFFF gray(255)
Colormap entries: 2
Colormap:
0: ( 0, 0, 0) #000000 gray(0)
1: (255,255,255) #FFFFFF gray(255)
Rendering intent: Perceptual
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: gray(255)
Border color: gray(223)
Matte color: gray(189)
Transparent color: gray(0)
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 320x240+0+0
Dispose: Undefined
Iterations: 0
Compression: Undefined
Orientation: Undefined
Properties:
date:create: 2015-01-18T07:39:32+09:00
date:modify: 2015-01-18T07:39:32+09:00
signature: 15df8571403f34fba791b56123e6923fc88fcc9f24e57a24aad152c651f3a55d
Artifacts:
filename: test.bmp
verbose: true
Tainted: False
Filesize: 9.73KB
Number pixels: 76.8K
Pixels per second: 3.0130237EB
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.9.0-4 Q16 i686 2015-01-17 http://www.imagemagick.org
像素数据的每条扫描线向上舍入为4字节的偶数倍。请务必考虑到这一点,因为不均匀的宽度会占用比您预期更多的字节(不过在这个特定示例中,320 是 4 的偶数倍)。
位深度 <= 8 的位图有一种颜色 table,您忽略了它。所以还有另外8-1024字节,具体取决于位深和压缩类型。
可能存在其他 header 字段和对齐填充,具体取决于位图类型(有许多可用选项会影响数据的打包方式)。
这些额外的细节很容易说明您丢失了额外的字节,因此您必须注意位图 header 实际告诉您的内容。
阅读以下内容了解更多详情: