| 117 | } |
| 118 | |
| 119 | bool Bmp8::LoadFromCharDumpFile(CachedFile *fp) { |
| 120 | unsigned short wid; |
| 121 | unsigned short hgt; |
| 122 | unsigned short x; |
| 123 | unsigned short y; |
| 124 | int buf_size; |
| 125 | int pix; |
| 126 | int pix_cnt; |
| 127 | unsigned int val32; |
| 128 | unsigned char *buff; |
| 129 | |
| 130 | // read and check 32 bit marker |
| 131 | if (fp->Read(&val32, sizeof(val32)) != sizeof(val32)) { |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | if (val32 != kMagicNumber) { |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | // read wid and hgt |
| 140 | if (fp->Read(&wid, sizeof(wid)) != sizeof(wid)) { |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | if (fp->Read(&hgt, sizeof(hgt)) != sizeof(hgt)) { |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | // read buf size |
| 149 | if (fp->Read(&buf_size, sizeof(buf_size)) != sizeof(buf_size)) { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | // validate buf size: for now, only 3 channel (RBG) is supported |
| 154 | pix_cnt = wid * hgt; |
| 155 | if (buf_size != (3 * pix_cnt)) { |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | // alloc memory & read the 3 channel buffer |
| 160 | buff = new unsigned char[buf_size]; |
| 161 | |
| 162 | if (fp->Read(buff, buf_size) != buf_size) { |
| 163 | delete []buff; |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | // create internal buffers |
| 168 | wid_ = wid; |
| 169 | hgt_ = hgt; |
| 170 | |
| 171 | line_buff_ = CreateBmpBuffer(); |
| 172 | if (line_buff_ == NULL) { |
| 173 | delete []buff; |
| 174 | return false; |
| 175 | } |
| 176 |
no test coverage detected