diff options
Diffstat (limited to 'apps/gui/skin_engine')
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 79 |
1 files changed, 31 insertions, 48 deletions
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 | } |
1911 | static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL}; | ||
1912 | #endif | 1911 | #endif |
1913 | 1912 | ||
1914 | static int load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char* bmpdir) | 1913 | static 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 | ||
1984 | static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir) | 1967 | static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir) |