Difference between revisions of "Aufgaben:Exercise 5.8: BMP Format"

From LNTwww
 
Line 46: Line 46:
 
{Which image format has the image "Sunset.bmp"?
 
{Which image format has the image "Sunset.bmp"?
 
|type="{}"}
 
|type="{}"}
$\rm width \ = \ $ { 280 } $\ \rm Pixel $
+
$\rm width \ = \ $ { 280 } $\ \rm pixels $
$\rm height \hspace{0.3cm} = \ $ { 210 } $\ \rm Pixel $
+
$\rm height \hspace{0.3cm} = \ $ { 210 } $\ \rm pixels $
  
 
{What is the color depth in "bit per pixel" $\rm (BPP)$?
 
{What is the color depth in "bit per pixel" $\rm (BPP)$?

Latest revision as of 13:46, 18 October 2022

Photo "Sunset"

A bitmap is an image format in which the individual pixels (of Picture Elements ) are stored in matrix form. The header of such a BMP file contains at least 54 bytes, consisting of the file header (in hexadecimal representation from 0x00 to 0x0D) as well as the information block starting from 0x0E. This is followed by the image data, in the case of color images with the color components R – G – B.

The following hexdump describes the photo "Sunset.bmp". Shown are the first and last 96 of the total 176456 bytes in hexadecimal representation.

Hexdump for Sunset.bmp

The file header contains the following information (the prefix "0x" indicates the hexadecimal representation):

  • 0x00 ... 0x01 (2 bytes) BMP identifier: 0x 42 4D  ⇒  "BM",
  • 0x02 ... 0x05 (4 bytes) file size in bytes,
  • 0x06 ... 0x09 (5 bytes) reserved (must always be assigned 0),
  • 0x0A ... 0x0D (4 bytes) offset (start of image data).


These specifications are only valid for the Intel processor, which reads according to the little–endian byte order from the least significant byte (LSB) to the most significant byte (MSB). The order "48 B1 02 00" of bytes 2 to 5 is therefore to be interpreted as "0x 00 02 B1 48", which corresponds to the decimal number 176456.

The 40 byte information block contains the following values:

  • 0x0E ... 0x11 (4 bytes) length of the info block,
  • 0x12 ... 0x15 (4 bytes) image width in pixels,
  • 0x16 ... 0x19 (4 bytes) image height in pixels,
  • 0x1A ... 0x1B (2 bytes) number of color planes (always set to 1),
  • 0x1C ... 0x1D (2 bytes) bits per pixel (BPP),
  • 0x1E ... 0x21 (4 bytes) type of data compression,
  • 0x22 ... 0x25 (4 bytes) size of the bitmap in bytes,
  • 0x26 ... 0x29 (4 bytes) horizontal resolution in pixels/meter,
  • 0x2A ... 0x2D (4 bytes) vertical resolution in pixels/meter,
  • 0x2E ... 0x31 (4 bytes) number of colors used,
  • 0x32 ... 0x35 (4 bytes) number of important colors.




Note:


Questions

1

Which image format has the image "Sunset.bmp"?

$\rm width \ = \ $

$\ \rm pixels $
$\rm height \hspace{0.3cm} = \ $

$\ \rm pixels $

2

What is the color depth in "bit per pixel" $\rm (BPP)$?

$\rm color \ depth \ = \ $

$\ \rm BPP $

3

What is the vertical resolution in "dot per inch" $\rm (dpi)$? Conversion: $1 \ {\rm inch} \approx 25.4 \ \rm mm$?

$\rm vertical \ resolution \ = \ $

$\ \rm dpi $

4

How many bytes  $(N_{\rm Info})$  does the information block contain here? From which byte  $\rm (offset)$  does the image data start?

$\rm offset \ = \ $

$\ \rm bytes $
$N_{\rm Info} \hspace{0.38cm} = \ $

$\ \rm (decimal) $

5

What are the decimal values of the color components of the upper left pixel?

$R \ = \ $

$\ \rm (decimal) $
$G \ = \ $

$\ \rm (decimal) $
$B \ = \ $

$\ \rm (decimal) $


Solution

(1)  The image width (in the range 0x12 ... 0x15) has the hexadecimal value 0x118 (decimal value 280).

  • Correspondingly, the image height (in the range 0x16 ... 0x19) has the hexadecimal value 0x00D2 ⇒ 210 pixels.
  • The decimal values 280 (width) and 210 (height) are to be entered in each case.


(2)  The color depth is 24 BPP (hexadecimal 0x18), as specified in the range 0x1C ... 0x1D.


(3)  The vertical resolution can be found in the range 0x2A ... 0x2D. It is 0x 0E EA = 3818 pixels per meter.

  • With the specified length conversion, this results in 3818 · 0.0254 ≈ 97 dpi (dots per inch).
  • The horizontal resolution (range 0x26 ... 0x29) is similar, but not the same: 0x0EC3 ⇒ 3779 · 0.0254 ≈ 96 dpi.


(4)  At 24 BPP (color depth) the information block has the minimum size 0x28 = 40d, because then no color information is given in tabular form.

  • Taking into account the 14 bytes for the file header, the offset is 0x36 = 54 bytes (offset). The first data byte is therefore 0x36.
  • The size of the bitmap (in the range 0x22 ... 0x25) is 0x 02 B1 12 = 176402d. This value is smaller than the file size by 54 (file header). This value is composed as follows:
$$N_{\rm Info} = 280 \cdot 210 \cdot 3 + 2 \hspace{0.15cm}\underline {= 176402} .$$
  • Here, the "2" takes into account the two termination bytes (00 00), as can be seen from the hex dump in the information section.


(5)  The image data are stored line by line from bottom right to top left with three bytes each. The color values of the upper left point are thus

R = 0x28 = 40d,
G = 0x52 = 82d,
B = 0x73 = 115d.


Note here again the little–endian byte order of the Intel processor, so that  "R – G – B"  are actually arranged in the rows  "B – G – R".