summaryrefslogtreecommitdiff
path: root/cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'cli.c')
-rw-r--r--cli.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/cli.c b/cli.c
index 33edcee..b0d3a1b 100644
--- a/cli.c
+++ b/cli.c
@@ -34,23 +34,31 @@ cli_read_images(libusb_context *usb, struct device *device, int count,
{
device_start(device);
for (int i = 0; i < count;) {
- const struct device_image *device_image = device_read(device);
- if (device_image) {
+ struct image *image = device_read(device);
+ if (image) {
+ if (image->format != IMAGE_FORMAT_XBGR32) {
+ struct image *cimage = image_new(image->width, image->height,
+ image->width * 4, IMAGE_FORMAT_XBGR32);
+ image_convert(cimage, image);
+ image_unref(image);
+ image = cimage;
+ }
char *name = NULL;
if (asprintf(&name, out, i) < 0)
utils_fatal("can not prepare file name");
utils_info("write %s", name);
- png_image image;
- memset(&image, 0, sizeof(image));
- image.version = PNG_IMAGE_VERSION;
- image.width = device_image->width;
- image.height = device_image->height;
- image.format = PNG_FORMAT_BGRA;
- int r = png_image_write_to_file(&image, name, 0,
- device_image->pixels, device_image->stride, NULL);
+ png_image pimage;
+ memset(&pimage, 0, sizeof(pimage));
+ pimage.version = PNG_IMAGE_VERSION;
+ pimage.width = image->width;
+ pimage.height = image->height;
+ pimage.format = PNG_FORMAT_BGRA;
+ int r = png_image_write_to_file(&pimage, name, 0,
+ image->pixels, image->stride, NULL);
if (r == 0)
- utils_fatal("can not write image: %s", image.message);
+ utils_fatal("can not write image: %s", pimage.message);
free(name);
+ image_unref(image);
i++;
} else {
libusb_handle_events(usb);