MCPcopy Create free account
hub / github.com/creatale/node-dv / findFileFormatStream

Function findFileFormatStream

deps/leptonica/src/readfile.c:602–635  ·  view source on GitHub ↗

! * \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. * */

Source from the content-addressed store, hash-verified

600 * </pre>
601 */
602l_int32
603findFileFormatStream(FILE *fp,
604 l_int32 *pformat)
605{
606l_uint8 firstbytes[12];
607l_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/*!

Callers 5

pixReadStreamFunction · 0.85
pixReadHeaderFunction · 0.85
findFileFormatFunction · 0.85
fileFormatIsTiffFunction · 0.85
freadHeaderTiffFunction · 0.85

Calls 3

fnbytesInFileFunction · 0.85
findFileFormatBufferFunction · 0.85
findTiffCompressionFunction · 0.70

Tested by

no test coverage detected