File: gif.c

package info (click to toggle)
htp 1.11-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 316 kB
  • ctags: 429
  • sloc: ansic: 5,108; makefile: 55
file content (85 lines) | stat: -rw-r--r-- 1,722 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
//
// gif.c
//
// GIF (Graphic Interchange Format) support functions
//
// Copyright (c) 1995-96 Jim Nelson.  Permission to distribute
// granted by the author.  No warranties are made on the fitness of this
// source code.
//
*/

#include "htp.h"

BOOL GifFormatFound(FILE *file)
{
    BYTE header[8];

    /* move to BOF */
    if(fseek(file, 0, SEEK_SET) != 0)
    {
        DEBUG_PRINT(("unable to seek to start of GIF file"));
        return FALSE;
    }

    /* read first six bytes, looking for GIF header + version info */
    if(fread(header, 1, 6, file) != 6)
    {
        DEBUG_PRINT(("could not read GIF image file header"));
        return FALSE;
    }

    /* is this a GIF file? */
    if((memcmp(header, "GIF87a", 6) == 0) || (memcmp(header, "GIF89a", 6) == 0))
    {
        return TRUE;
    }

    /* not a GIF file */
    return FALSE;
}

BOOL GifReadDimensions(FILE *file, WORD *height, WORD *width)
{
    BYTE hi;
    BYTE lo;

    /* move to the image size position in the file header */
    if(fseek(file, 6, SEEK_SET) != 0)
    {
        DEBUG_PRINT(("unable to seek to start of GIF file"));
        return FALSE;
    }

    /* read the width, byte by byte */
    /* this gets around machine endian problems while retaining the */
    /* fact that GIF uses little-endian notation */
    if(fread(&lo, 1, 1, file) != 1)
    {
        return FALSE;
    }

    if(fread(&hi, 1, 1, file) != 1)
    {
        return FALSE;
    }

    *width = MAKE_WORD(hi, lo);

    /* read the height, byte by byte */
    if(fread(&lo, 1, 1, file) != 1)
    {
        return FALSE;
    }

    if(fread(&hi, 1, 1, file) != 1)
    {
        return FALSE;
    }

    *height = MAKE_WORD(hi, lo);

    return TRUE;
}