MCPcopy Create free account
hub / github.com/davisking/dlib / load_bmp

Function load_bmp

dlib/image_loader/image_loader.h:33–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 typename image_type
32 >
33 void load_bmp (
34 image_type& image_,
35 std::istream& in_
36 )
37 {
38 image_view<image_type> image(image_);
39 try
40 {
41 unsigned long bytes_read_so_far = 0;
42 unsigned long bfSize;
43 unsigned long bfOffBits;
44 unsigned long biSize;
45 unsigned long biWidth;
46 int32 biHeight;
47 unsigned short biBitCount;
48 unsigned long biCompression;
49 unsigned long a, b, c, d, i;
50
51 std::streambuf& in = *in_.rdbuf();
52 unsigned char buf[100];
53
54
55 // first make sure the BMP starts with BM
56 if (in.sgetn(reinterpret_cast<char*>(buf),2) != 2)
57 throw image_load_error("bmp load error 1: header error");
58 bytes_read_so_far += 2;
59
60 if (buf[0] != 'B' || buf[1] != 'M')
61 throw image_load_error("bmp load error 2: header error");
62
63 // now read the BITMAPFILEHEADER
64 if (in.sgetn(reinterpret_cast<char*>(buf),12) != 12)
65 throw image_load_error("bmp load error 3: header error");
66
67 bytes_read_so_far += 12;
68
69 i = 0;
70 a = buf[i]; b = buf[i+1]; c = buf[i+2]; d = buf[i+3];
71 bfSize = a | (b<<8) | (c<<16) | (d<<24);
72
73 // Ignore the next 4 bytes (Reserved Area)
74
75 i = 8;
76 a = buf[i]; b = buf[i+1]; c = buf[i+2]; d = buf[i+3];
77 bfOffBits = a | (b<<8) | (c<<16) | (d<<24);
78
79 // load the BITMAPINFOHEADER
80 if (in.sgetn(reinterpret_cast<char*>(buf),40) != 40)
81 throw image_load_error("bmp load error 5: file too short");
82 bytes_read_so_far += 40;
83
84
85 i = 0;
86 a = buf[i]; b = buf[i+1]; c = buf[i+2]; d = buf[i+3];
87 biSize = a | (b<<8) | (c<<16) | (d<<24);
88
89 i += 4;
90 a = buf[i]; b = buf[i+1]; c = buf[i+2]; d = buf[i+3];

Callers 3

load_imageFunction · 0.85
perform_testMethod · 0.85
image_testFunction · 0.85

Calls 7

assign_pixelFunction · 0.85
assign_all_pixelsFunction · 0.85
image_load_errorClass · 0.70
minFunction · 0.50
set_sizeMethod · 0.45
ncMethod · 0.45
clearMethod · 0.45

Tested by 2

perform_testMethod · 0.68
image_testFunction · 0.68