MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ClassifyFileFormat

Function ClassifyFileFormat

tensorflow/core/kernels/decode_image_op.cc:45–51  ·  view source on GitHub ↗

Classify the contents of a file based on starting bytes (the magic number).

Source from the content-addressed store, hash-verified

43
44// Classify the contents of a file based on starting bytes (the magic number).
45FileFormat ClassifyFileFormat(StringPiece data) {
46 // The 4th byte of JPEG is '\xe0' or '\xe1', so check just the first three
47 if (absl::StartsWith(data, "\xff\xd8\xff")) return kJpgFormat;
48 if (absl::StartsWith(data, "\x89PNG\r\n\x1a\n")) return kPngFormat;
49 if (absl::StartsWith(data, "\x47\x49\x46\x38")) return kGifFormat;
50 return kUnknownFormat;
51}
52
53string FileFormatString(FileFormat magic, StringPiece data) {
54 switch (magic) {

Callers 1

ComputeMethod · 0.85

Calls 1

StartsWithFunction · 0.85

Tested by

no test coverage detected