static bool load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char* bmpdir) { (void)wps_data; /* only needed for remote targets */ char img_path[MAX_PATH]; int fd; get_image_filename(bitmap->data, bmpdir, img_path, sizeof(img_path)); /* load the image */ int format; #ifdef HAVE_REMOTE_LCD if (curr_screen == SCREEN_REMOTE) format = FORMAT_ANY|FORMAT_REMOTE; else #endif format = FORMAT_ANY|FORMAT_TRANSPARENT; fd = open(img_path, O_RDONLY); if (fd < 0) { DEBUGF("Couldn't open %s\n", img_path); return false; } size_t buf_size = read_bmp_fd(fd, bitmap, 0, format|FORMAT_RETURN_SIZE, NULL); char* imgbuf = (char*)skin_buffer_alloc(buf_size); if (!imgbuf) { #ifndef APPLICATION DEBUGF("Not enough skin buffer: need %zd more.\n", buf_size - skin_buffer_freespace()); #endif close(fd); return NULL; } lseek(fd, 0, SEEK_SET); bitmap->data = imgbuf; int ret = read_bmp_fd(fd, bitmap, buf_size, format, NULL); close(fd); if (ret > 0) { return true; } else { /* Abort if we can't load an image */ DEBUGF("Couldn't load '%s'\n", img_path); return false; } }
/* Given a file descriptor to a bitmap file, write the bitmap data to the buffer, with a struct bitmap and the actual data immediately following. Return value is the total size (struct + data). */ static int load_image(int fd, const char *path, struct dim *dim) { int rc; struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx]; /* get the desired image size */ bmp->width = dim->width, bmp->height = dim->height; /* FIXME: alignment may be needed for the data buffer. */ bmp->data = &buffer[buf_widx + sizeof(struct bitmap)]; #ifndef HAVE_JPEG (void) path; #endif #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) bmp->maskdata = NULL; #endif int free = (int)MIN(buffer_len - BUF_USED, buffer_len - buf_widx) - sizeof(struct bitmap); #ifdef HAVE_JPEG int pathlen = strlen(path); if (strcmp(path + pathlen - 4, ".bmp")) rc = read_jpeg_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); else #endif rc = read_bmp_fd(fd, bmp, free, FORMAT_NATIVE|FORMAT_DITHER| FORMAT_RESIZE|FORMAT_KEEP_ASPECT, NULL); return rc + (rc > 0 ? sizeof(struct bitmap) : 0); }