diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-12-19 21:12:07 -0500 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-12-20 19:07:46 -0500 |
commit | 88f662842340c6b9082b4ea9ea99bf24aefd2da7 (patch) | |
tree | 40eb3012231f1aca4d061f0d58af961e913f3adb /apps/gui/icon.c | |
parent | 2b4a4070c99439898e22c9c9da2c21877d18a367 (diff) | |
download | rockbox-88f662842340c6b9082b4ea9ea99bf24aefd2da7.tar.gz rockbox-88f662842340c6b9082b4ea9ea99bf24aefd2da7.zip |
consolidate bmp_read function between icons and skin_parser
uses fd now rather than opening file twice
Change-Id: If35418cbc77adacf5e96fb6aa0fc8ffef2fffcbd
Diffstat (limited to 'apps/gui/icon.c')
-rw-r--r-- | apps/gui/icon.c | 48 |
1 files changed, 9 insertions, 39 deletions
diff --git a/apps/gui/icon.c b/apps/gui/icon.c index 9deb1a0c65..7a59a72151 100644 --- a/apps/gui/icon.c +++ b/apps/gui/icon.c | |||
@@ -167,57 +167,27 @@ static int buflib_move_callback(int handle, void* current, void* new) | |||
167 | } | 167 | } |
168 | return BUFLIB_CB_OK; | 168 | return BUFLIB_CB_OK; |
169 | } | 169 | } |
170 | static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL}; | ||
171 | 170 | ||
172 | static void load_icons(const char* filename, enum Iconset iconset, | 171 | static void load_icons(const char* filename, enum Iconset iconset, |
173 | enum screen_type screen) | 172 | enum screen_type screen) |
174 | { | 173 | { |
175 | ssize_t size_read; | 174 | static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL}; |
176 | ssize_t buf_size; | 175 | const int bmpformat = (FORMAT_ANY|FORMAT_DITHER|FORMAT_TRANSPARENT); |
177 | int fd; | ||
178 | int bmpformat = (FORMAT_ANY|FORMAT_DITHER|FORMAT_TRANSPARENT); | ||
179 | struct iconset *ic = &iconsets[iconset][screen]; | 176 | struct iconset *ic = &iconsets[iconset][screen]; |
177 | ssize_t buf_reqd; | ||
180 | 178 | ||
181 | ic->loaded = false; | 179 | ic->loaded = false; |
182 | ic->handle = 0; | 180 | ic->handle = CLB_ALOC_ERR; |
183 | if (filename[0] && filename[0] != '-') | 181 | if (filename[0] && filename[0] != '-') |
184 | { | 182 | { |
185 | char fname[MAX_PATH]; | 183 | char fname[MAX_PATH]; |
186 | fd = open_pathfmt(fname, sizeof(fname), O_RDONLY, | 184 | snprintf(fname, sizeof(fname), ICON_DIR "/%s.bmp", filename); |
187 | ICON_DIR "/%s.bmp", filename); | 185 | ic->handle = core_load_bmp(fname, &ic->bmp, bmpformat, &buf_reqd, &buflib_ops); |
188 | if (fd < 0) | 186 | if (ic->handle != CLB_ALOC_ERR) |
189 | return; | ||
190 | buf_size = read_bmp_fd(fd, &ic->bmp, 0, | ||
191 | bmpformat|FORMAT_RETURN_SIZE, NULL); | ||
192 | if (buf_size > 0) | ||
193 | ic->handle = core_alloc_ex(filename, (size_t) buf_size, &buflib_ops); | ||
194 | |||
195 | if (ic->handle <= 0) | ||
196 | { | ||
197 | /* error */ | ||
198 | goto finished; | ||
199 | } | ||
200 | lseek(fd, 0, SEEK_SET); | ||
201 | core_pin(ic->handle); | ||
202 | ic->bmp.data = core_get_data(ic->handle); | ||
203 | size_read = read_bmp_fd(fd, &ic->bmp, buf_size, bmpformat, NULL); | ||
204 | core_unpin(ic->handle); | ||
205 | |||
206 | if (size_read < 0) | ||
207 | { | 187 | { |
208 | /* error */ | 188 | ic->bmp.data = core_get_data(ic->handle); |
209 | size_read = 0; | ||
210 | } | ||
211 | /* free unused alpha channel, if any */ | ||
212 | core_shrink(ic->handle, ic->bmp.data, size_read); | ||
213 | |||
214 | if (size_read == 0) | ||
215 | ic->handle = core_free(ic->handle); | ||
216 | else | ||
217 | ic->loaded = true; | 189 | ic->loaded = true; |
218 | finished: | 190 | } |
219 | close(fd); | ||
220 | return; | ||
221 | } | 191 | } |
222 | } | 192 | } |
223 | 193 | ||