| 51 | } |
| 52 | |
| 53 | string FileFormatString(FileFormat magic, StringPiece data) { |
| 54 | switch (magic) { |
| 55 | case kPngFormat: |
| 56 | return "PNG"; |
| 57 | case kJpgFormat: |
| 58 | return "JPEG"; |
| 59 | case kGifFormat: |
| 60 | return "GIF"; |
| 61 | default: { |
| 62 | if (data.empty()) return "empty file"; |
| 63 | return strings::StrCat("unknown format starting with '", |
| 64 | absl::CEscape(data.substr(0, 16)), "'"); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // Decode an image (either jpeg, png, or gif). We use a single op so that |
| 70 | // users don't have to care about which format they have. |