| 1 | /* |
| 2 | * gifdump.c |
| 3 | * |
| 4 | * Copyright (C) 2003-2025 Cosmin Truta. |
| 5 | * This software is distributed under the same licensing and warranty terms |
| 6 | * as gifread.c. |
| 7 | */ |
| 8 | |
| 9 | #include "gifread.h"cxx . . $ `<file>/third_party/gifread/gifread.h`/ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | |
| 13 | |
| 14 | /* |
| 15 | * Dumps the structure of a GIF image file. |
| 16 | */ |
| 17 | int GIFDumpcxx . . $ GIFDump(5c4306d8553b3696).(const char *filename) |
| 18 | { |
| 19 | int result; |
| 20 | FILEcxx . . $ FILE# *stream; |
| 21 | struct GIFScreencxx . . $ GIFScreen# screen; |
| 22 | struct GIFImagecxx . . $ GIFImage# image; |
| 23 | struct GIFExtensioncxx . . $ GIFExtension# ext; |
| 24 | struct GIFGraphicCtlExtcxx . . $ GIFGraphicCtlExt# graphicExt; |
| 25 | int loop; |
| 26 | |
| 27 | stream = fopencxx . . $ fopen(82ec0787cd37e0a3).(filename, "rb"); |
| 28 | if (stream == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 29 | { |
| 30 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error: Can't open %s\n", filename); |
| 31 | return -1; |
| 32 | } |
| 33 | |
| 34 | result = 0; |
| 35 | printfcxx . . $ printf(581fddd72a8db8fc).("File: %s\n", filename); |
| 36 | |
| 37 | GIFReadScreencxx . . $ GIFReadScreen(cda1c5bcbeb2a4f0).(&screen, stream); |
| 38 | printfcxx . . $ printf(581fddd72a8db8fc).("Screen: %u x %u\n", screen.Widthcxx . . $ GIFScreen#Width., screen.Heightcxx . . $ GIFScreen#Height.); |
| 39 | if (screen.GlobalColorFlagcxx . . $ GIFScreen#GlobalColorFlag.) |
| 40 | printfcxx . . $ printf(581fddd72a8db8fc).(" Global colors: %u\n", screen.GlobalNumColorscxx . . $ GIFScreen#GlobalNumColors.); |
| 41 | if (screen.PixelAspectRatiocxx . . $ GIFScreen#PixelAspectRatio. != 0) |
| 42 | printfcxx . . $ printf(581fddd72a8db8fc).(" Pixel aspect ratio = %u\n", screen.PixelAspectRatiocxx . . $ GIFScreen#PixelAspectRatio.); |
| 43 | |
| 44 | GIFInitImagecxx . . $ GIFInitImage(c956e24543cc1768).(&image, &screen, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 45 | GIFInitExtensioncxx . . $ GIFInitExtension(229c763ec06d9c9f).(&ext, &screen, 256); |
| 46 | |
| 47 | loop = 1; |
| 48 | while (loop) |
| 49 | { |
| 50 | switch (GIFReadNextBlockcxx . . $ GIFReadNextBlock(3a398aa393699901).(&image, &ext, stream)) |
| 51 | { |
| 52 | case GIF_TERMINATORcxx . . $ `third_party/gifread/gifread.h:39:9`!: |
| 53 | loop = 0; |
| 54 | break; |
| 55 | case GIF_IMAGEcxx . . $ `third_party/gifread/gifread.h:38:9`!: |
| 56 | ++result; |
| 57 | printfcxx . . $ printf(581fddd72a8db8fc).("Image: %u x %u @ (%u, %u)\n", |
| 58 | image.Widthcxx . . $ GIFImage#Width., image.Heightcxx . . $ GIFImage#Height., image.LeftPoscxx . . $ GIFImage#LeftPos., image.TopPoscxx . . $ GIFImage#TopPos.); |
| 59 | if (image.LocalColorFlagcxx . . $ GIFImage#LocalColorFlag.) |
| 60 | printfcxx . . $ printf(581fddd72a8db8fc).(" Local colors: %u\n", image.LocalNumColorscxx . . $ GIFImage#LocalNumColors.); |
| 61 | printfcxx . . $ printf(581fddd72a8db8fc).(" Interlaced: %s\n", image.InterlaceFlagcxx . . $ GIFImage#InterlaceFlag. ? "YES" : "NO"); |
| 62 | break; |
| 63 | case GIF_EXTENSIONcxx . . $ `third_party/gifread/gifread.h:37:9`!: |
| 64 | if (ext.Labelcxx . . $ GIFExtension#Label. == GIF_GRAPHICCTLcxx . . $ `third_party/gifread/gifread.h:40:9`!) |
| 65 | { |
| 66 | GIFGetGraphicCtlcxx . . $ GIFGetGraphicCtl(d115dbec00c89685).(&graphicExt, &ext); |
| 67 | printfcxx . . $ printf(581fddd72a8db8fc).("Graphic Control Extension: 0x%02X\n", ext.Labelcxx . . $ GIFExtension#Label.); |
| 68 | printfcxx . . $ printf(581fddd72a8db8fc).(" Disposal method: %u\n", graphicExt.DisposalMethodcxx . . $ GIFGraphicCtlExt#DisposalMethod.); |
| 69 | printfcxx . . $ printf(581fddd72a8db8fc).(" User input flag: %u\n", graphicExt.InputFlagcxx . . $ GIFGraphicCtlExt#InputFlag.); |
| 70 | printfcxx . . $ printf(581fddd72a8db8fc).(" Delay time : %u\n", graphicExt.DelayTimecxx . . $ GIFGraphicCtlExt#DelayTime.); |
| 71 | if (graphicExt.TransparentFlagcxx . . $ GIFGraphicCtlExt#TransparentFlag.) |
| 72 | printfcxx . . $ printf(581fddd72a8db8fc).(" Transparent : %u\n", graphicExt.Transparentcxx . . $ GIFGraphicCtlExt#Transparent.); |
| 73 | } |
| 74 | else |
| 75 | printfcxx . . $ printf(581fddd72a8db8fc).("Extension: 0x%02X\n", ext.Labelcxx . . $ GIFExtension#Label.); |
| 76 | break; |
| 77 | default: |
| 78 | result = -1; |
| 79 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error: Unexpected data in %s\n", filename); |
| 80 | loop = 0; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(stream); |
| 85 | |
| 86 | if (result == 0) |
| 87 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error: No image in %s\n", filename); |
| 88 | return result; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * main |
| 93 | */ |
| 94 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) |
| 95 | { |
| 96 | int result; |
| 97 | int i; |
| 98 | |
| 99 | if (argc <= 1) |
| 100 | { |
| 101 | printfcxx . . $ printf(581fddd72a8db8fc).("Usage: gifdump [<file>...]\n"); |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | result = 0; |
| 106 | for (i = 1; i < argc; ++i) |
| 107 | { |
| 108 | if (GIFDumpcxx . . $ GIFDump(5c4306d8553b3696).(argv[i]) <= 0) |
| 109 | result = 1; |
| 110 | } |
| 111 | |
| 112 | return result; |
| 113 | } |