summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tinyff/image/bmp.h4
-rw-r--r--src/format/image/bmp.c27
2 files changed, 31 insertions, 0 deletions
diff --git a/include/tinyff/image/bmp.h b/include/tinyff/image/bmp.h
index 82edff3..8c4fd56 100644
--- a/include/tinyff/image/bmp.h
+++ b/include/tinyff/image/bmp.h
@@ -36,4 +36,8 @@ typedef struct {
} ff_bmp_ctx;
+ff_result ff_bmp_isvalid(ff_stream *stream);
+ff_result ff_open_bmp(ff_stream *stream, ff_bmp_ctx **out_ctx);
+
+
#endif BMP_H_ \ No newline at end of file
diff --git a/src/format/image/bmp.c b/src/format/image/bmp.c
new file mode 100644
index 0000000..d947a83
--- /dev/null
+++ b/src/format/image/bmp.c
@@ -0,0 +1,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;
+} \ No newline at end of file