diff options
Diffstat (limited to 'apps/recorder')
-rw-r--r-- | apps/recorder/jpeg_load.c | 43 | ||||
-rw-r--r-- | apps/recorder/jpeg_load.h | 23 |
2 files changed, 58 insertions, 8 deletions
diff --git a/apps/recorder/jpeg_load.c b/apps/recorder/jpeg_load.c index 1af65fab6c..cd13934921 100644 --- a/apps/recorder/jpeg_load.c +++ b/apps/recorder/jpeg_load.c @@ -75,12 +75,12 @@ struct jpeg { #ifdef JPEG_FROM_MEM unsigned char *data; - unsigned long len; #else int fd; int buf_left; int buf_index; #endif + unsigned long len; unsigned long int bitbuf; int bitbuf_bits; int marker_ind; @@ -888,8 +888,12 @@ INLINE void jpeg_putc(struct jpeg* p_jpeg) #else INLINE void fill_buf(struct jpeg* p_jpeg) { - p_jpeg->buf_left = read(p_jpeg->fd, p_jpeg->buf, JPEG_READ_BUF_SIZE); + p_jpeg->buf_left = read(p_jpeg->fd, p_jpeg->buf, + (p_jpeg->len >= JPEG_READ_BUF_SIZE)? + JPEG_READ_BUF_SIZE : p_jpeg->len); p_jpeg->buf_index = 0; + if (p_jpeg->buf_left > 0) + p_jpeg->len -= p_jpeg->buf_left; } static unsigned char *jpeg_getc(struct jpeg* p_jpeg) @@ -1960,7 +1964,9 @@ block_end: * *****************************************************************************/ #ifndef JPEG_FROM_MEM -int read_jpeg_file(const char* filename, +int clip_jpeg_file(const char* filename, + int offset, + unsigned long jpeg_size, struct bitmap *bm, int maxsize, int format, @@ -1975,11 +1981,20 @@ int read_jpeg_file(const char* filename, DEBUGF("read_jpeg_file: can't open '%s', rc: %d\n", filename, fd); return fd * 10 - 1; } - - ret = read_jpeg_fd(fd, bm, maxsize, format, cformat); + lseek(fd, offset, SEEK_SET); + ret = clip_jpeg_fd(fd, jpeg_size, bm, maxsize, format, cformat); close(fd); return ret; } + +int read_jpeg_file(const char* filename, + struct bitmap *bm, + int maxsize, + int format, + const struct custom_format *cformat) +{ + return clip_jpeg_file(filename, 0, 0, bm, maxsize, format, cformat); +} #endif static int calc_scale(int in_size, int out_size) @@ -2014,10 +2029,11 @@ int get_jpeg_dim_mem(unsigned char *data, unsigned long len, return 0; } -int decode_jpeg_mem(unsigned char *data, unsigned long len, +int decode_jpeg_mem(unsigned char *data, #else -int read_jpeg_fd(int fd, +int clip_jpeg_fd(int fd, #endif + unsigned long len, struct bitmap *bm, int maxsize, int format, @@ -2039,11 +2055,13 @@ int read_jpeg_fd(int fd, return -1; #endif memset(p_jpeg, 0, sizeof(struct jpeg)); + p_jpeg->len = len; #ifdef JPEG_FROM_MEM p_jpeg->data = data; - p_jpeg->len = len; #else p_jpeg->fd = fd; + if (p_jpeg->len == 0) + p_jpeg->len = filesize(p_jpeg->fd); #endif status = process_markers(p_jpeg); #ifndef JPEG_FROM_MEM @@ -2212,4 +2230,13 @@ int read_jpeg_fd(int fd, return 0; } +int read_jpeg_fd(int fd, + struct bitmap *bm, + int maxsize, + int format, + const struct custom_format *cformat) +{ + return clip_jpeg_fd(fd, 0, bm, maxsize, format, cformat); +} + /**************** end JPEG code ********************/ diff --git a/apps/recorder/jpeg_load.h b/apps/recorder/jpeg_load.h index 73b6c51bf3..6ff96dabad 100644 --- a/apps/recorder/jpeg_load.h +++ b/apps/recorder/jpeg_load.h @@ -44,4 +44,27 @@ int read_jpeg_fd(int fd, int format, const struct custom_format *cformat); +/** + * read embedded jpeg files as above. Needs an offset and length into + * the file + **/ +int clip_jpeg_file(const char* filename, + int offset, + unsigned long jpeg_size, + struct bitmap *bm, + int maxsize, + int format, + const struct custom_format *cformat); + +/** + * read embedded jpeg files as above. Needs an open file descripter, and + * assumes the caller has lseek()'d to the start of the jpeg blob + **/ +int clip_jpeg_fd(int fd, + unsigned long jpeg_size, + struct bitmap *bm, + int maxsize, + int format, + const struct custom_format *cformat); + #endif /* _JPEG_JPEG_DECODER_H */ |