-
-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pandagl): update image reader to support reading one row of data
- Loading branch information
Showing
17 changed files
with
795 additions
and
839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
#ifndef LIB_PANDAGL_INCLUDE_PANDAGL_FILE_READER_H | ||
#define LIB_PANDAGL_INCLUDE_PANDAGL_FILE_READER_H | ||
|
||
#include "common.h" | ||
#include "types.h" | ||
|
||
PD_BEGIN_DECLS | ||
|
||
typedef struct pd_file_reader_t { | ||
void *stream_data; | ||
void (*fn_close)(void*); | ||
void (*fn_rewind)(void*); | ||
size_t (*fn_read)(void *, void *, size_t); | ||
void (*fn_skip)(void *, long); | ||
} pd_file_reader_t; | ||
|
||
PD_INLINE size_t pd_file_reader_read(pd_file_reader_t *reader, void *buffer, | ||
size_t size) | ||
{ | ||
return reader->fn_read(reader->stream_data, buffer, size); | ||
} | ||
|
||
PD_INLINE void pd_file_reader_rewind(pd_file_reader_t *reader) | ||
{ | ||
reader->fn_rewind(reader->stream_data); | ||
} | ||
|
||
PD_INLINE void pd_file_reader_skip(pd_file_reader_t *reader, long bytes) | ||
{ | ||
reader->fn_skip(reader->stream_data, bytes); | ||
} | ||
|
||
PD_PUBLIC pd_file_reader_t *pd_file_reader_create(void); | ||
PD_PUBLIC pd_file_reader_t *pd_file_reader_create_from_file(const char *filename); | ||
PD_PUBLIC void pd_file_reader_destroy(pd_file_reader_t *reader); | ||
|
||
PD_END_DECLS | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <pandagl/file_reader.h> | ||
|
||
static size_t pd_file_stream_on_read(void *data, void *buffer, size_t size) | ||
{ | ||
return fread(buffer, 1, size, data); | ||
} | ||
|
||
static void pd_file_stream_on_skip(void *data, long offset) | ||
{ | ||
fseek(data, offset, SEEK_CUR); | ||
} | ||
|
||
static void pd_file_stream_on_rewind(void *data) | ||
{ | ||
rewind(data); | ||
} | ||
|
||
static void pd_file_stream_on_close(void *data) | ||
{ | ||
fclose(data); | ||
} | ||
|
||
pd_file_reader_t *pd_file_reader_create(void) | ||
{ | ||
return calloc(1, sizeof(pd_file_reader_t)); | ||
} | ||
|
||
pd_file_reader_t *pd_file_reader_create_from_file(const char *filename) | ||
{ | ||
FILE *fp; | ||
pd_file_reader_t *reader; | ||
|
||
fp = fopen(filename, "rb"); | ||
if (fp == NULL) { | ||
return NULL; | ||
} | ||
reader = pd_file_reader_create(); | ||
reader->stream_data = fp; | ||
reader->fn_skip = pd_file_stream_on_skip; | ||
reader->fn_read = pd_file_stream_on_read; | ||
reader->fn_rewind = pd_file_stream_on_rewind; | ||
reader->fn_close = pd_file_stream_on_close; | ||
return reader; | ||
} | ||
|
||
void pd_file_reader_destroy(pd_file_reader_t *reader) | ||
{ | ||
reader->fn_close(reader->stream_data); | ||
free(reader); | ||
} |
Oops, something went wrong.