return total;
}
+// For a single image the table just contains the end of the image.
static uint32_t * ReadImageTable(SurfaceFileHeader *hdrPtr, FILE *fp)
{
uint32_t *table = NULL;
free(triangles);
}
+ uint32_t image_table = ftell(fp);
+ printf(" image table: %#08x\n", image_table);
uint32_t *offsets = ReadImageTable(&hdr, fp);
uint32_t table_base = ftell(fp);
if (offsets)
{
+ if (hdr.num_images < 10)
+ {
+ for (uint32_t n = 0; n < hdr.num_images + 1; ++n)
+ printf(" %lu: %#08x\n", n, offsets[n]);
+ }
printf(" image base: %#08x\n", table_base);
#ifdef WIN32
_tmkdir(_T("images"));
exit(1);
}
- // this calculated image size is off by 4 bytes. why?
- uint32_t image_size = offsets[n + 1] - offsets[n] - sizeof(SurfaceImageInfo);
+ uint32_t image_section_size = offsets[n + 1] - offsets[n] - sizeof(SurfaceImageInfo);
SurfaceImageInfo info = { 0 };
fseek(fp, offsets[n], SEEK_SET);
fread(&info, sizeof(SurfaceImageInfo), 1, fp);
size_t len = fcopy(fp, fp2, info.image_size);
fclose(fp2);
+ // For revision > 2 we have the size of the 'original' image if present and the image data.
+ if (hdr.revision > 2)
+ {
+ uint32_t backup_size = 0;
+ fread(&backup_size, sizeof(uint32_t), 1, fp);
+ fseek(fp, backup_size, SEEK_CUR);
+ len += sizeof(backup_size) + backup_size; // account for 'backup image' and its size
+ printf(" orig:%u: %u\n", n, backup_size);
+ }
- printf(" img:%d: %#08x @(%.3f,%.3f,%.3f) fov:%.3f,%.3f res:%u,%u off:%d,%d siz:%#08x %d\n",
- n, offsets[n],
+ printf(" img:%u: %#08x @(%.3f,%.3f,%.3f) fov:%.3f,%.3f res:%u,%u off:%d,%d siz:%#08x\n",
+ n, offsets[n],
info.point.x, info.point.y, info.point.z,
info.image_width_microns, info.image_height_microns,
info.resolution_x, info.resolution_y,
- info.xoffset, info.yoffset, info.image_size, len-image_size);
+ info.xoffset, info.yoffset, info.image_size);
+ if ((len - image_section_size) != 0)
+ {
+ printf(" image size error of %zu bytes\n", (len - image_section_size));
+ }
}
free(offsets);
}