summaryrefslogtreecommitdiff
path: root/src/format/image/bmp.c
blob: d947a8371168a34b20569fd86996513360e3e715 (plain)
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
#include "tinyff/image/bmp.h"
#include "tinyff/dbg.h"
#include "bmp.h"

ff_result ff_bmp_isvalid(ff_stream* stream) 
{
    ff_dprintf("png: validating signature\n");

    char raw_sig[2];
    if (stream->read(raw_sig, 2, stream->user) != 2) {
        ff_dprintf("bmp: failed to read signature bytes\n");
        return FF_RESULT_ERROR_INVALID_FILE;
    }

    ff_dprintf(
        "bmp: signature read: %02X %02X \n",
        raw_sig[0], raw_sig[1]
    );

    if (memcmp(raw_sig, BMP_SIGNATURE, 2) != 0) {
        ff_dprintf("bmp: signature mismatch\n");
        return FF_RESULT_ERROR_INVALID_PNG_SIGNITURE;
    }

    ff_dprintf("bmp: signature valid\n");
    return FF_RESULT_OK;
}