aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--src/loader.c6
-rw-r--r--test/loader.c40
-rw-r--r--test/orientation.jpgbin0 -> 212 bytes
4 files changed, 47 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 71f5c9f..88880a8 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,7 @@ TARGET := $(BUILDDIR)/imv
SOURCES := $(wildcard src/*.c)
OBJECTS := $(patsubst src/%.c,$(BUILDDIR)/%.o,$(SOURCES))
TESTS := $(patsubst test/%.c,$(BUILDDIR)/test_%,$(wildcard test/*.c))
+TFLAGS ?= -g ${CFLAGS}
VERSION = "v2.0.0"
@@ -44,11 +45,11 @@ $(BUILDDIR)/%.o: src/%.c
$(BUILDDIR)/test_%: test/%.c src/%.c
@echo "BUILDING $@"
- $(MUTE)$(CC) -o $@ -Isrc -W -Wall $(CFLAGS) $(LDFLAGS) -std=gnu11 -lcmocka $^
+ $(MUTE)$(CC) -o $@ -Isrc $(TFLAGS) $(LDFLAGS) -std=gnu11 -lcmocka $^
check: $(BUILDDIR) $(TESTS)
@echo "RUNNING TESTS"
- $(MUTE)for t in "$(TESTS)"; do $$t; done
+ $(MUTE)for t in $(TESTS); do $$t; done
clean:
$(MUTE)$(RM) -Rf $(BUILDDIR)
diff --git a/src/loader.c b/src/loader.c
index 35e7450..e7d0321 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -227,13 +227,15 @@ static void *bg_new_img(void *data)
} else {
/* Future TODO: If we load image line-by-line we could stop loading large
* ones before wasting much more time/memory on them. */
+
+ int flags = (fmt == FIF_JPEG) ? JPEG_EXIFROTATE : 0;
FIBITMAP *image;
if(from_stdin) {
pthread_mutex_lock(&ldr->lock);
- image = FreeImage_LoadFromMemory(fmt, ldr->fi_buffer, 0);
+ image = FreeImage_LoadFromMemory(fmt, ldr->fi_buffer, flags);
pthread_mutex_unlock(&ldr->lock);
} else {
- image = FreeImage_Load(fmt, path, 0);
+ image = FreeImage_Load(fmt, path, flags);
}
if(!image) {
error_occurred(ldr);
diff --git a/test/loader.c b/test/loader.c
new file mode 100644
index 0000000..b528c8f
--- /dev/null
+++ b/test/loader.c
@@ -0,0 +1,40 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <unistd.h>
+#include <FreeImage.h>
+#include <pthread.h>
+#include "loader.h"
+
+static void test_jpeg_rotation(void **state)
+{
+ (void)state;
+ struct imv_loader ldr;
+ void *retval;
+ char *error;
+ unsigned int width;
+
+ imv_init_loader(&ldr);
+
+ imv_loader_load(&ldr, "test/orientation.jpg", NULL, 0);
+ pthread_join(ldr.bg_thread, &retval);
+
+ error = imv_loader_get_error(&ldr);
+ assert_false(error);
+
+ assert_false(retval == PTHREAD_CANCELED);
+ assert_false(ldr.out_bmp == NULL);
+
+ width = FreeImage_GetWidth(ldr.out_bmp);
+ assert_true(width == 1);
+}
+
+int main(void)
+{
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(test_jpeg_rotation),
+ };
+
+ return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/test/orientation.jpg b/test/orientation.jpg
new file mode 100644
index 0000000..c74189b
--- /dev/null
+++ b/test/orientation.jpg
Binary files differ