summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTazyFoundSoup <gardendistrict0x0@outlook.com>2026-05-18 10:31:15 +1000
committerTazyFoundSoup <gardendistrict0x0@outlook.com>2026-05-18 10:31:42 +1000
commitcbd6c45887a177bd9279ce9198da0712a6417248 (patch)
tree4a9a12ed4ad2ec4bcee19fc14ae9e2e5f19ea30a
parent57cd3d1fee606fd27992d3ad6be819ffbb0af001 (diff)
ci(coverage): Add repo coverage with codecov
-rw-r--r--.github/workflows/coverage.yaml27
-rw-r--r--.gitignore7
-rw-r--r--Makefile14
-rw-r--r--src/format/image/png.c18
4 files changed, 54 insertions, 12 deletions
diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml
new file mode 100644
index 0000000..527aa20
--- /dev/null
+++ b/.github/workflows/coverage.yaml
@@ -0,0 +1,27 @@
+name: Coverage
+
+on:
+ push:
+ branches: [master]
+ pull_request:
+ branches: [master]
+
+jobs:
+ coverage:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Install lcov
+ run: sudo apt-get update && sudo apt-get install lcov
+
+ - name: Generate coverage report
+ run: make coverage
+
+ - name: Upload coverage report to Codecov
+ uses: codecov/codecov-action@v5
+ with:
+ files: coverage.info
+ token: ${{ secrets.CODECOV_TOKEN }}
+ fail_ci_if_error: true \ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 40d3802..14c982f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,10 @@ tests/logs/*
# Ignore generated book from mdbook
docs/book/
docs/book/*
+
+# Coverage outputs
+.coverage
+coverage/
+*.gcda
+*.gcov
+*.lcov \ No newline at end of file
diff --git a/Makefile b/Makefile
index cca0169..1716671 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ OUTDIR = build
BENCH_OUT = $(OUTDIR)/bench
LIB = libtinyff.a
-ALL_CFLAGS = -Wall -Wextra -Werror -std=c11 -Iinclude
+ALL_CFLAGS = -Wall -Wextra -Werror -std=c11 -Iinclude --coverage
DEBUG_FLAGS = -g -O0 -fno-omit-frame-pointer
RELEASE_FLAGS = -O2
@@ -37,7 +37,7 @@ $(OUTDIR)/%.o: %.c
$(CC) $(ALL_CFLAGS) $(CFLAGS) -c $< -o $@
clean:
- rm -rf $(OUTDIR) png_test
+ rm -rf $(OUTDIR) png_test coverage.info .coverage
debug: CFLAGS = $(DEBUG_FLAGS)
debug: $(OUTDIR)/$(LIB)
@@ -63,4 +63,12 @@ bench: $(OUTDIR)/$(LIB)
$(CC) $(ALL_CFLAGS) $(RELEASE_FLAGS) $(BENCH_SRC) -o $(BENCH_OUT)/bench -L$(OUTDIR) -ltinyff
$(BENCH_OUT)/bench
-.PHONY: all clean debug release asan test test-png gdb bench \ No newline at end of file
+coverage: clean
+ $(MAKE) USE_HOSTED=1 debug
+ $(CC) $(ALL_CFLAGS) $(DEBUG_FLAGS) -DUSE_HOSTED tests/format/image/png/png_open.c -o $(OUTDIR)/png_test -L$(OUTDIR) -ltinyff
+ ./$(OUTDIR)/png_test || true
+ lcov --capture --directory . --output-file coverage.info
+ lcov --remove coverage.info '/usr/*' --output-file coverage.info --ignore-errors unused
+ lcov --list coverage.info
+
+.PHONY: all clean debug release asan test test-png gdb bench coverage \ No newline at end of file
diff --git a/src/format/image/png.c b/src/format/image/png.c
index 3b1fe5c..32399c6 100644
--- a/src/format/image/png.c
+++ b/src/format/image/png.c
@@ -440,19 +440,19 @@ ff_result ff_png_end_handler(ff_ctx* ctx, uint8_t *buf, size_t len, ff_png_ctx *
ff_result ff_png_trans_handler(ff_ctx* ctx, uint8_t *buf, size_t len, ff_png_ctx *png_ctx)
{
- (void)buf; // Unused (for now)
-
- ff_dprintf(ctx, "png: tRNS chunk received\n"); // TODO: Format
+ ff_dprintf(ctx, "png: tRNS chunk received\n");
- if (png_ctx->color_type == 0) { // Grayscale
- if (len != 2) {
- ff_dprintf(ctx, "png: invalid tRNS length for grayscale image\n");
- png_ctx->last_error = FF_RESULT_ERROR_INVALID_FILE;
- return FF_RESULT_ERROR_INVALID_FILE;
+ if (png_ctx->color_type == 3) { // indexed
+ size_t count = len;
+ if (count > png_ctx->palette_size)
+ count = png_ctx->palette_size;
+
+ for (size_t i = 0; i < count; i++) {
+ png_ctx->palette[i * 4 + 3] = buf[i];
}
}
- return FF_RESULT_WARN_NO_IMPL;
+ return FF_RESULT_OK;
}