diff options
| author | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-02-17 15:43:04 +1100 |
|---|---|---|
| committer | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-02-17 15:43:04 +1100 |
| commit | 1e91f1d335e0d25b84f0b93aceff91f2f7fb9760 (patch) | |
| tree | 2adc58de3f4d47f97f0dea6a48bbf5f219b984f1 | |
| parent | b8de9285970775d539f09f7bc81d3eae24e410e9 (diff) | |
feat(bmp): Implement ff_open_bmp function for BMP context initialization
| -rw-r--r-- | include/tinyff/image/bmp.h | 7 | ||||
| -rw-r--r-- | src/format/image/bmp.c | 38 |
2 files changed, 45 insertions, 0 deletions
diff --git a/include/tinyff/image/bmp.h b/include/tinyff/image/bmp.h index 8c4fd56..6381cea 100644 --- a/include/tinyff/image/bmp.h +++ b/include/tinyff/image/bmp.h @@ -17,6 +17,10 @@ static const unsigned char BMP_SIGNATURE[2] = { }; typedef struct { + // Raw stream handle + ff_stream *raw; + + uint32_t file_size; // tbh, i actually have no idea why this is needed uint32_t data_offset; @@ -34,6 +38,9 @@ typedef struct { uint8_t* pixels; + + bool valid; + ff_result last_error; } ff_bmp_ctx; ff_result ff_bmp_isvalid(ff_stream *stream); diff --git a/src/format/image/bmp.c b/src/format/image/bmp.c index d947a83..d1d343c 100644 --- a/src/format/image/bmp.c +++ b/src/format/image/bmp.c @@ -24,4 +24,42 @@ ff_result ff_bmp_isvalid(ff_stream* stream) ff_dprintf("bmp: signature valid\n"); return FF_RESULT_OK; +} + +ff_result ff_open_bmp(ff_stream *stream, ff_bmp_ctx **out_ctx) +{ + + ff_bmp_ctx *ctx = malloc(sizeof(ff_bmp_ctx)); + if (!ctx) return FF_RESULT_ERROR_MEMORY_ALLOCATION; + + // Init + memset(ctx, 0, sizeof(*ctx)); + ctx->raw = stream; + ctx->last_error = FF_RESULT_OK; + + + if (ctx->raw->read == NULL) { + ff_dprintf("bmp: stream failed to read\n"); + free(ctx); + ctx->last_error = FF_RESULT_ERROR_READ_FILE_FAILURE; + return FF_RESULT_ERROR_READ_FILE_FAILURE; + } + + ff_dprintf("bmp: stream read successfully\n"); + + ff_result res = ff_bmp_isvalid(ctx->raw); + if (res != FF_RESULT_OK) { + ff_dprintf("bmp: validation failed (%d)\n", res); + free(ctx); + ctx->last_error = res; + return res; + } + + ff_dprintf("bmp: validation passed\n"); + ctx->valid = true; + + *out_ctx = ctx; + ff_dprintf("bmp: open_bmp reached WIP end\n"); + + return FF_RESULT_WARN_NO_IMPL; }
\ No newline at end of file |
