! * \brief findFileFormatStream() * * \param[in] fp file stream * \param[out] pformat found format * \return 0 if OK, 1 on error or if format is not recognized * * * Notes: * (1) Important: Side effect -- this resets fp to BOF. * */
| 600 | * </pre> |
| 601 | */ |
| 602 | l_int32 |
| 603 | findFileFormatStream(FILE *fp, |
| 604 | l_int32 *pformat) |
| 605 | { |
| 606 | l_uint8 firstbytes[12]; |
| 607 | l_int32 format; |
| 608 | |
| 609 | PROCNAME("findFileFormatStream"); |
| 610 | |
| 611 | if (!pformat) |
| 612 | return ERROR_INT("&format not defined", procName, 1); |
| 613 | *pformat = IFF_UNKNOWN; |
| 614 | if (!fp) |
| 615 | return ERROR_INT("stream not defined", procName, 1); |
| 616 | |
| 617 | rewind(fp); |
| 618 | if (fnbytesInFile(fp) < 12) |
| 619 | return ERROR_INT("truncated file", procName, 1); |
| 620 | |
| 621 | if (fread((char *)&firstbytes, 1, 12, fp) != 12) |
| 622 | return ERROR_INT("failed to read first 12 bytes of file", procName, 1); |
| 623 | rewind(fp); |
| 624 | |
| 625 | findFileFormatBuffer(firstbytes, &format); |
| 626 | if (format == IFF_TIFF) { |
| 627 | findTiffCompression(fp, &format); |
| 628 | rewind(fp); |
| 629 | } |
| 630 | *pformat = format; |
| 631 | if (format == IFF_UNKNOWN) |
| 632 | return 1; |
| 633 | else |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | |
| 638 | /*! |
no test coverage detected