- if (fread(&type, sizeof type, 1, img->f) != 1) goto readerr;
- type = letohs(type); img->foff += sizeof type;
-
- if (first) {
- img->currentx = 0;
- img->currenty = 0;
- type = 0;
- }
-
- if (type == 0) {
- if (fread(&yval, sizeof yval, 1, img->f) != 1) goto readerr;
- yval = letohs(yval); img->foff += sizeof yval;
- if (yval == 1000)
- return 1;
- if (fread(&count, sizeof count, 1, img->f) != 1) goto readerr;
- count = letohs(count); img->foff += sizeof count;
- if (fread(&xval, sizeof xval, 1, img->f) != 1) goto readerr;
- xval = letohs(xval); img->foff += sizeof xval;
- if (xval == 1000)
- return 1;
-
- /* Ensure that the row fits in the image. */
- if (img->height - img->currenty <= yval || xval >= img->width) {
- lbx_errno = LBX_EFORMAT;
- return -1;
- }