Loads & depacks IMG (0 if succeded, else error). */ Bitplanes are one after another in address IMG_HEADER.addr. */
| 161 | /* Loads & depacks IMG (0 if succeded, else error). */ |
| 162 | /* Bitplanes are one after another in address IMG_HEADER.addr. */ |
| 163 | int |
| 164 | depack_img(char *name, IMG_header *pic) |
| 165 | { |
| 166 | int b, line, plane, width, word_aligned, opcode, patt_len, pal_size, |
| 167 | byte_repeat, patt_repeat, scan_repeat, error = FALSE; |
| 168 | char *pattern, *to, *endline, *puffer, sol_pat; |
| 169 | long size; |
| 170 | FILE *fp; |
| 171 | |
| 172 | if ((fp = fopen(name, "rb")) == NULL) |
| 173 | return (ERR_FILE); |
| 174 | |
| 175 | setvbuf(fp, NULL, _IOLBF, BUFSIZ); |
| 176 | |
| 177 | /* read header info (bw & ximg) into image structure */ |
| 178 | fread((char *) &(pic->version), 2, 8 + 3, fp); |
| 179 | |
| 180 | /* only 2-256 color imgs */ |
| 181 | if (pic->planes < 1 || pic->planes > 8) { |
| 182 | error = ERR_COLOR; |
| 183 | goto end_depack; |
| 184 | } |
| 185 | |
| 186 | /* if XIMG, read info */ |
| 187 | if (pic->magic == XIMG && pic->paltype == 0) { |
| 188 | pal_size = (1 << pic->planes) * 3 * 2; |
| 189 | if ((pic->palette = (short *) calloc(1, pal_size))) { |
| 190 | fread((char *) pic->palette, 1, pal_size, fp); |
| 191 | } |
| 192 | } else { |
| 193 | pic->palette = NULL; |
| 194 | } |
| 195 | |
| 196 | /* width in bytes word aliged */ |
| 197 | word_aligned = (pic->img_w + 15) >> 4; |
| 198 | word_aligned <<= 1; |
| 199 | |
| 200 | /* width byte aligned */ |
| 201 | width = (pic->img_w + 7) >> 3; |
| 202 | |
| 203 | /* allocate memory for the picture */ |
| 204 | free(pic->addr); |
| 205 | size = (long) ((long) word_aligned * (long) pic->img_h |
| 206 | * (long) pic->planes); /*MAR*/ |
| 207 | |
| 208 | /* check for header validity & malloc long... */ |
| 209 | if (pic->length > 7 && pic->planes < 33 && pic->img_w > 0 |
| 210 | && pic->img_h > 0) { |
| 211 | if (!(pic->addr = (char *) calloc(1, size))) { |
| 212 | error = ERR_ALLOC; |
| 213 | goto end_depack; |
| 214 | } |
| 215 | } else { |
| 216 | error = ERR_HEADER; |
| 217 | goto end_depack; |
| 218 | } |
| 219 | |
| 220 | patt_len = pic->pat_len; |
no test coverage detected