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 | |||
75 | { | 75 | { |
76 | #ifdef JPEG_FROM_MEM | 76 | #ifdef JPEG_FROM_MEM |
77 | unsigned char *data; | 77 | unsigned char *data; |
78 | unsigned long len; | ||
79 | #else | 78 | #else |
80 | int fd; | 79 | int fd; |
81 | int buf_left; | 80 | int buf_left; |
82 | int buf_index; | 81 | int buf_index; |
83 | #endif | 82 | #endif |
83 | unsigned long len; | ||
84 | unsigned long int bitbuf; | 84 | unsigned long int bitbuf; |
85 | int bitbuf_bits; | 85 | int bitbuf_bits; |
86 | int marker_ind; | 86 | int marker_ind; |
@@ -888,8 +888,12 @@ INLINE void jpeg_putc(struct jpeg* p_jpeg) | |||
888 | #else | 888 | #else |
889 | INLINE void fill_buf(struct jpeg* p_jpeg) | 889 | INLINE void fill_buf(struct jpeg* p_jpeg) |
890 | { | 890 | { |
891 | p_jpeg->buf_left = read(p_jpeg->fd, p_jpeg->buf, JPEG_READ_BUF_SIZE); | 891 | p_jpeg->buf_left = read(p_jpeg->fd, p_jpeg->buf, |
892 | (p_jpeg->len >= JPEG_READ_BUF_SIZE)? | ||
893 | JPEG_READ_BUF_SIZE : p_jpeg->len); | ||
892 | p_jpeg->buf_index = 0; | 894 | p_jpeg->buf_index = 0; |
895 | if (p_jpeg->buf_left > 0) | ||
896 | p_jpeg->len -= p_jpeg->buf_left; | ||
893 | } | 897 | } |
894 | 898 | ||
895 | static unsigned char *jpeg_getc(struct jpeg* p_jpeg) | 899 | static unsigned char *jpeg_getc(struct jpeg* p_jpeg) |
@@ -1960,7 +1964,9 @@ block_end: | |||
1960 | * | 1964 | * |
1961 | *****************************************************************************/ | 1965 | *****************************************************************************/ |
1962 | #ifndef JPEG_FROM_MEM | 1966 | #ifndef JPEG_FROM_MEM |
1963 | int read_jpeg_file(const char* filename, | 1967 | int clip_jpeg_file(const char* filename, |
1968 | int offset, | ||
1969 | unsigned long jpeg_size, | ||
1964 | struct bitmap *bm, | 1970 | struct bitmap *bm, |
1965 | int maxsize, | 1971 | int maxsize, |
1966 | int format, | 1972 | int format, |
@@ -1975,11 +1981,20 @@ int read_jpeg_file(const char* filename, | |||
1975 | DEBUGF("read_jpeg_file: can't open '%s', rc: %d\n", filename, fd); | 1981 | DEBUGF("read_jpeg_file: can't open '%s', rc: %d\n", filename, fd); |
1976 | return fd * 10 - 1; | 1982 | return fd * 10 - 1; |
1977 | } | 1983 | } |
1978 | 1984 | lseek(fd, offset, SEEK_SET); | |
1979 | ret = read_jpeg_fd(fd, bm, maxsize, format, cformat); | 1985 | ret = clip_jpeg_fd(fd, jpeg_size, bm, maxsize, format, cformat); |
1980 | close(fd); | 1986 | close(fd); |
1981 | return ret; | 1987 | return ret; |
1982 | } | 1988 | } |
1989 | |||
1990 | int read_jpeg_file(const char* filename, | ||
1991 | struct bitmap *bm, | ||
1992 | int maxsize, | ||
1993 | int format, | ||
1994 | const struct custom_format *cformat) | ||
1995 | { | ||
1996 | return clip_jpeg_file(filename, 0, 0, bm, maxsize, format, cformat); | ||
1997 | } | ||
1983 | #endif | 1998 | #endif |
1984 | 1999 | ||
1985 | static int calc_scale(int in_size, int out_size) | 2000 | 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, | |||
2014 | return 0; | 2029 | return 0; |
2015 | } | 2030 | } |
2016 | 2031 | ||
2017 | int decode_jpeg_mem(unsigned char *data, unsigned long len, | 2032 | int decode_jpeg_mem(unsigned char *data, |
2018 | #else | 2033 | #else |
2019 | int read_jpeg_fd(int fd, | 2034 | int clip_jpeg_fd(int fd, |
2020 | #endif | 2035 | #endif |
2036 | unsigned long len, | ||
2021 | struct bitmap *bm, | 2037 | struct bitmap *bm, |
2022 | int maxsize, | 2038 | int maxsize, |
2023 | int format, | 2039 | int format, |
@@ -2039,11 +2055,13 @@ int read_jpeg_fd(int fd, | |||
2039 | return -1; | 2055 | return -1; |
2040 | #endif | 2056 | #endif |
2041 | memset(p_jpeg, 0, sizeof(struct jpeg)); | 2057 | memset(p_jpeg, 0, sizeof(struct jpeg)); |
2058 | p_jpeg->len = len; | ||
2042 | #ifdef JPEG_FROM_MEM | 2059 | #ifdef JPEG_FROM_MEM |
2043 | p_jpeg->data = data; | 2060 | p_jpeg->data = data; |
2044 | p_jpeg->len = len; | ||
2045 | #else | 2061 | #else |
2046 | p_jpeg->fd = fd; | 2062 | p_jpeg->fd = fd; |
2063 | if (p_jpeg->len == 0) | ||
2064 | p_jpeg->len = filesize(p_jpeg->fd); | ||
2047 | #endif | 2065 | #endif |
2048 | status = process_markers(p_jpeg); | 2066 | status = process_markers(p_jpeg); |
2049 | #ifndef JPEG_FROM_MEM | 2067 | #ifndef JPEG_FROM_MEM |
@@ -2212,4 +2230,13 @@ int read_jpeg_fd(int fd, | |||
2212 | return 0; | 2230 | return 0; |
2213 | } | 2231 | } |
2214 | 2232 | ||
2233 | int read_jpeg_fd(int fd, | ||
2234 | struct bitmap *bm, | ||
2235 | int maxsize, | ||
2236 | int format, | ||
2237 | const struct custom_format *cformat) | ||
2238 | { | ||
2239 | return clip_jpeg_fd(fd, 0, bm, maxsize, format, cformat); | ||
2240 | } | ||
2241 | |||
2215 | /**************** end JPEG code ********************/ | 2242 | /**************** 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, | |||
44 | int format, | 44 | int format, |
45 | const struct custom_format *cformat); | 45 | const struct custom_format *cformat); |
46 | 46 | ||
47 | /** | ||
48 | * read embedded jpeg files as above. Needs an offset and length into | ||
49 | * the file | ||
50 | **/ | ||
51 | int clip_jpeg_file(const char* filename, | ||
52 | int offset, | ||
53 | unsigned long jpeg_size, | ||
54 | struct bitmap *bm, | ||
55 | int maxsize, | ||
56 | int format, | ||
57 | const struct custom_format *cformat); | ||
58 | |||
59 | /** | ||
60 | * read embedded jpeg files as above. Needs an open file descripter, and | ||
61 | * assumes the caller has lseek()'d to the start of the jpeg blob | ||
62 | **/ | ||
63 | int clip_jpeg_fd(int fd, | ||
64 | unsigned long jpeg_size, | ||
65 | struct bitmap *bm, | ||
66 | int maxsize, | ||
67 | int format, | ||
68 | const struct custom_format *cformat); | ||
69 | |||
47 | #endif /* _JPEG_JPEG_DECODER_H */ | 70 | #endif /* _JPEG_JPEG_DECODER_H */ |