summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2011-12-01 09:41:56 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2011-12-01 09:41:56 +0100
commit8ed172cab141f02390d7c77abec9eb18fe212182 (patch)
tree79e99568eb8cd1240374e31e648e6b2716cf0111 /test
parent7a847adfb41352466475428c61e85807ca4d25b8 (diff)
downloadufodecode-8ed172cab141f02390d7c77abec9eb18fe212182.tar.gz
ufodecode-8ed172cab141f02390d7c77abec9eb18fe212182.tar.bz2
ufodecode-8ed172cab141f02390d7c77abec9eb18fe212182.tar.xz
ufodecode-8ed172cab141f02390d7c77abec9eb18fe212182.zip
Make ipedec a lib and executable
Diffstat (limited to 'test')
-rw-r--r--test/ipedec.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/ipedec.c b/test/ipedec.c
new file mode 100644
index 0000000..1aef1d6
--- /dev/null
+++ b/test/ipedec.c
@@ -0,0 +1,83 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <libipe.h>
+
+
+int read_raw_file(const char *filename, char **buffer, size_t *length)
+{
+ FILE *fp = fopen(filename, "rb");
+ if (fp == NULL)
+ return ENOENT;
+
+ fseek(fp, 0, SEEK_END);
+ *length = ftell(fp);
+ rewind(fp);
+
+ *buffer = (char *) malloc(*length);
+ if (*buffer == NULL) {
+ fclose(fp);
+ return ENOMEM;
+ }
+
+ size_t buffer_length = fread(*buffer, 1, *length, fp);
+ fclose(fp);
+ if (buffer_length != *length) {
+ free(buffer);
+ return ERANGE;
+ }
+ return 0;
+}
+
+
+int main(int argc, char const* argv[])
+{
+ if (argc < 3) {
+ fprintf(stderr, "Usage: ipedec <filename> <number of lines per frame>\n");
+ return EXIT_FAILURE;
+ }
+
+ char *buffer = NULL;
+ size_t num_bytes = 0;
+ if (read_raw_file(argv[1], &buffer, &num_bytes))
+ return EXIT_FAILURE;
+
+ const int rows = atoi(argv[2]);
+
+ ipe_decoder decoder = ipe_decoder_new(rows, (uint32_t *) buffer, num_bytes);
+ int err = 0;
+ uint16_t *pixels = (uint16_t *) malloc(2048 * rows * sizeof(uint16_t));
+ uint32_t frame_number, time_stamp;
+ int num_frames = 0;
+ struct timeval start, end;
+ long seconds = 0L, useconds = 0L;
+
+ /* FILE *fp = fopen("test.raw", "wb"); */
+
+ while (!err) {
+ gettimeofday(&start, NULL);
+ err = ipe_decoder_get_next_frame(decoder, &pixels, &frame_number, &time_stamp);
+ gettimeofday(&end, NULL);
+
+ if (!err) {
+ num_frames++;
+ seconds += end.tv_sec - start.tv_sec;
+ useconds += end.tv_usec - start.tv_usec;
+ /* fwrite(pixels, sizeof(uint16_t), 2048 * 1088, fp); */
+ }
+ }
+ /* fclose(fp); */
+
+ float mtime = seconds * 1000.0 + useconds / 1000.0;
+ printf("Decoded %i frames in %.5fms\n", num_frames, mtime);
+
+ free(pixels);
+ ipe_decoder_free(decoder);
+ free(buffer);
+
+ return 0;
+}
+