summaryrefslogtreecommitdiff
path: root/apps/gui
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/icon.c48
-rw-r--r--apps/gui/skin_engine/skin_parser.c79
2 files changed, 40 insertions, 87 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}
170static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL};
171 170
172static void load_icons(const char* filename, enum Iconset iconset, 171static 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;
218finished: 190 }
219 close(fd);
220 return;
221 } 191 }
222} 192}
223 193
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index ad5fa48756..9495e34f5b 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -1908,77 +1908,60 @@ static int buflib_move_callback(int handle, void* current, void* new)
1908 1908
1909 return BUFLIB_CB_OK; 1909 return BUFLIB_CB_OK;
1910} 1910}
1911static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL};
1912#endif 1911#endif
1913 1912
1914static int load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char* bmpdir) 1913static int load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char* bmpdir)
1915{ 1914{
1915 static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL};
1916 (void)wps_data; /* only needed for remote targets */ 1916 (void)wps_data; /* only needed for remote targets */
1917 char img_path[MAX_PATH]; 1917 char img_path[MAX_PATH];
1918 int fd; 1918
1919 int handle;
1920 get_image_filename(bitmap->data, bmpdir, 1919 get_image_filename(bitmap->data, bmpdir,
1921 img_path, sizeof(img_path)); 1920 img_path, sizeof(img_path));
1922 1921
1923 /* load the image */ 1922#ifdef __PCTOOL__ /* just check if image exists */
1924 int format; 1923 int fd = open(img_path, O_RDONLY);
1925#ifdef HAVE_REMOTE_LCD
1926 if (curr_screen == SCREEN_REMOTE)
1927 format = FORMAT_ANY|FORMAT_REMOTE;
1928 else
1929#endif
1930 format = FORMAT_ANY|FORMAT_TRANSPARENT;
1931
1932 fd = open(img_path, O_RDONLY);
1933 if (fd < 0) 1924 if (fd < 0)
1934 { 1925 {
1935 DEBUGF("Couldn't open %s\n", img_path); 1926 DEBUGF("Couldn't open %s\n", img_path);
1936 return fd; 1927 return fd;
1937 } 1928 }
1938#ifndef __PCTOOL__ 1929 close(fd);
1939 int buf_size = read_bmp_fd(fd, bitmap, 0, 1930 return 1;
1940 format|FORMAT_RETURN_SIZE, NULL); 1931#else /* load the image */
1941 if(buf_size < 0) 1932 int handle;
1942 { 1933 int bmpformat;
1943 close(fd); 1934 ssize_t buf_reqd;
1944 return buf_size; 1935#ifdef HAVE_REMOTE_LCD
1945 } 1936 if (curr_screen == SCREEN_REMOTE)
1937 bmpformat = FORMAT_ANY|FORMAT_REMOTE;
1938 else
1939#endif
1940 bmpformat = FORMAT_ANY|FORMAT_TRANSPARENT;
1946 1941
1947 handle = core_alloc_ex(bitmap->data, buf_size, &buflib_ops); 1942 handle = core_load_bmp(img_path, bitmap, bmpformat, &buf_reqd, &buflib_ops);
1948 if (handle <= 0) 1943 if (handle != CLB_ALOC_ERR)
1949 { 1944 {
1950 DEBUGF("Not enough skin buffer: need %zd more.\n", 1945 /* NOTE!: bitmap->data == NULL to force a crash later if the
1951 buf_size - skin_buffer_freespace()); 1946 caller doesnt call core_get_data() */
1952 close(fd); 1947 _stats->buflib_handles++;
1948 _stats->images_size += buf_reqd;
1953 return handle; 1949 return handle;
1954 } 1950 }
1955 _stats->buflib_handles++; 1951
1956 _stats->images_size += buf_size; 1952 if (buf_reqd == CLB_READ_ERR)
1957 lseek(fd, 0, SEEK_SET);
1958 core_pin(handle);
1959 bitmap->data = core_get_data(handle);
1960 int ret = read_bmp_fd(fd, bitmap, buf_size, format, NULL);
1961 bitmap->data = NULL; /* do this to force a crash later if the
1962 caller doesnt call core_get_data() */
1963 core_unpin(handle);
1964 close(fd);
1965 if (ret > 0)
1966 { 1953 {
1967 /* free unused alpha channel, if any */ 1954 /* Abort if we can't load an image */
1968 core_shrink(handle, core_get_data(handle), ret); 1955 DEBUGF("Couldn't load '%s' (%ld)\n", img_path, buf_reqd);
1969 return handle;
1970 } 1956 }
1971 else 1957 else
1972 { 1958 {
1973 /* Abort if we can't load an image */ 1959 DEBUGF("Not enough skin buffer: need %zd more.\n",
1974 DEBUGF("Couldn't load '%s'\n", img_path); 1960 buf_reqd - skin_buffer_freespace());
1975 core_free(handle);
1976 return -1;
1977 } 1961 }
1978#else /* !__PCTOOL__ */ 1962
1979 close(fd); 1963 return -1;
1980 return 1; 1964#endif/* !__PCTOOL__ */
1981#endif
1982} 1965}
1983 1966
1984static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir) 1967static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir)